@hi-ui/form 4.0.0-beta.24 → 4.0.0-beta.27
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/lib/cjs/Form.js +2 -2
- package/lib/cjs/FormSubmit.js +2 -0
- package/lib/cjs/use-form.js +15 -13
- package/lib/cjs/utils/index.js +17 -0
- package/lib/esm/Form.js +2 -2
- package/lib/esm/FormSubmit.js +2 -0
- package/lib/esm/use-form.js +17 -15
- package/lib/esm/utils/index.js +16 -1
- package/lib/types/FormField.d.ts +2 -3
- package/lib/types/FormItem.d.ts +3 -3
- package/lib/types/FormLabel.d.ts +1 -1
- package/lib/types/FormList.d.ts +4 -4
- package/lib/types/FormReset.d.ts +3 -0
- package/lib/types/FormSubmit.d.ts +4 -1
- package/lib/types/types.d.ts +15 -20
- package/lib/types/use-form.d.ts +6 -5
- package/lib/types/utils/index.d.ts +1 -0
- package/package.json +6 -6
package/lib/cjs/Form.js
CHANGED
|
@@ -72,14 +72,14 @@ var Form = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
72
72
|
validate: formContext.submitForm,
|
|
73
73
|
reset: formContext.resetForm,
|
|
74
74
|
validateField: formContext.validateFieldState,
|
|
75
|
-
// validateFields: formContext.va,
|
|
76
75
|
setFieldValue: formContext.setFieldValue,
|
|
77
76
|
setFieldsValue: formContext.setFieldsValue,
|
|
78
77
|
getFieldValue: formContext.getFieldValue,
|
|
79
78
|
getFieldsValue: formContext.getFieldsValue,
|
|
80
79
|
getFieldError: formContext.getFieldError,
|
|
81
80
|
getFieldsError: formContext.getFieldsError,
|
|
82
|
-
clearValidates: formContext.resetErrors
|
|
81
|
+
clearValidates: formContext.resetErrors,
|
|
82
|
+
clearFieldValidate: formContext.resetFieldError
|
|
83
83
|
};
|
|
84
84
|
});
|
|
85
85
|
var providedValue = React.useMemo(function () {
|
package/lib/cjs/FormSubmit.js
CHANGED
|
@@ -71,8 +71,10 @@ var FormSubmit = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
71
71
|
evt.preventDefault();
|
|
72
72
|
evt.stopPropagation();
|
|
73
73
|
submitForm().then(function (result) {
|
|
74
|
+
// @ts-ignore
|
|
74
75
|
_onClick === null || _onClick === void 0 ? void 0 : _onClick(result, null);
|
|
75
76
|
})["catch"](function (error) {
|
|
77
|
+
// @ts-ignore
|
|
76
78
|
_onClick === null || _onClick === void 0 ? void 0 : _onClick(null, error);
|
|
77
79
|
});
|
|
78
80
|
}
|
package/lib/cjs/use-form.js
CHANGED
|
@@ -309,7 +309,6 @@ var useForm = function useForm(_a) {
|
|
|
309
309
|
*/
|
|
310
310
|
|
|
311
311
|
var setFieldValue = React.useCallback(function (field, value, shouldValidate) {
|
|
312
|
-
// @ts-ignore
|
|
313
312
|
formDispatch({
|
|
314
313
|
type: 'SET_FIELD_VALUE',
|
|
315
314
|
payload: {
|
|
@@ -318,20 +317,20 @@ var useForm = function useForm(_a) {
|
|
|
318
317
|
}
|
|
319
318
|
}); // touched 给外部控制展示,而不是当做参数暴露
|
|
320
319
|
|
|
321
|
-
var shouldValidateField =
|
|
322
|
-
validateAfterTouched ? objectUtils.getNested(formState.touched, field) && shouldValidate : shouldValidate;
|
|
320
|
+
var shouldValidateField = validateAfterTouched ? objectUtils.getNested(formState.touched, field) && shouldValidate : shouldValidate;
|
|
323
321
|
|
|
324
322
|
if (shouldValidateField) {
|
|
325
323
|
validateField(field, value);
|
|
326
324
|
}
|
|
327
325
|
}, [validateField, validateAfterTouched, formState]);
|
|
328
|
-
var setFieldsValue = React.useCallback(function (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
326
|
+
var setFieldsValue = React.useCallback(function (fieldsState) {
|
|
327
|
+
formDispatch({
|
|
328
|
+
type: 'SET_VALUES',
|
|
329
|
+
payload: function payload(prevState) {
|
|
330
|
+
return typeAssertion.isFunction(fieldsState) ? fieldsState(prevState) : index.mergeValues(prevState, fieldsState);
|
|
331
|
+
}
|
|
333
332
|
});
|
|
334
|
-
}, [
|
|
333
|
+
}, []);
|
|
335
334
|
var normalizeValueFromChange = React.useCallback(function (eventOrValue, valuePropName) {
|
|
336
335
|
var nextValue = eventOrValue;
|
|
337
336
|
|
|
@@ -539,11 +538,13 @@ var useForm = function useForm(_a) {
|
|
|
539
538
|
}, [resetForm]);
|
|
540
539
|
var resetErrors = React.useCallback(function () {
|
|
541
540
|
formDispatch({
|
|
542
|
-
// TODO: reset errorMsg
|
|
543
541
|
type: 'SET_ERRORS',
|
|
544
542
|
payload: {}
|
|
545
543
|
});
|
|
546
544
|
}, []);
|
|
545
|
+
var resetFieldError = React.useCallback(function (field) {
|
|
546
|
+
setFieldError(field, '');
|
|
547
|
+
}, [setFieldError]);
|
|
547
548
|
var setFormState = React__default["default"].useCallback(function (stateOrFunc) {
|
|
548
549
|
// @ts-ignore
|
|
549
550
|
formDispatch({
|
|
@@ -609,14 +610,14 @@ var useForm = function useForm(_a) {
|
|
|
609
610
|
submitForm: submitForm,
|
|
610
611
|
resetForm: resetForm,
|
|
611
612
|
resetErrors: resetErrors,
|
|
613
|
+
resetFieldError: resetFieldError,
|
|
612
614
|
validateFieldState: validateFieldState,
|
|
613
615
|
validateValue: validateField,
|
|
614
616
|
getFieldsValue: getFieldsValue,
|
|
615
617
|
setFieldsValue: setFieldsValue,
|
|
616
618
|
getFieldsError: getFieldsError
|
|
617
619
|
});
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
+
};
|
|
620
621
|
|
|
621
622
|
function formReducer(state, action) {
|
|
622
623
|
switch (action.type) {
|
|
@@ -625,8 +626,9 @@ function formReducer(state, action) {
|
|
|
625
626
|
return Object.assign(Object.assign({}, state), nextState);
|
|
626
627
|
|
|
627
628
|
case 'SET_VALUES':
|
|
629
|
+
var nextValues = typeAssertion.isFunction(action.payload) ? action.payload(state.values) : action.payload;
|
|
628
630
|
return Object.assign(Object.assign({}, state), {
|
|
629
|
-
values:
|
|
631
|
+
values: nextValues
|
|
630
632
|
});
|
|
631
633
|
|
|
632
634
|
case 'SET_ERRORS':
|
package/lib/cjs/utils/index.js
CHANGED
|
@@ -15,6 +15,8 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
15
15
|
|
|
16
16
|
var typeAssertion = require('@hi-ui/type-assertion');
|
|
17
17
|
|
|
18
|
+
var objectUtils = require('@hi-ui/object-utils');
|
|
19
|
+
|
|
18
20
|
var stringify = function stringify(field) {
|
|
19
21
|
return JSON.stringify(field);
|
|
20
22
|
};
|
|
@@ -31,6 +33,21 @@ var isValidField = function isValidField(field) {
|
|
|
31
33
|
return true;
|
|
32
34
|
};
|
|
33
35
|
|
|
36
|
+
var mergeValues = function mergeValues(source, override) {
|
|
37
|
+
if (!override) return source;
|
|
38
|
+
if (!source) return objectUtils.clone(override);
|
|
39
|
+
var target = objectUtils.clone(source);
|
|
40
|
+
|
|
41
|
+
for (var key in override) {
|
|
42
|
+
if (objectUtils.hasOwnProp(override, key)) {
|
|
43
|
+
target[key] = override[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return target;
|
|
48
|
+
};
|
|
49
|
+
|
|
34
50
|
exports.isValidField = isValidField;
|
|
51
|
+
exports.mergeValues = mergeValues;
|
|
35
52
|
exports.parse = parse;
|
|
36
53
|
exports.stringify = stringify;
|
package/lib/esm/Form.js
CHANGED
|
@@ -50,14 +50,14 @@ var Form = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
50
50
|
validate: formContext.submitForm,
|
|
51
51
|
reset: formContext.resetForm,
|
|
52
52
|
validateField: formContext.validateFieldState,
|
|
53
|
-
// validateFields: formContext.va,
|
|
54
53
|
setFieldValue: formContext.setFieldValue,
|
|
55
54
|
setFieldsValue: formContext.setFieldsValue,
|
|
56
55
|
getFieldValue: formContext.getFieldValue,
|
|
57
56
|
getFieldsValue: formContext.getFieldsValue,
|
|
58
57
|
getFieldError: formContext.getFieldError,
|
|
59
58
|
getFieldsError: formContext.getFieldsError,
|
|
60
|
-
clearValidates: formContext.resetErrors
|
|
59
|
+
clearValidates: formContext.resetErrors,
|
|
60
|
+
clearFieldValidate: formContext.resetFieldError
|
|
61
61
|
};
|
|
62
62
|
});
|
|
63
63
|
var providedValue = useMemo(function () {
|
package/lib/esm/FormSubmit.js
CHANGED
|
@@ -47,8 +47,10 @@ var FormSubmit = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
47
47
|
evt.preventDefault();
|
|
48
48
|
evt.stopPropagation();
|
|
49
49
|
submitForm().then(function (result) {
|
|
50
|
+
// @ts-ignore
|
|
50
51
|
_onClick === null || _onClick === void 0 ? void 0 : _onClick(result, null);
|
|
51
52
|
})["catch"](function (error) {
|
|
53
|
+
// @ts-ignore
|
|
52
54
|
_onClick === null || _onClick === void 0 ? void 0 : _onClick(null, error);
|
|
53
55
|
});
|
|
54
56
|
}
|
package/lib/esm/use-form.js
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
11
11
|
import { __rest, __awaiter } from 'tslib';
|
|
12
|
-
import { stringify, parse, isValidField } from './utils/index.js';
|
|
12
|
+
import { stringify, parse, mergeValues, 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
|
-
import { isArray,
|
|
15
|
+
import { isArray, isFunction, isObjectLike } from '@hi-ui/type-assertion';
|
|
16
16
|
import { callAllFuncs } from '@hi-ui/func-utils';
|
|
17
17
|
import { getNested, setNested } from '@hi-ui/object-utils';
|
|
18
18
|
import { stopEvent } from '@hi-ui/dom-utils';
|
|
@@ -282,7 +282,6 @@ var useForm = function useForm(_a) {
|
|
|
282
282
|
*/
|
|
283
283
|
|
|
284
284
|
var setFieldValue = useCallback(function (field, value, shouldValidate) {
|
|
285
|
-
// @ts-ignore
|
|
286
285
|
formDispatch({
|
|
287
286
|
type: 'SET_FIELD_VALUE',
|
|
288
287
|
payload: {
|
|
@@ -291,20 +290,20 @@ var useForm = function useForm(_a) {
|
|
|
291
290
|
}
|
|
292
291
|
}); // touched 给外部控制展示,而不是当做参数暴露
|
|
293
292
|
|
|
294
|
-
var shouldValidateField =
|
|
295
|
-
validateAfterTouched ? getNested(formState.touched, field) && shouldValidate : shouldValidate;
|
|
293
|
+
var shouldValidateField = validateAfterTouched ? getNested(formState.touched, field) && shouldValidate : shouldValidate;
|
|
296
294
|
|
|
297
295
|
if (shouldValidateField) {
|
|
298
296
|
validateField(field, value);
|
|
299
297
|
}
|
|
300
298
|
}, [validateField, validateAfterTouched, formState]);
|
|
301
|
-
var setFieldsValue = useCallback(function (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
299
|
+
var setFieldsValue = useCallback(function (fieldsState) {
|
|
300
|
+
formDispatch({
|
|
301
|
+
type: 'SET_VALUES',
|
|
302
|
+
payload: function payload(prevState) {
|
|
303
|
+
return isFunction(fieldsState) ? fieldsState(prevState) : mergeValues(prevState, fieldsState);
|
|
304
|
+
}
|
|
306
305
|
});
|
|
307
|
-
}, [
|
|
306
|
+
}, []);
|
|
308
307
|
var normalizeValueFromChange = useCallback(function (eventOrValue, valuePropName) {
|
|
309
308
|
var nextValue = eventOrValue;
|
|
310
309
|
|
|
@@ -512,11 +511,13 @@ var useForm = function useForm(_a) {
|
|
|
512
511
|
}, [resetForm]);
|
|
513
512
|
var resetErrors = useCallback(function () {
|
|
514
513
|
formDispatch({
|
|
515
|
-
// TODO: reset errorMsg
|
|
516
514
|
type: 'SET_ERRORS',
|
|
517
515
|
payload: {}
|
|
518
516
|
});
|
|
519
517
|
}, []);
|
|
518
|
+
var resetFieldError = useCallback(function (field) {
|
|
519
|
+
setFieldError(field, '');
|
|
520
|
+
}, [setFieldError]);
|
|
520
521
|
var setFormState = React.useCallback(function (stateOrFunc) {
|
|
521
522
|
// @ts-ignore
|
|
522
523
|
formDispatch({
|
|
@@ -582,14 +583,14 @@ var useForm = function useForm(_a) {
|
|
|
582
583
|
submitForm: submitForm,
|
|
583
584
|
resetForm: resetForm,
|
|
584
585
|
resetErrors: resetErrors,
|
|
586
|
+
resetFieldError: resetFieldError,
|
|
585
587
|
validateFieldState: validateFieldState,
|
|
586
588
|
validateValue: validateField,
|
|
587
589
|
getFieldsValue: getFieldsValue,
|
|
588
590
|
setFieldsValue: setFieldsValue,
|
|
589
591
|
getFieldsError: getFieldsError
|
|
590
592
|
});
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
+
};
|
|
593
594
|
|
|
594
595
|
function formReducer(state, action) {
|
|
595
596
|
switch (action.type) {
|
|
@@ -598,8 +599,9 @@ function formReducer(state, action) {
|
|
|
598
599
|
return Object.assign(Object.assign({}, state), nextState);
|
|
599
600
|
|
|
600
601
|
case 'SET_VALUES':
|
|
602
|
+
var nextValues = isFunction(action.payload) ? action.payload(state.values) : action.payload;
|
|
601
603
|
return Object.assign(Object.assign({}, state), {
|
|
602
|
-
values:
|
|
604
|
+
values: nextValues
|
|
603
605
|
});
|
|
604
606
|
|
|
605
607
|
case 'SET_ERRORS':
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
import { isNullish, isArray } from '@hi-ui/type-assertion';
|
|
11
|
+
import { clone, hasOwnProp } from '@hi-ui/object-utils';
|
|
11
12
|
|
|
12
13
|
var stringify = function stringify(field) {
|
|
13
14
|
return JSON.stringify(field);
|
|
@@ -25,4 +26,18 @@ var isValidField = function isValidField(field) {
|
|
|
25
26
|
return true;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
var mergeValues = function mergeValues(source, override) {
|
|
30
|
+
if (!override) return source;
|
|
31
|
+
if (!source) return clone(override);
|
|
32
|
+
var target = clone(source);
|
|
33
|
+
|
|
34
|
+
for (var key in override) {
|
|
35
|
+
if (hasOwnProp(override, key)) {
|
|
36
|
+
target[key] = override[key];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return target;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { isValidField, mergeValues, parse, stringify };
|
package/lib/types/FormField.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { UseFormFieldProps } from './use-form-field';
|
|
3
|
-
import { FormFieldRenderFunc } from './types';
|
|
4
3
|
/**
|
|
5
4
|
* TODO: What is FormField
|
|
6
5
|
*/
|
|
@@ -9,9 +8,9 @@ export interface FormFieldProps extends UseFormFieldProps {
|
|
|
9
8
|
/**
|
|
10
9
|
* 表单控件
|
|
11
10
|
*/
|
|
12
|
-
children?: React.
|
|
11
|
+
children?: React.ReactNode;
|
|
13
12
|
/**
|
|
14
13
|
* 支持表单控件 render 渲染
|
|
15
14
|
*/
|
|
16
|
-
render?:
|
|
15
|
+
render?: (props: Record<string, any>) => React.ReactNode;
|
|
17
16
|
}
|
package/lib/types/FormItem.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ import { FormLabelProps } from './FormLabel';
|
|
|
7
7
|
export declare const FormItem: React.FC<FormItemProps>;
|
|
8
8
|
export interface FormItemProps extends UseFormFieldProps, FormLabelProps {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* 表单控件或其渲染函数
|
|
11
11
|
*/
|
|
12
|
-
children?: React.
|
|
12
|
+
children?: React.ReactNode;
|
|
13
13
|
/**
|
|
14
14
|
* 支持表单控件 render 渲染
|
|
15
15
|
*/
|
|
16
|
-
render?: (props: Record<string, any>) =>
|
|
16
|
+
render?: (props: Record<string, any>) => any;
|
|
17
17
|
}
|
package/lib/types/FormLabel.d.ts
CHANGED
package/lib/types/FormList.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FormListChildrenAction } from './types';
|
|
2
|
+
import { FormFieldPath, FormListChildrenAction } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* TODO: What is FormList
|
|
5
5
|
*/
|
|
6
6
|
export declare const FormList: React.FC<FormListProps>;
|
|
7
7
|
export interface FormListProps {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* 表单控件渲染函数
|
|
10
10
|
*/
|
|
11
|
-
children?: (fields: any[], action: FormListChildrenAction) => React.ReactElement
|
|
11
|
+
children?: (fields: any[], action: FormListChildrenAction) => React.ReactElement;
|
|
12
12
|
/**
|
|
13
13
|
* 列表名称
|
|
14
14
|
*/
|
|
15
|
-
name:
|
|
15
|
+
name: FormFieldPath;
|
|
16
16
|
}
|
package/lib/types/FormReset.d.ts
CHANGED
|
@@ -5,5 +5,8 @@ import { ButtonProps } from '@hi-ui/button';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const FormReset: React.ForwardRefExoticComponent<FormResetProps & React.RefAttributes<HTMLButtonElement | null>>;
|
|
7
7
|
export interface FormResetProps extends ButtonProps {
|
|
8
|
+
/**
|
|
9
|
+
* 点击重置后触发
|
|
10
|
+
*/
|
|
8
11
|
onClick?: () => void;
|
|
9
12
|
}
|
|
@@ -5,5 +5,8 @@ import { ButtonProps } from '@hi-ui/button';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const FormSubmit: React.ForwardRefExoticComponent<FormSubmitProps & React.RefAttributes<HTMLAnchorElement | HTMLButtonElement | null>>;
|
|
7
7
|
export interface FormSubmitProps extends Omit<ButtonProps, 'onClick'> {
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* 点击提交后触发
|
|
10
|
+
*/
|
|
11
|
+
onClick?: () => void;
|
|
9
12
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RuleItem } from 'async-validator';
|
|
2
|
-
import React from 'react';
|
|
3
2
|
export interface FormState<T> {
|
|
4
3
|
/**
|
|
5
4
|
* 字段及值的映射存储
|
|
@@ -41,19 +40,19 @@ export declare type FormAction<T> = {
|
|
|
41
40
|
} | {
|
|
42
41
|
type: 'SET_FIELD_VALUE';
|
|
43
42
|
payload: {
|
|
44
|
-
field:
|
|
43
|
+
field: FormFieldPath;
|
|
45
44
|
value?: any;
|
|
46
45
|
};
|
|
47
46
|
} | {
|
|
48
47
|
type: 'SET_FIELD_TOUCHED';
|
|
49
48
|
payload: {
|
|
50
|
-
field:
|
|
49
|
+
field: FormFieldPath;
|
|
51
50
|
value?: boolean;
|
|
52
51
|
};
|
|
53
52
|
} | {
|
|
54
53
|
type: 'SET_FIELD_ERROR';
|
|
55
54
|
payload: {
|
|
56
|
-
field:
|
|
55
|
+
field: FormFieldPath;
|
|
57
56
|
value?: string;
|
|
58
57
|
};
|
|
59
58
|
} | {
|
|
@@ -85,41 +84,38 @@ export interface FormHelpers<T = any> {
|
|
|
85
84
|
*/
|
|
86
85
|
validate: () => Promise<T>;
|
|
87
86
|
/**
|
|
88
|
-
* 重置整个表单的验证,对应 Form.Reset中的 API
|
|
87
|
+
* 重置整个表单的验证,对应 Form.Reset中的 API,如果不知道 nextState,则重置为 initialValues
|
|
89
88
|
*/
|
|
90
|
-
reset: (
|
|
89
|
+
reset: (nextState?: Partial<FormState<any>>) => Promise<T>;
|
|
91
90
|
/**
|
|
92
91
|
* 对指定表单字段进行校验
|
|
93
92
|
*/
|
|
94
|
-
validateField: (fields
|
|
93
|
+
validateField: (fields: FormFieldPath) => Promise<T>;
|
|
95
94
|
/**
|
|
96
|
-
*
|
|
97
|
-
*/
|
|
98
|
-
validateFields: (fields?: FormFieldPath) => Promise<T>;
|
|
99
|
-
/**
|
|
100
|
-
* 设置表单的值,在异步获取的数据回显的时候,使用该方法
|
|
95
|
+
* 设置某个表单字段的值,在更新表单数据的的时候,使用该方法
|
|
101
96
|
*/
|
|
102
97
|
setFieldValue: (field: FormFieldPath, value: any) => void;
|
|
103
98
|
/**
|
|
104
99
|
* 设置多个表单的值,在异步获取的数据回显的时候,使用该方法
|
|
100
|
+
* TODO
|
|
105
101
|
*/
|
|
106
|
-
setFieldsValue: (field: Record<string, any>) => void;
|
|
102
|
+
setFieldsValue: (field: Record<string, any> | ((prevValues: Record<string, any>) => Record<string, any>)) => void;
|
|
107
103
|
/**
|
|
108
|
-
* 获取一个字段名对应的
|
|
104
|
+
* 获取一个字段名对应的 Value,返回为对应 Field 值
|
|
109
105
|
*/
|
|
110
106
|
getFieldValue: (field: FormFieldPath) => any;
|
|
111
107
|
/**
|
|
112
|
-
* 获取所有字段名对应的 Values
|
|
108
|
+
* 获取所有字段名对应的 Values 返回为字典映射数据结构
|
|
113
109
|
*/
|
|
114
110
|
getFieldsValue: () => any;
|
|
115
111
|
/**
|
|
116
|
-
*
|
|
112
|
+
* 获取一组字段名对应的 errorMessage,返回为对应 field 错误信息
|
|
117
113
|
*/
|
|
118
114
|
getFieldError: (field: FormFieldPath) => any;
|
|
119
115
|
/**
|
|
120
|
-
*
|
|
116
|
+
* 获取所有字段名对应的错误信息,返回为字典映射数据结构
|
|
121
117
|
*/
|
|
122
|
-
getFieldsError: () => any
|
|
118
|
+
getFieldsError: () => FormErrors<any>;
|
|
123
119
|
/**
|
|
124
120
|
* 移除所有表单项的校验结果
|
|
125
121
|
*/
|
|
@@ -127,12 +123,11 @@ export interface FormHelpers<T = any> {
|
|
|
127
123
|
/**
|
|
128
124
|
* 移除表单项的校验结果,传入待移除的表单项的 field 属性组成的数组
|
|
129
125
|
*/
|
|
130
|
-
|
|
126
|
+
clearFieldValidate: (fields: FormFieldPath) => void;
|
|
131
127
|
}
|
|
132
128
|
export declare type FormFieldPath = (string | number)[] | string | number;
|
|
133
129
|
export declare type FormErrorMessage = string;
|
|
134
130
|
export declare type FormRules = Record<string, FormRuleModel[]>;
|
|
135
|
-
export declare type FormFieldRenderFunc = (props: Record<string, any>) => React.ReactElement;
|
|
136
131
|
export interface FormListChildrenAction {
|
|
137
132
|
/**
|
|
138
133
|
* 在尾部追加一个 FormItems
|
package/lib/types/use-form.d.ts
CHANGED
|
@@ -9,21 +9,22 @@ export declare const useForm: <Values = Record<string, any>>({ initialValues, in
|
|
|
9
9
|
getFieldError: (fieldName: FormFieldPath) => any;
|
|
10
10
|
getFieldRules: (fieldName: FormFieldPath) => any;
|
|
11
11
|
getRootProps: () => {
|
|
12
|
-
onSubmit: (evt?: React.FormEvent<HTMLFormElement> | undefined) => Promise<
|
|
12
|
+
onSubmit: (evt?: React.FormEvent<HTMLFormElement> | undefined) => Promise<any>;
|
|
13
13
|
onReset: (evt?: React.FormEvent<HTMLFormElement> | undefined) => void;
|
|
14
14
|
};
|
|
15
15
|
getFieldProps: (props?: any) => any;
|
|
16
16
|
registerField: (keyOrKeys: FormFieldPath, value: FormFieldCollection<Values>) => void;
|
|
17
17
|
unregisterField: (keyOrKeys: FormFieldPath) => void;
|
|
18
|
-
submitForm: () => Promise<
|
|
18
|
+
submitForm: () => Promise<any>;
|
|
19
19
|
resetForm: (nextState?: Partial<FormState<any>> | undefined) => Promise<void>;
|
|
20
20
|
resetErrors: () => void;
|
|
21
|
+
resetFieldError: (field: FormFieldPath) => void;
|
|
21
22
|
validateFieldState: (field: FormFieldPath) => Promise<{} | undefined>;
|
|
22
23
|
validateValue: (field: FormFieldPath, value: unknown) => Promise<{} | undefined>;
|
|
23
24
|
getFieldsValue: () => any;
|
|
24
|
-
setFieldsValue: (
|
|
25
|
+
setFieldsValue: (fieldsState: Record<string, any> | Function) => void;
|
|
25
26
|
getFieldsError: () => any;
|
|
26
|
-
values:
|
|
27
|
+
values: any;
|
|
27
28
|
errors: FormErrors<unknown>;
|
|
28
29
|
touched: import("./types").FormTouched<unknown>;
|
|
29
30
|
validating: boolean;
|
|
@@ -31,7 +32,7 @@ export declare const useForm: <Values = Record<string, any>>({ initialValues, in
|
|
|
31
32
|
};
|
|
32
33
|
export interface UseFormProps<T = Record<string, any>> {
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
+
* 初始化表单值,只在初始化以及重置时生效;该值是不受控的,和表单中的 defaultValue 的作用类似
|
|
35
36
|
*/
|
|
36
37
|
initialValues: T;
|
|
37
38
|
/**
|
|
@@ -2,3 +2,4 @@ import { FormFieldPath } from './../types';
|
|
|
2
2
|
export declare const stringify: (field: FormFieldPath) => string;
|
|
3
3
|
export declare const parse: (fieldStr: string) => FormFieldPath;
|
|
4
4
|
export declare const isValidField: (field: FormFieldPath | undefined) => field is FormFieldPath;
|
|
5
|
+
export declare const mergeValues: <T extends Object, E extends T>(source: T, override: E | null | undefined) => T;
|
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.27",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HIUI <mi-hiui@xiaomi.com>",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@hi-ui/array-utils": "^4.0.0-beta.7",
|
|
47
|
-
"@hi-ui/button": "^4.0.0-beta.
|
|
47
|
+
"@hi-ui/button": "^4.0.0-beta.13",
|
|
48
48
|
"@hi-ui/classname": "^4.0.0-beta.0",
|
|
49
49
|
"@hi-ui/core-css": "^4.0.0-beta.5",
|
|
50
50
|
"@hi-ui/dom-utils": "^4.0.0-beta.5",
|
|
51
51
|
"@hi-ui/env": "^4.0.0-beta.0",
|
|
52
|
-
"@hi-ui/func-utils": "^4.0.0-beta.
|
|
53
|
-
"@hi-ui/locale-context": "^4.0.0-beta.
|
|
54
|
-
"@hi-ui/object-utils": "^4.0.0-beta.
|
|
52
|
+
"@hi-ui/func-utils": "^4.0.0-beta.12",
|
|
53
|
+
"@hi-ui/locale-context": "^4.0.0-beta.18",
|
|
54
|
+
"@hi-ui/object-utils": "^4.0.0-beta.11",
|
|
55
55
|
"@hi-ui/type-assertion": "^4.0.0-beta.4",
|
|
56
56
|
"@hi-ui/use-latest": "^4.0.0-beta.4",
|
|
57
57
|
"async-validator": "^4.0.7"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"react": "^17.0.1",
|
|
66
66
|
"react-dom": "^17.0.1"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "64cc3305632f0d88f852f4a95cba7c27ff388a2d"
|
|
69
69
|
}
|