@hi-ui/form 4.0.0-alpha.1 → 4.0.0-alpha.6

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.
Files changed (55) hide show
  1. package/lib/cjs/Form.js +26 -6
  2. package/lib/cjs/Form.js.map +1 -1
  3. package/lib/cjs/FormItem.js +29 -5
  4. package/lib/cjs/FormItem.js.map +1 -1
  5. package/lib/cjs/FormLabel.js +1 -1
  6. package/lib/cjs/FormLabel.js.map +1 -1
  7. package/lib/cjs/FormList.js +2 -2
  8. package/lib/cjs/FormList.js.map +1 -1
  9. package/lib/cjs/FormMessage.js +3 -3
  10. package/lib/cjs/FormMessage.js.map +1 -1
  11. package/lib/cjs/FormReset.js +76 -0
  12. package/lib/cjs/FormReset.js.map +1 -0
  13. package/lib/cjs/FormSubmit.js +87 -0
  14. package/lib/cjs/FormSubmit.js.map +1 -0
  15. package/lib/cjs/index.js +6 -0
  16. package/lib/cjs/index.js.map +1 -1
  17. package/lib/cjs/styles/index.scss.js +1 -1
  18. package/lib/cjs/use-form-field.js +14 -32
  19. package/lib/cjs/use-form-field.js.map +1 -1
  20. package/lib/cjs/use-form.js +130 -57
  21. package/lib/cjs/use-form.js.map +1 -1
  22. package/lib/cjs/utils/index.js +26 -0
  23. package/lib/cjs/utils/index.js.map +1 -0
  24. package/lib/esm/Form.js +26 -6
  25. package/lib/esm/Form.js.map +1 -1
  26. package/lib/esm/FormItem.js +27 -5
  27. package/lib/esm/FormItem.js.map +1 -1
  28. package/lib/esm/FormLabel.js +1 -1
  29. package/lib/esm/FormLabel.js.map +1 -1
  30. package/lib/esm/FormList.js +2 -2
  31. package/lib/esm/FormList.js.map +1 -1
  32. package/lib/esm/FormMessage.js +3 -3
  33. package/lib/esm/FormMessage.js.map +1 -1
  34. package/lib/esm/FormReset.js +52 -0
  35. package/lib/esm/FormReset.js.map +1 -0
  36. package/lib/esm/FormSubmit.js +63 -0
  37. package/lib/esm/FormSubmit.js.map +1 -0
  38. package/lib/esm/index.js +2 -0
  39. package/lib/esm/index.js.map +1 -1
  40. package/lib/esm/styles/index.scss.js +1 -1
  41. package/lib/esm/use-form-field.js +15 -33
  42. package/lib/esm/use-form-field.js.map +1 -1
  43. package/lib/esm/use-form.js +131 -59
  44. package/lib/esm/use-form.js.map +1 -1
  45. package/lib/esm/utils/index.js +19 -0
  46. package/lib/esm/utils/index.js.map +1 -0
  47. package/lib/types/FormReset.d.ts +2 -1
  48. package/lib/types/FormSubmit.d.ts +3 -2
  49. package/lib/types/context.d.ts +30 -16
  50. package/lib/types/index.d.ts +2 -0
  51. package/lib/types/types.d.ts +34 -12
  52. package/lib/types/use-form-field.d.ts +9 -5
  53. package/lib/types/use-form.d.ts +15 -8
  54. package/lib/types/utils/index.d.ts +3 -0
  55. package/package.json +11 -11
@@ -3,17 +3,17 @@ export declare const useFormField: <Values = any>(props: UseFormFieldProps<Value
3
3
  [x: number]: unknown;
4
4
  ref: any;
5
5
  onBlur: (...args: any) => void;
6
- invalid: unknown;
6
+ invalid: any;
7
7
  };
