rxtutils 1.1.3 → 1.1.4-beta.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/cjs/hooks/index.cjs +7 -0
- package/cjs/hooks/index.d.ts +1 -0
- package/cjs/hooks/useCombineControlValue.cjs +32 -0
- package/cjs/hooks/useCombineControlValue.d.ts +18 -0
- package/cjs/index.cjs +2 -0
- package/cjs/index.d.ts +1 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.mjs +1 -0
- package/es/hooks/useCombineControlValue.d.ts +18 -0
- package/es/hooks/useCombineControlValue.mjs +30 -0
- package/es/index.d.ts +1 -0
- package/es/index.mjs +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCombineControlValue } from './useCombineControlValue.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param param props 组件属性
|
|
7
|
+
* @param param valueKey 组件值的key,默认value, undefined 被认为是有值,只有当 key 不存在时,转换为非受控模式
|
|
8
|
+
* @param param defaultValue 默认值
|
|
9
|
+
* @param param onChange 值改变时的回调
|
|
10
|
+
* @returns value: 组件应该采用的值,onChange:值改变时的回调,处理非受控值与向父组件传递值的逻辑
|
|
11
|
+
*/
|
|
12
|
+
var useCombineControlValue = function (_a) {
|
|
13
|
+
var props = _a.props, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, defaultValue = _a.defaultValue, onChange = _a.onChange;
|
|
14
|
+
var _c = props, _d = valueKey, value = _c[_d];
|
|
15
|
+
var hasValue = props.hasOwnProperty(valueKey);
|
|
16
|
+
var _e = react.useState(value !== null && value !== void 0 ? value : defaultValue), internalValue = _e[0], setInternalValue = _e[1];
|
|
17
|
+
var handleChange = react.useCallback(function (nextVal) {
|
|
18
|
+
setInternalValue(nextVal);
|
|
19
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(nextVal);
|
|
20
|
+
}, [onChange]);
|
|
21
|
+
var finalValue = react.useMemo(function () {
|
|
22
|
+
if (hasValue)
|
|
23
|
+
return value;
|
|
24
|
+
return internalValue;
|
|
25
|
+
}, [hasValue, internalValue, value]);
|
|
26
|
+
return {
|
|
27
|
+
value: finalValue,
|
|
28
|
+
onChange: handleChange
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useCombineControlValue = useCombineControlValue;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 }: {
|
|
9
|
+
props: Record<string, any>;
|
|
10
|
+
valueKey?: string;
|
|
11
|
+
defaultValue?: V;
|
|
12
|
+
onChange?: (val: V) => void;
|
|
13
|
+
}) => {
|
|
14
|
+
value: any;
|
|
15
|
+
onChange: (nextVal: V) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useCombineControlValue };
|
package/cjs/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var index$3 = require('./store/createGetter/index.cjs');
|
|
|
6
6
|
var index$2 = require('./store/createStateStore/index.cjs');
|
|
7
7
|
var validator = require('./validator/validator.cjs');
|
|
8
8
|
var decorators = require('./validator/decorators.cjs');
|
|
9
|
+
var useCombineControlValue = require('./hooks/useCombineControlValue.cjs');
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
@@ -26,3 +27,4 @@ exports.VNumber = decorators.VNumber;
|
|
|
26
27
|
exports.VPattern = decorators.VPattern;
|
|
27
28
|
exports.VRequired = decorators.VRequired;
|
|
28
29
|
exports.VString = decorators.VString;
|
|
30
|
+
exports.useCombineControlValue = useCombineControlValue.useCombineControlValue;
|
package/cjs/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { createStoreGetter, createStoreGetterMemo } from './store/createGetter/i
|
|
|
4
4
|
export { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter, default as createStateStore } from './store/createStateStore/index.js';
|
|
5
5
|
export { BaseValidator } from './validator/validator.js';
|
|
6
6
|
export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from './validator/decorators.js';
|
|
7
|
+
export { useCombineControlValue } from './hooks/useCombineControlValue.js';
|
|
7
8
|
export { default as RequestError, RequestErrorType } from './request/error.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCombineControlValue } from './useCombineControlValue.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCombineControlValue } from './useCombineControlValue.mjs';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 }: {
|
|
9
|
+
props: Record<string, any>;
|
|
10
|
+
valueKey?: string;
|
|
11
|
+
defaultValue?: V;
|
|
12
|
+
onChange?: (val: V) => void;
|
|
13
|
+
}) => {
|
|
14
|
+
value: any;
|
|
15
|
+
onChange: (nextVal: V) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useCombineControlValue };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, useCallback, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param param props 组件属性
|
|
5
|
+
* @param param valueKey 组件值的key,默认value, undefined 被认为是有值,只有当 key 不存在时,转换为非受控模式
|
|
6
|
+
* @param param defaultValue 默认值
|
|
7
|
+
* @param param onChange 值改变时的回调
|
|
8
|
+
* @returns value: 组件应该采用的值,onChange:值改变时的回调,处理非受控值与向父组件传递值的逻辑
|
|
9
|
+
*/
|
|
10
|
+
var useCombineControlValue = function (_a) {
|
|
11
|
+
var props = _a.props, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, defaultValue = _a.defaultValue, onChange = _a.onChange;
|
|
12
|
+
var _c = props, _d = valueKey, value = _c[_d];
|
|
13
|
+
var hasValue = props.hasOwnProperty(valueKey);
|
|
14
|
+
var _e = useState(value !== null && value !== void 0 ? value : defaultValue), internalValue = _e[0], setInternalValue = _e[1];
|
|
15
|
+
var handleChange = useCallback(function (nextVal) {
|
|
16
|
+
setInternalValue(nextVal);
|
|
17
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(nextVal);
|
|
18
|
+
}, [onChange]);
|
|
19
|
+
var finalValue = useMemo(function () {
|
|
20
|
+
if (hasValue)
|
|
21
|
+
return value;
|
|
22
|
+
return internalValue;
|
|
23
|
+
}, [hasValue, internalValue, value]);
|
|
24
|
+
return {
|
|
25
|
+
value: finalValue,
|
|
26
|
+
onChange: handleChange
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { useCombineControlValue };
|
package/es/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { createStoreGetter, createStoreGetterMemo } from './store/createGetter/i
|
|
|
4
4
|
export { IHookStateInitAction, IHookStateInitialSetter, IHookStateResolvable, IHookStateSetAction, IHookStateSetter, default as createStateStore } from './store/createStateStore/index.js';
|
|
5
5
|
export { BaseValidator } from './validator/validator.js';
|
|
6
6
|
export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from './validator/decorators.js';
|
|
7
|
+
export { useCombineControlValue } from './hooks/useCombineControlValue.js';
|
|
7
8
|
export { default as RequestError, RequestErrorType } from './request/error.js';
|
package/es/index.mjs
CHANGED
|
@@ -4,3 +4,4 @@ export { createStoreGetter, createStoreGetterMemo } from './store/createGetter/i
|
|
|
4
4
|
export { default as createStateStore } from './store/createStateStore/index.mjs';
|
|
5
5
|
export { BaseValidator } from './validator/validator.mjs';
|
|
6
6
|
export { VArray, VBoolean, VEmail, VMax, VMaxLength, VMin, VMinLength, VNumber, VPattern, VRequired, VString } from './validator/decorators.mjs';
|
|
7
|
+
export { useCombineControlValue } from './hooks/useCombineControlValue.mjs';
|