rxtutils 1.1.4-beta.3 → 1.1.4-beta.5
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/cjs/hooks/useCombineControlValue.cjs +18 -7
- package/cjs/hooks/useCombineControlValue.d.ts +11 -10
- package/cjs/validator/validator.cjs +2 -2
- package/es/hooks/useCombineControlValue.d.ts +11 -10
- package/es/hooks/useCombineControlValue.mjs +18 -7
- package/es/validator/validator.mjs +2 -2
- package/package.json +2 -2
|
@@ -5,19 +5,30 @@ var react = require('react');
|
|
|
5
5
|
/**
|
|
6
6
|
* @param param props 组件属性
|
|
7
7
|
* @param param valueKey 组件值的key,默认value, undefined 被认为是有值,只有当 key 不存在时,转换为非受控模式
|
|
8
|
-
* @param param defaultValue
|
|
8
|
+
* @param param defaultValue 默认值,当 value 和 defaultValue 同时存在时,以 value 为默认值
|
|
9
9
|
* @param param onChange 值改变时的回调
|
|
10
10
|
* @returns value: 组件应该采用的值,onChange:值改变时的回调,处理非受控值与向父组件传递值的逻辑
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
function useCombineControlValue(_a, resolveFn) {
|
|
13
13
|
var props = _a.props, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, defaultValue = _a.defaultValue, onChange = _a.onChange;
|
|
14
14
|
var _c = props, _d = valueKey, value = _c[_d];
|
|
15
15
|
var hasValue = Object.prototype.hasOwnProperty.call(props, valueKey);
|
|
16
16
|
var _e = react.useState(value !== null && value !== void 0 ? value : defaultValue), internalValue = _e[0], setInternalValue = _e[1];
|
|
17
|
-
var handleChange = react.useCallback(function (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
var handleChange = react.useCallback(function () {
|
|
18
|
+
var params = [];
|
|
19
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
20
|
+
params[_i] = arguments[_i];
|
|
21
|
+
}
|
|
22
|
+
var realNextVal;
|
|
23
|
+
if (typeof resolveFn === 'function') {
|
|
24
|
+
realNextVal = resolveFn.apply(void 0, params);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
realNextVal = params[0];
|
|
28
|
+
}
|
|
29
|
+
setInternalValue(realNextVal);
|
|
30
|
+
onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, params);
|
|
31
|
+
}, [onChange, resolveFn]);
|
|
21
32
|
var finalValue = react.useMemo(function () {
|
|
22
33
|
if (hasValue)
|
|
23
34
|
return value;
|
|
@@ -27,6 +38,6 @@ var useCombineControlValue = function (_a) {
|
|
|
27
38
|
value: finalValue,
|
|
28
39
|
onChange: handleChange
|
|
29
40
|
};
|
|
30
|
-
}
|
|
41
|
+
}
|
|
31
42
|
|
|
32
43
|
exports.useCombineControlValue = useCombineControlValue;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
* @param param props 组件属性
|
|
3
|
-
* @param param valueKey 组件值的key,默认value, undefined 被认为是有值,只有当 key 不存在时,转换为非受控模式
|
|
4
|
-
* @param param defaultValue 默认值
|
|
5
|
-
* @param param onChange 值改变时的回调
|
|
6
|
-
* @returns value: 组件应该采用的值,onChange:值改变时的回调,处理非受控值与向父组件传递值的逻辑
|
|
7
|
-
*/
|
|
8
|
-
declare const useCombineControlValue: <V>({ props, valueKey, defaultValue, onChange }: {
|
|
1
|
+
type UseCombineControlValueOptions<V> = {
|
|
9
2
|
props: Record<string, any>;
|
|
10
3
|
valueKey?: string;
|
|
11
4
|
defaultValue?: V;
|
|
12
5
|
onChange?: (val: V) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
6
|
+
};
|
|
7
|
+
type UseCombineControlValueEasyResult<V> = {
|
|
8
|
+
value: V;
|
|
15
9
|
onChange: (nextVal: V) => void;
|
|
16
10
|
};
|
|
11
|
+
type UseCombineControlValueResolveResult<V, R extends (...args: any[]) => any> = {
|
|
12
|
+
value: V;
|
|
13
|
+
onChange: (...args: Parameters<R>) => void;
|
|
14
|
+
};
|
|
15
|
+
declare function useCombineControlValue<V>(options: UseCombineControlValueOptions<V>): UseCombineControlValueEasyResult<V>;
|
|
16
|
+
declare function useCombineControlValue<V, R extends (...args: any[]) => any>(options: UseCombineControlValueOptions<V>, resolveFn: (...args: Parameters<R>) => V): UseCombineControlValueResolveResult<V, R>;
|
|
17
17
|
|
|
18
18
|
export { useCombineControlValue };
|
|
19
|
+
export type { UseCombineControlValueEasyResult, UseCombineControlValueOptions, UseCombineControlValueResolveResult };
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
|
|
5
|
+
var KEY_SYMBOL = Symbol("key-description");
|
|
5
6
|
/**
|
|
6
7
|
* 基础验证器类
|
|
7
8
|
* 提供字段验证功能,可通过装饰器为类属性添加验证规则
|
|
@@ -13,8 +14,7 @@ var BaseValidator = /** @class */ (function () {
|
|
|
13
14
|
*/
|
|
14
15
|
function BaseValidator() {
|
|
15
16
|
/** 用于存储验证器映射的私有符号 */
|
|
16
|
-
this.__keySymbol =
|
|
17
|
-
this.__keySymbol = Symbol("key-description");
|
|
17
|
+
this.__keySymbol = KEY_SYMBOL;
|
|
18
18
|
this[this.__keySymbol] = {};
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
* @param param props 组件属性
|
|
3
|
-
* @param param valueKey 组件值的key,默认value, undefined 被认为是有值,只有当 key 不存在时,转换为非受控模式
|
|
4
|
-
* @param param defaultValue 默认值
|
|
5
|
-
* @param param onChange 值改变时的回调
|
|
6
|
-
* @returns value: 组件应该采用的值,onChange:值改变时的回调,处理非受控值与向父组件传递值的逻辑
|
|
7
|
-
*/
|
|
8
|
-
declare const useCombineControlValue: <V>({ props, valueKey, defaultValue, onChange }: {
|
|
1
|
+
type UseCombineControlValueOptions<V> = {
|
|
9
2
|
props: Record<string, any>;
|
|
10
3
|
valueKey?: string;
|
|
11
4
|
defaultValue?: V;
|
|
12
5
|
onChange?: (val: V) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
6
|
+
};
|
|
7
|
+
type UseCombineControlValueEasyResult<V> = {
|
|
8
|
+
value: V;
|
|
15
9
|
onChange: (nextVal: V) => void;
|
|
16
10
|
};
|
|
11
|
+
type UseCombineControlValueResolveResult<V, R extends (...args: any[]) => any> = {
|
|
12
|
+
value: V;
|
|
13
|
+
onChange: (...args: Parameters<R>) => void;
|
|
14
|
+
};
|
|
15
|
+
declare function useCombineControlValue<V>(options: UseCombineControlValueOptions<V>): UseCombineControlValueEasyResult<V>;
|
|
16
|
+
declare function useCombineControlValue<V, R extends (...args: any[]) => any>(options: UseCombineControlValueOptions<V>, resolveFn: (...args: Parameters<R>) => V): UseCombineControlValueResolveResult<V, R>;
|
|
17
17
|
|
|
18
18
|
export { useCombineControlValue };
|
|
19
|
+
export type { UseCombineControlValueEasyResult, UseCombineControlValueOptions, UseCombineControlValueResolveResult };
|
|
@@ -3,19 +3,30 @@ import { useState, useCallback, useMemo } from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* @param param props 组件属性
|
|
5
5
|
* @param param valueKey 组件值的key,默认value, undefined 被认为是有值,只有当 key 不存在时,转换为非受控模式
|
|
6
|
-
* @param param defaultValue
|
|
6
|
+
* @param param defaultValue 默认值,当 value 和 defaultValue 同时存在时,以 value 为默认值
|
|
7
7
|
* @param param onChange 值改变时的回调
|
|
8
8
|
* @returns value: 组件应该采用的值,onChange:值改变时的回调,处理非受控值与向父组件传递值的逻辑
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
function useCombineControlValue(_a, resolveFn) {
|
|
11
11
|
var props = _a.props, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, defaultValue = _a.defaultValue, onChange = _a.onChange;
|
|
12
12
|
var _c = props, _d = valueKey, value = _c[_d];
|
|
13
13
|
var hasValue = Object.prototype.hasOwnProperty.call(props, valueKey);
|
|
14
14
|
var _e = useState(value !== null && value !== void 0 ? value : defaultValue), internalValue = _e[0], setInternalValue = _e[1];
|
|
15
|
-
var handleChange = useCallback(function (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
var handleChange = useCallback(function () {
|
|
16
|
+
var params = [];
|
|
17
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
+
params[_i] = arguments[_i];
|
|
19
|
+
}
|
|
20
|
+
var realNextVal;
|
|
21
|
+
if (typeof resolveFn === 'function') {
|
|
22
|
+
realNextVal = resolveFn.apply(void 0, params);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
realNextVal = params[0];
|
|
26
|
+
}
|
|
27
|
+
setInternalValue(realNextVal);
|
|
28
|
+
onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, params);
|
|
29
|
+
}, [onChange, resolveFn]);
|
|
19
30
|
var finalValue = useMemo(function () {
|
|
20
31
|
if (hasValue)
|
|
21
32
|
return value;
|
|
@@ -25,6 +36,6 @@ var useCombineControlValue = function (_a) {
|
|
|
25
36
|
value: finalValue,
|
|
26
37
|
onChange: handleChange
|
|
27
38
|
};
|
|
28
|
-
}
|
|
39
|
+
}
|
|
29
40
|
|
|
30
41
|
export { useCombineControlValue };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __spreadArray } from 'tslib';
|
|
2
2
|
|
|
3
|
+
var KEY_SYMBOL = Symbol("key-description");
|
|
3
4
|
/**
|
|
4
5
|
* 基础验证器类
|
|
5
6
|
* 提供字段验证功能,可通过装饰器为类属性添加验证规则
|
|
@@ -11,8 +12,7 @@ var BaseValidator = /** @class */ (function () {
|
|
|
11
12
|
*/
|
|
12
13
|
function BaseValidator() {
|
|
13
14
|
/** 用于存储验证器映射的私有符号 */
|
|
14
|
-
this.__keySymbol =
|
|
15
|
-
this.__keySymbol = Symbol("key-description");
|
|
15
|
+
this.__keySymbol = KEY_SYMBOL;
|
|
16
16
|
this[this.__keySymbol] = {};
|
|
17
17
|
}
|
|
18
18
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rxtutils",
|
|
3
|
-
"version": "1.1.4-beta.
|
|
3
|
+
"version": "1.1.4-beta.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "cjs/index.cjs",
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "pnpm clean && rollup -c",
|
|
14
14
|
"clean": "rm -rf es cjs",
|
|
15
15
|
"publishNpm": "npm publish --registry https://registry.npmjs.org",
|
|
16
|
-
"
|
|
16
|
+
"loginNpm": "npm login --registry https://registry.npmjs.org"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@rollup/plugin-typescript": "^12.1.2",
|