8
8
  export interface UseFormFieldProps<T = Record<string, any>> {
9
9
  /**
10
10
  * 字段名,支持数组
11
11
  */
12
- field: FormFieldPath;
12
+ field: FormFieldPath | null;
13
13
  /**
14
14
  * 指定控件值数据结构类型
15
15
  */
16
- valueType: 'string' | 'boolean' | 'number' | 'array' | 'object' | 'date';
16
+ valueType: 'string' | 'boolean' | 'number' | 'array' | 'object' | 'date' | null;
17
17
  /**
18
18
  * 设置字段的验证规则,会覆盖 Form 设置的 rules
19
19
  */
@@ -25,11 +25,15 @@ export interface UseFormFieldProps<T = Record<string, any>> {
25
25
  /**
26
26
  * form 从控件个体采集数据的转换器,最终会把返回值转发给 Form
27
27
  */
28
- valueSync?: (value: any) => T;
28
+ valueCollectPipe?: (value: any) => T;
29
+ /**
30
+ * 控件个体接收 form 下发数据的转换器,最终会把返回值转发给 FormField
31
+ */
32
+ valueSyncPipe?: (value: any) => T;
29
33
  /**
30
34
  * 自定义设置 Form 从表单控件采集数据回调的属性
31
35
  */
32
- onChangePropName?: string;
36
+ valueCollectPropName?: string;
33
37
  /**
34
38
  * 设置触发该字段校验的时机,会覆盖 Form 设置的 validateTrigger
35
39
  */
@@ -2,25 +2,32 @@ import React from 'react';
2
2
  import { FormState, FormFieldCollection, FormErrors, FormRuleModel, FormFieldPath, FormErrorMessage, FormSetState } from './types';
3
3
  export declare const useForm: <Values = Record<string, any>>({ initialValues, initialErrors, initialTouched, lazyValidate, onValuesChange, onReset, onSubmit, rules, validateAfterTouched, validateTrigger: validateTriggerProp, ...rest }: UseFormProps<Values>) => {
4
4
  setFormState: (stateOrFunc: FormSetState<Values>) => void;
5
- setFieldValue: (field: string, value: unknown, shouldValidate?: boolean | undefined) => void;
5
+ setFieldValue: (field: FormFieldPath, value: unknown, shouldValidate?: boolean | undefined) => void;
6
6
  setFieldError: (field: FormFieldPath, errorMessage: FormErrorMessage | undefined) => void;
7
7
  setFieldTouched: (field: FormFieldPath, touched?: any) => void;
8
- getFieldError: (fieldName: string) => unknown;
9
- getFieldRules: (fieldName: string) => import("async-validator").RuleItem[];
8
+ getFieldValue: (fieldName: FormFieldPath) => any;
9
+ getFieldError: (fieldName: FormFieldPath) => any;
10
+ getFieldRules: (fieldName: FormFieldPath) => any;
10
11
  getRootProps: () => {
11
- onSubmit: (evt?: React.FormEvent<HTMLFormElement> | undefined) => void;
12
+ onSubmit: (evt?: React.FormEvent<HTMLFormElement> | undefined) => Promise<unknown>;
12
13
  onReset: (evt?: React.FormEvent<HTMLFormElement> | undefined) => void;
13
14
  };
14
15
  getFieldProps: (props?: any, ref?: any) => {
15
16
  [x: number]: unknown;
16
17
  ref: any;
17
18
  onBlur: (...args: any) => void;
18
- invalid: unknown;
19
+ invalid: any;
19
20
  };
20
- registerField: (key: string, value: FormFieldCollection<Values>) => void;
21
- unregisterField: (key: string) => void;
22
- submitForm: () => Promise<undefined>;
21
+ registerField: (keyOrKeys: FormFieldPath, value: FormFieldCollection<Values>) => void;
22
+ unregisterField: (keyOrKeys: FormFieldPath) => void;
23
+ submitForm: () => Promise<unknown>;
23
24
  resetForm: (nextState?: Partial<FormState<any>> | undefined) => Promise<void>;
25
+ resetErrors: () => void;
26
+ validateFieldState: (field: FormFieldPath) => Promise<{} | undefined>;
27
+ validateValue: (field: FormFieldPath, value: unknown) => Promise<{} | undefined>;
28
+ getFieldsValue: () => any;
29
+ setFieldsValue: (fields: Record<string, any>, shouldValidate?: boolean | undefined) => void;
30
+ getFieldsError: () => any;
24
31
  values: unknown;
25
32
  errors: FormErrors<unknown>;
26
33
  touched: import("./types").FormTouched<unknown>;
@@ -1 +1,4 @@
1
+ import { FormFieldPath } from './../types';
1
2
  export declare const setProp: (o: any, filed: any, value: any) => any;
3
+ export declare const stringify: (field: FormFieldPath) => string;
4
+ export declare const parse: (fieldStr: string) => FormFieldPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/form",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.6",
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
  "@flcwly/validater": "^0.1.4",
47
- "@hi-ui/button": "^4.0.0-alpha.14",
48
- "@hi-ui/classname": "^4.0.0-alpha.0",
49
- "@hi-ui/core-css": "^4.0.0-alpha.9",
50
- "@hi-ui/dom-utils": "^4.0.0-alpha.5",
51
- "@hi-ui/env": "^4.0.0-alpha.4",
52
- "@hi-ui/func-utils": "^4.0.0-alpha.4",
53
- "@hi-ui/type-assertion": "^4.0.0-alpha.12",
54
- "@hi-ui/use-latest": "^4.0.0-alpha.3",
47
+ "@hi-ui/button": "^4.0.0-alpha.18",
48
+ "@hi-ui/classname": "^4.0.0-alpha.3",
49
+ "@hi-ui/core-css": "^4.0.0-alpha.11",
50
+ "@hi-ui/dom-utils": "^4.0.0-alpha.6",
51
+ "@hi-ui/env": "^4.0.0-alpha.5",
52
+ "@hi-ui/func-utils": "^4.0.0-alpha.5",
53
+ "@hi-ui/type-assertion": "^4.0.0-alpha.13",
54
+ "@hi-ui/use-latest": "^4.0.0-alpha.4",
55
55
  "async-validator": "^4.0.7",
56
56
  "yup": "^0.32.11"
57
57
  },
@@ -60,9 +60,9 @@
60
60
  "react-dom": "^17.0.1"
61
61
  },
62
62
  "devDependencies": {
63
- "@hi-ui/hi-build": "^4.0.0-alpha.0",
63
+ "@hi-ui/hi-build": "^4.0.0-alpha.4",
64
64
  "react": "^17.0.1",
65
65
  "react-dom": "^17.0.1"
66
66
  },
67
- "gitHead": "37cbc875cd26474cfc9ddbd1eeb0abd797a31835"
67
+ "gitHead": "4f087bc74252731d943e607074c9754426c7be77"
68
68
  }