@hi-ui/form 4.0.0-beta.26 → 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/FormSubmit.js +2 -0
- package/lib/cjs/use-form.js +1 -1
- package/lib/cjs/utils/index.js +17 -0
- package/lib/esm/FormSubmit.js +2 -0
- package/lib/esm/use-form.js +3 -3
- 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 +0 -2
- package/lib/types/use-form.d.ts +1 -1
- package/lib/types/utils/index.d.ts +1 -0
- package/package.json +3 -3
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
|
@@ -327,7 +327,7 @@ var useForm = function useForm(_a) {
|
|
|
327
327
|
formDispatch({
|
|
328
328
|
type: 'SET_VALUES',
|
|
329
329
|
payload: function payload(prevState) {
|
|
330
|
-
return typeAssertion.isFunction(fieldsState) ? fieldsState(prevState) :
|
|
330
|
+
return typeAssertion.isFunction(fieldsState) ? fieldsState(prevState) : index.mergeValues(prevState, fieldsState);
|
|
331
331
|
}
|
|
332
332
|
});
|
|
333
333
|
}, []);
|
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/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,12 +9,12 @@
|
|
|
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
15
|
import { isArray, isFunction, isObjectLike } from '@hi-ui/type-assertion';
|
|
16
16
|
import { callAllFuncs } from '@hi-ui/func-utils';
|
|
17
|
-
import { getNested, setNested
|
|
17
|
+
import { getNested, setNested } from '@hi-ui/object-utils';
|
|
18
18
|
import { stopEvent } from '@hi-ui/dom-utils';
|
|
19
19
|
var EMPTY_RULES = {};
|
|
20
20
|
var EMPTY_ERRORS = {};
|
|
@@ -300,7 +300,7 @@ var useForm = function useForm(_a) {
|
|
|
300
300
|
formDispatch({
|
|
301
301
|
type: 'SET_VALUES',
|
|
302
302
|
payload: function payload(prevState) {
|
|
303
|
-
return isFunction(fieldsState) ? fieldsState(prevState) :
|
|
303
|
+
return isFunction(fieldsState) ? fieldsState(prevState) : mergeValues(prevState, fieldsState);
|
|
304
304
|
}
|
|
305
305
|
});
|
|
306
306
|
}, []);
|
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
|
* 字段及值的映射存储
|
|
@@ -129,7 +128,6 @@ export interface FormHelpers<T = any> {
|
|
|
129
128
|
export declare type FormFieldPath = (string | number)[] | string | number;
|
|
130
129
|
export declare type FormErrorMessage = string;
|
|
131
130
|
export declare type FormRules = Record<string, FormRuleModel[]>;
|
|
132
|
-
export declare type FormFieldRenderFunc = (props: Record<string, any>) => React.ReactElement;
|
|
133
131
|
export interface FormListChildrenAction {
|
|
134
132
|
/**
|
|
135
133
|
* 在尾部追加一个 FormItems
|
package/lib/types/use-form.d.ts
CHANGED
|
@@ -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,7 +44,7 @@
|
|
|
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",
|
|
@@ -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
|
}
|