@hi-ui/form 4.0.9 → 4.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ # @hi-ui/form
2
+
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2336](https://github.com/XiaoMi/hiui/pull/2336) [`bb2de106e`](https://github.com/XiaoMi/hiui/commit/bb2de106ee471f47a6f7223b6297e707f42d0278) Thanks [@zyprepare](https://github.com/zyprepare)! - FormList 对外暴露内部 add remove 等方法
@@ -38,9 +38,10 @@ var fieldListSymbol = Symbol('field-list');
38
38
  * TODO: What is FormList
39
39
  */
40
40
 
41
- var FormList = function FormList(_ref) {
41
+ var FormList = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
42
  var children = _ref.children,
43
- nameProp = _ref.name;
43
+ nameProp = _ref.name,
44
+ innerRef = _ref.innerRef;
44
45
 
45
46
  var _useFormContext = context.useFormContext(),
46
47
  values = _useFormContext.values,
@@ -128,7 +129,17 @@ var FormList = function FormList(_ref) {
128
129
  value: value
129
130
  };
130
131
  });
131
- }, [values, name]);
132
+ }, [values, name]); // @ts-ignore
133
+
134
+ React.useImperativeHandle(innerRef, function () {
135
+ return {
136
+ add: add,
137
+ remove: remove,
138
+ insertBefore: insertBefore,
139
+ swap: swap,
140
+ move: move
141
+ };
142
+ });
132
143
 
133
144
  if (typeof children !== 'function') {
134
145
  if (env.__DEV__) {
@@ -145,7 +156,7 @@ var FormList = function FormList(_ref) {
145
156
  insertBefore: insertBefore,
146
157
  move: move
147
158
  });
148
- };
159
+ });
149
160
 
150
161
  if (env.__DEV__) {
151
162
  FormList.displayName = 'FormList';
@@ -7,7 +7,7 @@
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 React from 'react';
10
+ import React, { forwardRef, useImperativeHandle } from 'react';
11
11
  import { __DEV__ } from '@hi-ui/env';
12
12
  import { useFormContext } from './context.js';
13
13
  import { setNested, getNested } from '@hi-ui/object-utils';
@@ -17,9 +17,10 @@ var fieldListSymbol = Symbol('field-list');
17
17
  * TODO: What is FormList
18
18
  */
19
19
 
20
- var FormList = function FormList(_ref) {
20
+ var FormList = /*#__PURE__*/forwardRef(function (_ref, ref) {
21
21
  var children = _ref.children,
22
- nameProp = _ref.name;
22
+ nameProp = _ref.name,
23
+ innerRef = _ref.innerRef;
23
24
 
24
25
  var _useFormContext = useFormContext(),
25
26
  values = _useFormContext.values,
@@ -107,7 +108,17 @@ var FormList = function FormList(_ref) {
107
108
  value: value
108
109
  };
109
110
  });
110
- }, [values, name]);
111
+ }, [values, name]); // @ts-ignore
112
+
113
+ useImperativeHandle(innerRef, function () {
114
+ return {
115
+ add: add,
116
+ remove: remove,
117
+ insertBefore: insertBefore,
118
+ swap: swap,
119
+ move: move
120
+ };
121
+ });
111
122
 
112
123
  if (typeof children !== 'function') {
113
124
  if (__DEV__) {
@@ -124,7 +135,7 @@ var FormList = function FormList(_ref) {
124
135
  insertBefore: insertBefore,
125
136
  move: move
126
137
  });
127
- };
138
+ });
128
139
 
129
140
  if (__DEV__) {
130
141
  FormList.displayName = 'FormList';
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
- import { FormFieldPath, FormListChildrenAction } from './types';
2
+ import { HiBaseHTMLProps } from '@hi-ui/core';
3
+ import { FormFieldPath, FormListChildrenAction, FormListHelper } from './types';
3
4
  /**
4
5
  * TODO: What is FormList
5
6
  */
6
- export declare const FormList: React.FC<FormListProps>;
7
- export interface FormListProps {
7
+ export declare const FormList: React.ForwardRefExoticComponent<FormListProps & React.RefAttributes<HTMLDivElement | null>>;
8
+ export interface FormListProps extends HiBaseHTMLProps<'div'> {
8
9
  /**
9
10
  * 表单控件渲染函数
10
11
  */
@@ -13,4 +14,8 @@ export interface FormListProps {
13
14
  * 列表名称
14
15
  */
15
16
  name: FormFieldPath;
17
+ /**
18
+ * 提供辅助方法的内部引用
19
+ */
20
+ innerRef?: React.Ref<FormListHelper>;
16
21
  }
@@ -2,7 +2,7 @@
2
2
  import './styles/index.scss';
3
3
  declare const Form: import("react").ForwardRefExoticComponent<import("./Form").FormProps<Record<string, any>> & import("react").RefAttributes<HTMLFormElement | null>> & {
4
4
  Item: import("react").FC<import("./FormItem").FormItemProps>;
5
- List: import("react").FC<import("./FormList").FormListProps>;
5
+ List: import("react").ForwardRefExoticComponent<import("./FormList").FormListProps & import("react").RefAttributes<HTMLDivElement | null>>;
6
6
  Submit: import("react").ForwardRefExoticComponent<import("./FormSubmit").FormSubmitProps & import("react").RefAttributes<HTMLAnchorElement | HTMLButtonElement | null>>;
7
7
  Reset: import("react").ForwardRefExoticComponent<import("./FormReset").FormResetProps & import("react").RefAttributes<HTMLButtonElement | null>>;
8
8
  };
@@ -125,6 +125,28 @@ export interface FormHelpers<T = any> {
125
125
  */
126
126
  clearFieldValidate: (fields: FormFieldPath) => void;
127
127
  }
128
+ export interface FormListHelper {
129
+ /**
130
+ * 动态添加表单
131
+ */
132
+ add: (value: any) => void;
133
+ /**
134
+ * 动态删除表单
135
+ */
136
+ remove: (index: number) => void;
137
+ /**
138
+ * 在 index 之前插入
139
+ */
140
+ insertBefore: (index: number, value: any) => void;
141
+ /**
142
+ * 置换表单值
143
+ */
144
+ swap: (aIndex: number, bIndex: number) => void;
145
+ /**
146
+ * 移动表单值
147
+ */
148
+ move: (fromIndex: number, toIndex: number) => void;
149
+ }
128
150
  export declare type FormFieldPath = (string | number)[] | string | number;
129
151
  export declare type FormErrorMessage = string;
130
152
  export declare type FormRules = Record<string, FormRuleModel[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/form",
3
- "version": "4.0.9",
3
+ "version": "4.1.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -65,6 +65,5 @@
65
65
  "@hi-ui/hi-build": "^4.0.1",
66
66
  "react": "^17.0.1",
67
67
  "react-dom": "^17.0.1"
68
- },
69
- "gitHead": "619fb2b1774e927c016d9e58117fd4bf0d0364f3"
68
+ }
70
69
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Xiaomi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.