Comparing version 0.2.0 to 0.2.1
import { FieldArrayModel, BasicModel, FieldArrayChild, ModelRef } from './models'; | ||
import { IValidators } from './validate'; | ||
export declare type IUseFieldArray<Item, Child extends BasicModel<Item>> = [FieldArrayChild<Item, Child>[], FieldArrayModel<Item, Child>]; | ||
/** | ||
* @param field 字段名,当`FormStrategy`是`View`的时候才能用字段名 | ||
* @param validators 当`field`是字段名的时候,可以传入`validator` | ||
* @param defaultValue 默认值 | ||
*/ | ||
export declare function useFieldArray<Item, Child extends BasicModel<Item>>(field: string | ModelRef<readonly Item[], any, FieldArrayModel<Item, Child>>, validators?: IValidators<readonly (Item | null)[]>, defaultValue?: Item[]): FieldArrayModel<Item, Child>; | ||
/** | ||
* | ||
* @param field model | ||
*/ | ||
export declare function useFieldArray<Item, Child extends BasicModel<Item>>(field: FieldArrayModel<Item, Child>): FieldArrayModel<Item, Child>; | ||
//# sourceMappingURL=field-array.d.ts.map |
@@ -5,3 +5,7 @@ import { IFormContext } from './context'; | ||
export declare type IUseFieldSet<T extends Record<string, BasicModel<any>>> = [IFormContext, FieldSetModel<T>]; | ||
/** | ||
* @param field model 或者字段名,当`FormStrategy`是`View`的时候才能用字段名 | ||
* @param validators 当`field`是字段名的时候,可以传入`validator` | ||
*/ | ||
export declare function useFieldSet<T extends Record<string, BasicModel<any>>>(field: string | FieldSetModel<T> | ModelRef<$FieldSetValue<T>, any, FieldSetModel<T>>, validators?: IValidators<T>): IUseFieldSet<T>; | ||
//# sourceMappingURL=field-set.d.ts.map |
@@ -52,2 +52,6 @@ import { useMemo } from 'react'; | ||
} | ||
/** | ||
* @param field model 或者字段名,当`FormStrategy`是`View`的时候才能用字段名 | ||
* @param validators 当`field`是字段名的时候,可以传入`validator` | ||
*/ | ||
export function useFieldSet(field, validators) { | ||
@@ -54,0 +58,0 @@ if (validators === void 0) { validators = []; } |
@@ -24,3 +24,28 @@ import { FieldModel } from './models/field'; | ||
/** | ||
* This triggers a validation | ||
* 生成一个默认的`onChange`回调,这个回调会触发`model.validate` | ||
* 如果不需要在onChange的时候触发校验,如下即可: | ||
* ```js | ||
* const onChange = useCallback(value => model.value = value, [model]); | ||
* ``` | ||
* 例如是一个`input`: | ||
* ```ts | ||
* const onChange = useCallback((value: React.ChangeEvent<HTMLInputElement>) => { | ||
* model.value = e.target.value; | ||
* }, [model]); | ||
* ``` | ||
* 可以配合usePipe使用: | ||
* ```js | ||
* function mapEventToValue(e) { | ||
* return e.target.value; | ||
* } | ||
* | ||
* function Foo() { | ||
* const onChange = FieldUtils.usePipe( | ||
* mapEventToValue, | ||
* FieldUtils.makeChangeHandler(model), | ||
* ); | ||
* } | ||
* | ||
* | ||
* ``` | ||
*/ | ||
@@ -27,0 +52,0 @@ export declare function makeChangeHandler<Value>(model: FieldModel<Value>, option: ValidateOption): (value: Value) => void; |
@@ -38,3 +38,28 @@ import { useCallback, useMemo, useRef } from 'react'; | ||
/** | ||
* This triggers a validation | ||
* 生成一个默认的`onChange`回调,这个回调会触发`model.validate` | ||
* 如果不需要在onChange的时候触发校验,如下即可: | ||
* ```js | ||
* const onChange = useCallback(value => model.value = value, [model]); | ||
* ``` | ||
* 例如是一个`input`: | ||
* ```ts | ||
* const onChange = useCallback((value: React.ChangeEvent<HTMLInputElement>) => { | ||
* model.value = e.target.value; | ||
* }, [model]); | ||
* ``` | ||
* 可以配合usePipe使用: | ||
* ```js | ||
* function mapEventToValue(e) { | ||
* return e.target.value; | ||
* } | ||
* | ||
* function Foo() { | ||
* const onChange = FieldUtils.usePipe( | ||
* mapEventToValue, | ||
* FieldUtils.makeChangeHandler(model), | ||
* ); | ||
* } | ||
* | ||
* | ||
* ``` | ||
*/ | ||
@@ -41,0 +66,0 @@ export function makeChangeHandler(model, option) { |
import { FieldModel, ModelRef } from './models'; | ||
import { IValidators } from './validate'; | ||
/** | ||
* @param field 字段名,当`FormStrategy`是`View`的时候才能用字段名 | ||
* @param validators 当`field`是字段名的时候,可以传入`validator` | ||
* @param defaultValue 默认值 | ||
*/ | ||
export declare function useField<Value>(field: string, defaultValue: Value | (() => Value), validators?: IValidators<Value>): FieldModel<Value>; | ||
/** | ||
* | ||
* @param field model | ||
*/ | ||
export declare function useField<Value>(field: FieldModel<Value> | ModelRef<Value, any, FieldModel<Value>>): FieldModel<Value>; | ||
//# sourceMappingURL=field.d.ts.map |
{ | ||
"name": "formulr", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Form toolkit for React", | ||
@@ -33,3 +33,2 @@ "keywords": [ | ||
"dependencies": { | ||
"@types/big.js": "^4.0.5", | ||
"big.js": "^5.2.2", | ||
@@ -43,2 +42,3 @@ "rxjs": "^6.4.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@types/big.js": "^4.0.5", | ||
"@types/react": "^16.8.0", | ||
@@ -45,0 +45,0 @@ "@types/react-dom": "^16.8.0", |
@@ -82,3 +82,28 @@ import { useCallback, useMemo, useRef } from 'react'; | ||
/** | ||
* This triggers a validation | ||
* 生成一个默认的`onChange`回调,这个回调会触发`model.validate` | ||
* 如果不需要在onChange的时候触发校验,如下即可: | ||
* ```js | ||
* const onChange = useCallback(value => model.value = value, [model]); | ||
* ``` | ||
* 例如是一个`input`: | ||
* ```ts | ||
* const onChange = useCallback((value: React.ChangeEvent<HTMLInputElement>) => { | ||
* model.value = e.target.value; | ||
* }, [model]); | ||
* ``` | ||
* 可以配合usePipe使用: | ||
* ```js | ||
* function mapEventToValue(e) { | ||
* return e.target.value; | ||
* } | ||
* | ||
* function Foo() { | ||
* const onChange = FieldUtils.usePipe( | ||
* mapEventToValue, | ||
* FieldUtils.makeChangeHandler(model), | ||
* ); | ||
* } | ||
* | ||
* | ||
* ``` | ||
*/ | ||
@@ -85,0 +110,0 @@ export function makeChangeHandler<Value>(model: FieldModel<Value>, option: ValidateOption) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
206927
9
3845
0
21
- Removed@types/big.js@^4.0.5
- Removed@types/big.js@4.0.5(transitive)