@hi-ui/form 4.3.0 → 4.3.2

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @hi-ui/form
2
2
 
3
+ ## 4.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3160](https://github.com/XiaoMi/hiui/pull/3160) [`3244e5a`](https://github.com/XiaoMi/hiui/commit/3244e5a94d1cfa3d85a65bc8804a21b8b60b80a4) Thanks [@zyprepare](https://github.com/zyprepare)! - <br>
8
+ - feat(form): 入口新增 FormLabel 组件导出
9
+ - feat(form): 更新 FormListProps 中 children 渲染函数中 fields 参数的类型
10
+
11
+ ## 4.3.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [#3121](https://github.com/XiaoMi/hiui/pull/3121) [`a6eb8cb`](https://github.com/XiaoMi/hiui/commit/a6eb8cbfda696dfeee147d6adba9805ecb8af5d0) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(form): 更新 FormItemProps 的 children 类型以支持渲染函数,并修复 useForm 中对 formState 的引用问题 (#3120)
16
+
3
17
  ## 4.3.0
4
18
 
5
19
  ### Minor 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;
@@ -430,7 +430,7 @@ var useForm = function useForm(_a) {
430
430
  var promiseOrUndefined;
431
431
  try {
432
432
  // @ts-ignore
433
- promiseOrUndefined = onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(formState.values);
433
+ promiseOrUndefined = onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(formStateRef.current.values);
434
434
  } catch (error) {
435
435
  formDispatch({
436
436
  type: 'SUBMIT_DONE'
@@ -442,7 +442,7 @@ var useForm = function useForm(_a) {
442
442
  type: 'SUBMIT_DONE'
443
443
  });
444
444
  // return combinedErrors
445
- return formState.values;
445
+ return formStateRef.current.values;
446
446
  }
447
447
  return Promise.resolve(promiseOrUndefined).then(function (result) {
448
448
  formDispatch({
@@ -450,7 +450,7 @@ var useForm = function useForm(_a) {
450
450
  });
451
451
  // return result
452
452
  // TODO: 满足promise 如果既给到values 又给到 errors
453
- return formState.values;
453
+ return formStateRef.current.values;
454
454
  })["catch"](function (_errors) {
455
455
  formDispatch({
456
456
  type: 'SUBMIT_DONE'
@@ -480,7 +480,7 @@ var useForm = function useForm(_a) {
480
480
  }
481
481
  }, _callee3);
482
482
  }));
483
- }, [formState, onSubmit, validateAll]);
483
+ }, [formStateRef, onSubmit, validateAll]);
484
484
  var handleSubmit = React.useCallback(function (evt) {
485
485
  domUtils.stopEvent(evt);
486
486
  return submitForm();
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,
@@ -417,7 +417,7 @@ var useForm = function useForm(_a) {
417
417
  var promiseOrUndefined;
418
418
  try {
419
419
  // @ts-ignore
420
- promiseOrUndefined = onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(formState.values);
420
+ promiseOrUndefined = onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(formStateRef.current.values);
421
421
  } catch (error) {
422
422
  formDispatch({
423
423
  type: 'SUBMIT_DONE'
@@ -429,7 +429,7 @@ var useForm = function useForm(_a) {
429
429
  type: 'SUBMIT_DONE'
430
430
  });
431
431
  // return combinedErrors
432
- return formState.values;
432
+ return formStateRef.current.values;
433
433
  }
434
434
  return Promise.resolve(promiseOrUndefined).then(function (result) {
435
435
  formDispatch({
@@ -437,7 +437,7 @@ var useForm = function useForm(_a) {
437
437
  });
438
438
  // return result
439
439
  // TODO: 满足promise 如果既给到values 又给到 errors
440
- return formState.values;
440
+ return formStateRef.current.values;
441
441
  })["catch"](function (_errors) {
442
442
  formDispatch({
443
443
  type: 'SUBMIT_DONE'
@@ -467,7 +467,7 @@ var useForm = function useForm(_a) {
467
467
  }
468
468
  }, _callee3);
469
469
  }));
470
- }, [formState, onSubmit, validateAll]);
470
+ }, [formStateRef, onSubmit, validateAll]);
471
471
  var handleSubmit = useCallback(function (evt) {
472
472
  stopEvent(evt);
473
473
  return submitForm();
@@ -6,7 +6,7 @@ export interface FormItemProps extends UseFormFieldProps, FormLabelProps {
6
6
  /**
7
7
  * 表单控件或其渲染函数
8
8
  */
9
- children?: React.ReactNode;
9
+ children?: React.ReactNode | ((props: Record<string, any>) => React.ReactNode);
10
10
  /**
11
11
  * 支持表单控件 render 渲染
12
12
  */
@@ -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: any[], action: FormListChildrenAction) => React.ReactElement;
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 {};
@@ -12,4 +12,5 @@ export * from './FormItem';
12
12
  export * from './FormList';
13
13
  export * from './FormSubmit';
14
14
  export * from './FormReset';
15
+ export * from './FormLabel';
15
16
  export * from './types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/form",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",