@pisell/utils 3.0.5 → 3.0.6
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/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
- package/es/arrayUtils.d.ts +76 -1
- package/es/arrayUtils.js +103 -24
- package/es/common/stateHelper.d.ts +22 -0
- package/es/common/stateHelper.js +23 -0
- package/es/common/types.d.ts +31 -0
- package/es/componentStorage.d.ts +38 -0
- package/es/componentStorage.js +106 -0
- package/es/constants/index.js +7 -9
- package/es/date.d.ts +6 -3
- package/es/date.js +36 -53
- package/es/document.d.ts +6 -3
- package/es/document.js +43 -67
- package/es/escPosPrinter/EscPosPrinter.js +353 -490
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +37 -52
- package/es/format.d.ts +12 -11
- package/es/format.js +90 -112
- package/es/image.d.ts +13 -10
- package/es/image.js +48 -60
- package/es/index.d.ts +39 -18
- package/es/index.js +40 -29
- package/es/jsBridge/index.d.ts +14 -106
- package/es/jsBridge/index.js +57 -40
- package/es/jsBridge/regDeviceApi.js +87 -126
- package/es/jsBridge/types.d.ts +129 -0
- package/es/locales.d.ts +11 -11
- package/es/locales.js +79 -69
- package/es/log.d.ts +11 -6
- package/es/log.js +37 -59
- package/es/miniRedux.d.ts +20 -13
- package/es/miniRedux.js +42 -71
- package/es/number-input/hooks/useNumberInputState.d.ts +29 -0
- package/es/number-input/hooks/useNumberInputState.js +72 -0
- package/es/number-input/types.d.ts +96 -0
- package/es/number-input/utils/formatter.d.ts +56 -0
- package/es/number-input/utils/formatter.js +56 -0
- package/es/number-input/utils/validation.d.ts +32 -0
- package/es/number-input/utils/validation.js +52 -0
- package/es/otherUtils.d.ts +51 -0
- package/es/otherUtils.js +71 -129
- package/es/platform.d.ts +12 -9
- package/es/platform.js +61 -85
- package/es/select/hooks/useDebouncedSearch.d.ts +23 -0
- package/es/select/hooks/useDebouncedSearch.js +41 -0
- package/es/select/hooks/useSelectState.d.ts +19 -0
- package/es/select/hooks/useSelectState.js +60 -0
- package/es/select/index.d.ts +7 -0
- package/es/select/types.d.ts +256 -0
- package/es/select/utils/filterOptions.d.ts +23 -0
- package/es/select/utils/filterOptions.js +29 -0
- package/es/select/utils/helpers.d.ts +43 -0
- package/es/select/utils/helpers.js +51 -0
- package/es/select/utils/index.d.ts +4 -0
- package/es/select/utils/sortOptions.d.ts +13 -0
- package/es/select/utils/sortOptions.js +20 -0
- package/es/select/utils/tagAggregation.d.ts +25 -0
- package/es/select/utils/tagAggregation.js +35 -0
- package/es/text-input/hooks/useTextInputState.d.ts +28 -0
- package/es/text-input/hooks/useTextInputState.js +70 -0
- package/es/text-input/types.d.ts +56 -0
- package/es/text-input/utils/validation.d.ts +28 -0
- package/es/text-input/utils/validation.js +51 -0
- package/es/typeUtils.d.ts +11 -8
- package/es/typeUtils.js +61 -84
- package/es/walletValidity.d.ts +57 -0
- package/es/walletValidity.js +404 -460
- package/es/weighing.d.ts +65 -0
- package/es/weighing.js +96 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
- package/lib/_virtual/_rolldown/runtime.js +23 -0
- package/lib/arrayUtils.d.ts +76 -1
- package/lib/arrayUtils.js +102 -37
- package/lib/common/stateHelper.d.ts +22 -0
- package/lib/common/stateHelper.js +23 -0
- package/lib/common/types.d.ts +31 -0
- package/lib/componentStorage.d.ts +38 -0
- package/lib/componentStorage.js +114 -0
- package/lib/constants/index.js +7 -36
- package/lib/date.d.ts +6 -3
- package/lib/date.js +43 -65
- package/lib/document.d.ts +6 -3
- package/lib/document.js +46 -62
- package/lib/escPosPrinter/EscPosPrinter.js +327 -403
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +38 -84
- package/lib/format.d.ts +12 -11
- package/lib/format.js +91 -93
- package/lib/image.d.ts +13 -10
- package/lib/image.js +48 -74
- package/lib/index.d.ts +39 -18
- package/lib/index.js +137 -68
- package/lib/jsBridge/index.d.ts +14 -106
- package/lib/jsBridge/index.js +60 -60
- package/lib/jsBridge/regDeviceApi.js +86 -133
- package/lib/jsBridge/types.d.ts +129 -0
- package/lib/locales.d.ts +11 -11
- package/lib/locales.js +79 -63
- package/lib/log.d.ts +11 -6
- package/lib/log.js +37 -61
- package/lib/miniRedux.d.ts +20 -13
- package/lib/miniRedux.js +43 -91
- package/lib/number-input/hooks/useNumberInputState.d.ts +29 -0
- package/lib/number-input/hooks/useNumberInputState.js +73 -0
- package/lib/number-input/types.d.ts +96 -0
- package/lib/number-input/utils/formatter.d.ts +56 -0
- package/lib/number-input/utils/formatter.js +58 -0
- package/lib/number-input/utils/validation.d.ts +32 -0
- package/lib/number-input/utils/validation.js +52 -0
- package/lib/otherUtils.d.ts +51 -0
- package/lib/otherUtils.js +86 -98
- package/lib/platform.d.ts +12 -9
- package/lib/platform.js +68 -123
- package/lib/select/hooks/useDebouncedSearch.d.ts +23 -0
- package/lib/select/hooks/useDebouncedSearch.js +42 -0
- package/lib/select/hooks/useSelectState.d.ts +19 -0
- package/lib/select/hooks/useSelectState.js +62 -0
- package/lib/select/index.d.ts +7 -0
- package/lib/select/types.d.ts +256 -0
- package/lib/select/utils/filterOptions.d.ts +23 -0
- package/lib/select/utils/filterOptions.js +30 -0
- package/lib/select/utils/helpers.d.ts +43 -0
- package/lib/select/utils/helpers.js +55 -0
- package/lib/select/utils/index.d.ts +4 -0
- package/lib/select/utils/sortOptions.d.ts +13 -0
- package/lib/select/utils/sortOptions.js +20 -0
- package/lib/select/utils/tagAggregation.d.ts +25 -0
- package/lib/select/utils/tagAggregation.js +35 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +28 -0
- package/lib/text-input/hooks/useTextInputState.js +71 -0
- package/lib/text-input/types.d.ts +56 -0
- package/lib/text-input/utils/validation.d.ts +28 -0
- package/lib/text-input/utils/validation.js +51 -0
- package/lib/typeUtils.d.ts +11 -8
- package/lib/typeUtils.js +68 -73
- package/lib/walletValidity.d.ts +57 -0
- package/lib/walletValidity.js +420 -323
- package/lib/weighing.d.ts +65 -0
- package/lib/weighing.js +114 -0
- package/package.json +1 -1
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/config/index.js +0 -54
- package/es/firebase/index.d.ts +0 -28
- package/es/firebase/index.js +0 -232
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/config/index.js +0 -79
- package/lib/firebase/index.d.ts +0 -28
- package/lib/firebase/index.js +0 -180
package/lib/miniRedux.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
//#region src/miniRedux.d.ts
|
|
1
2
|
interface MiniReduxProps<State, Namespace> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
namespace?: Namespace;
|
|
4
|
+
state?: State;
|
|
5
|
+
reducers?: any;
|
|
6
|
+
effects?: any;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({
|
|
9
|
+
namespace,
|
|
10
|
+
state,
|
|
11
|
+
reducers,
|
|
12
|
+
effects
|
|
13
|
+
}: MiniReduxProps<State, Namespace>) => {
|
|
14
|
+
Context: React.Context<{ [K in Namespace]: State } & {
|
|
15
|
+
dispatch: (params: {
|
|
16
|
+
type: string;
|
|
17
|
+
payload: any;
|
|
18
|
+
}) => void;
|
|
19
|
+
}>;
|
|
20
|
+
Provider: (ComponentUi: any) => any;
|
|
15
21
|
};
|
|
16
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
export { miniRedux };
|
package/lib/miniRedux.js
CHANGED
|
@@ -1,92 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_objectSpread2 = require("./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
react = require_runtime.__toESM(react);
|
|
5
|
+
//#region src/miniRedux.tsx
|
|
6
|
+
const miniRedux = ({ namespace = "state", state, reducers = {}, effects = {} }) => {
|
|
7
|
+
const Context = (0, react.createContext)({});
|
|
8
|
+
const Provider = (ComponentUi) => {
|
|
9
|
+
return (0, react.forwardRef)((props, ref) => {
|
|
10
|
+
const stateRef = (0, react.useRef)();
|
|
11
|
+
const [providerState, dispatch] = (0, react.useReducer)((state, { type, payload }) => {
|
|
12
|
+
if (reducers[type]) return reducers[type](state, payload) || state;
|
|
13
|
+
else return state;
|
|
14
|
+
}, state);
|
|
15
|
+
stateRef.current = providerState;
|
|
16
|
+
const _dispatch = (0, react.useCallback)(({ type, payload }) => {
|
|
17
|
+
if (effects[type]) effects[type].call(null, stateRef.current, payload, dispatch);
|
|
18
|
+
else if (reducers[type]) dispatch({
|
|
19
|
+
type,
|
|
20
|
+
payload
|
|
21
|
+
});
|
|
22
|
+
}, []);
|
|
23
|
+
const contextValue = (0, react.useMemo)(() => ({
|
|
24
|
+
[namespace]: providerState,
|
|
25
|
+
dispatch: _dispatch
|
|
26
|
+
}), [providerState, _dispatch]);
|
|
27
|
+
let _props = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
|
|
28
|
+
[namespace]: providerState,
|
|
29
|
+
dispatch: _dispatch
|
|
30
|
+
});
|
|
31
|
+
if (_props.forwardedRef) {
|
|
32
|
+
_props.forwardedRef;
|
|
33
|
+
delete _props.forwardedRef;
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ react.default.createElement(Context.Provider, { value: contextValue }, /* @__PURE__ */ react.default.createElement(ComponentUi, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, _props), {}, { ref })));
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
Context,
|
|
40
|
+
Provider
|
|
41
|
+
};
|
|
10
42
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/miniRedux.tsx
|
|
30
|
-
var miniRedux_exports = {};
|
|
31
|
-
__export(miniRedux_exports, {
|
|
32
|
-
miniRedux: () => miniRedux
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(miniRedux_exports);
|
|
35
|
-
var import_react = __toESM(require("react"));
|
|
36
|
-
var miniRedux = ({
|
|
37
|
-
namespace = "state",
|
|
38
|
-
state,
|
|
39
|
-
reducers = {},
|
|
40
|
-
effects = {}
|
|
41
|
-
}) => {
|
|
42
|
-
const Context = (0, import_react.createContext)({});
|
|
43
|
-
const Provider = (ComponentUi) => {
|
|
44
|
-
const Components = (0, import_react.forwardRef)((props, ref) => {
|
|
45
|
-
const stateRef = (0, import_react.useRef)();
|
|
46
|
-
const [providerState, dispatch] = (0, import_react.useReducer)(
|
|
47
|
-
(state2, { type, payload }) => {
|
|
48
|
-
if (reducers[type]) {
|
|
49
|
-
return reducers[type](state2, payload) || state2;
|
|
50
|
-
} else {
|
|
51
|
-
return state2;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
state
|
|
55
|
-
);
|
|
56
|
-
stateRef.current = providerState;
|
|
57
|
-
const _dispatch = (0, import_react.useCallback)(({ type, payload }) => {
|
|
58
|
-
if (effects[type]) {
|
|
59
|
-
effects[type].call(null, stateRef.current, payload, dispatch);
|
|
60
|
-
} else if (reducers[type]) {
|
|
61
|
-
dispatch({ type, payload });
|
|
62
|
-
}
|
|
63
|
-
}, []);
|
|
64
|
-
let _props = {
|
|
65
|
-
...props,
|
|
66
|
-
[namespace]: providerState,
|
|
67
|
-
dispatch: _dispatch
|
|
68
|
-
};
|
|
69
|
-
let _ref = null;
|
|
70
|
-
if (_props.forwardedRef) {
|
|
71
|
-
_ref = _props.forwardedRef;
|
|
72
|
-
delete _props.forwardedRef;
|
|
73
|
-
}
|
|
74
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
75
|
-
Context.Provider,
|
|
76
|
-
{
|
|
77
|
-
value: { [namespace]: providerState, dispatch: _dispatch }
|
|
78
|
-
},
|
|
79
|
-
/* @__PURE__ */ import_react.default.createElement(ComponentUi, { ..._props, ref })
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
return Components;
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
Context,
|
|
86
|
-
Provider
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
-
0 && (module.exports = {
|
|
91
|
-
miniRedux
|
|
92
|
-
});
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.miniRedux = miniRedux;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseNumberInputProps, NumberInputState } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/number-input/hooks/useNumberInputState.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 数值输入状态管理 Hook
|
|
6
|
+
*
|
|
7
|
+
* 管理组件的内部状态,包括:
|
|
8
|
+
* - 值管理(受控/非受控模式)
|
|
9
|
+
* - 校验状态管理
|
|
10
|
+
* - 事件处理函数封装
|
|
11
|
+
*
|
|
12
|
+
* 支持受控和非受控两种模式:
|
|
13
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
14
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
15
|
+
*
|
|
16
|
+
* @param props 组件 Props(包含校验配置)
|
|
17
|
+
* @returns 数值输入状态对象
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // 受控模式
|
|
21
|
+
* const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // 非受控模式
|
|
25
|
+
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
26
|
+
*/
|
|
27
|
+
declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useNumberInputState };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require("../../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_validation = require("../utils/validation.js");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
//#region src/number-input/hooks/useNumberInputState.ts
|
|
5
|
+
/**
|
|
6
|
+
* 数值输入状态管理 Hook
|
|
7
|
+
*
|
|
8
|
+
* 管理组件的内部状态,包括:
|
|
9
|
+
* - 值管理(受控/非受控模式)
|
|
10
|
+
* - 校验状态管理
|
|
11
|
+
* - 事件处理函数封装
|
|
12
|
+
*
|
|
13
|
+
* 支持受控和非受控两种模式:
|
|
14
|
+
* - 受控模式:value 由外部传入,组件不维护内部状态
|
|
15
|
+
* - 非受控模式:使用 defaultValue,组件维护内部状态
|
|
16
|
+
*
|
|
17
|
+
* @param props 组件 Props(包含校验配置)
|
|
18
|
+
* @returns 数值输入状态对象
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // 受控模式
|
|
22
|
+
* const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // 非受控模式
|
|
26
|
+
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
27
|
+
*/
|
|
28
|
+
function useNumberInputState(props) {
|
|
29
|
+
var _props$defaultValue;
|
|
30
|
+
const isControlled = props.value !== void 0;
|
|
31
|
+
const [innerValue, setInnerValue] = (0, react.useState)((_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : null);
|
|
32
|
+
const [isTouched, setIsTouched] = (0, react.useState)(false);
|
|
33
|
+
const [isValid, setIsValid] = (0, react.useState)(true);
|
|
34
|
+
const [errors, setErrors] = (0, react.useState)([]);
|
|
35
|
+
const currentValue = isControlled ? props.value : innerValue;
|
|
36
|
+
return {
|
|
37
|
+
value: currentValue,
|
|
38
|
+
isTouched,
|
|
39
|
+
isValid,
|
|
40
|
+
errors,
|
|
41
|
+
handleChange: (0, react.useCallback)((newValue) => {
|
|
42
|
+
var _props$onChange;
|
|
43
|
+
if (!isControlled) setInnerValue(newValue);
|
|
44
|
+
if (props.validateTrigger === "onChange" || props.validateTrigger === "both") {
|
|
45
|
+
var _props$onValidate;
|
|
46
|
+
const validation = require_validation.validateValue(newValue, props);
|
|
47
|
+
setIsValid(validation.isValid);
|
|
48
|
+
setErrors(validation.errors);
|
|
49
|
+
(_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
|
|
50
|
+
}
|
|
51
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
|
|
52
|
+
}, [isControlled, props]),
|
|
53
|
+
handleBlur: (0, react.useCallback)(() => {
|
|
54
|
+
var _props$onBlur;
|
|
55
|
+
setIsTouched(true);
|
|
56
|
+
if (props.validateTrigger !== "onChange") {
|
|
57
|
+
var _props$onValidate2;
|
|
58
|
+
const validation = require_validation.validateValue(currentValue, props);
|
|
59
|
+
setIsValid(validation.isValid);
|
|
60
|
+
setErrors(validation.errors);
|
|
61
|
+
(_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
|
|
62
|
+
}
|
|
63
|
+
(_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue !== null && currentValue !== void 0 ? currentValue : null);
|
|
64
|
+
}, [currentValue, props]),
|
|
65
|
+
handleFocus: (0, react.useCallback)(() => {
|
|
66
|
+
var _props$onFocus;
|
|
67
|
+
setIsTouched(true);
|
|
68
|
+
(_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
|
|
69
|
+
}, [props])
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.useNumberInputState = useNumberInputState;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DisplayState, ValidationResult } from "../common/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/number-input/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 数值输入状态 Hook 返回值
|
|
6
|
+
*/
|
|
7
|
+
interface NumberInputState {
|
|
8
|
+
/**
|
|
9
|
+
* 当前值
|
|
10
|
+
*/
|
|
11
|
+
value: number | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* 是否已被触摸(交互过)
|
|
14
|
+
*/
|
|
15
|
+
isTouched: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 是否校验通过
|
|
18
|
+
*/
|
|
19
|
+
isValid: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 错误信息数组
|
|
22
|
+
*/
|
|
23
|
+
errors: string[];
|
|
24
|
+
/**
|
|
25
|
+
* 值变更处理函数
|
|
26
|
+
*/
|
|
27
|
+
handleChange: (value: number | null) => void;
|
|
28
|
+
/**
|
|
29
|
+
* 失焦处理函数
|
|
30
|
+
*/
|
|
31
|
+
handleBlur: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* 聚焦处理函数
|
|
34
|
+
*/
|
|
35
|
+
handleFocus: () => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 基础数值输入 Props(供校验和状态管理使用)
|
|
39
|
+
*/
|
|
40
|
+
interface BaseNumberInputProps {
|
|
41
|
+
/**
|
|
42
|
+
* 当前值(受控)
|
|
43
|
+
*/
|
|
44
|
+
value?: number | null;
|
|
45
|
+
/**
|
|
46
|
+
* 默认值(非受控)
|
|
47
|
+
*/
|
|
48
|
+
defaultValue?: number | null;
|
|
49
|
+
/**
|
|
50
|
+
* 是否必填
|
|
51
|
+
*/
|
|
52
|
+
required?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 最小值
|
|
55
|
+
*/
|
|
56
|
+
min?: number;
|
|
57
|
+
/**
|
|
58
|
+
* 最大值
|
|
59
|
+
*/
|
|
60
|
+
max?: number;
|
|
61
|
+
/**
|
|
62
|
+
* 自定义校验函数
|
|
63
|
+
* @param value 当前值
|
|
64
|
+
* @returns true 表示通过,false 或错误信息字符串表示不通过
|
|
65
|
+
*/
|
|
66
|
+
validator?: (value: number | null) => boolean | string;
|
|
67
|
+
/**
|
|
68
|
+
* 校验触发时机
|
|
69
|
+
* - onChange: 输入时即时校验
|
|
70
|
+
* - onBlur: 失焦时校验
|
|
71
|
+
* - both: 输入和失焦时都校验
|
|
72
|
+
*/
|
|
73
|
+
validateTrigger?: 'onChange' | 'onBlur' | 'both';
|
|
74
|
+
/**
|
|
75
|
+
* 自定义错误提示信息
|
|
76
|
+
*/
|
|
77
|
+
errorMessage?: string;
|
|
78
|
+
/**
|
|
79
|
+
* 值变更回调
|
|
80
|
+
*/
|
|
81
|
+
onChange?: (value: number | null) => void;
|
|
82
|
+
/**
|
|
83
|
+
* 失焦回调
|
|
84
|
+
*/
|
|
85
|
+
onBlur?: (value: number | null) => void;
|
|
86
|
+
/**
|
|
87
|
+
* 聚焦回调
|
|
88
|
+
*/
|
|
89
|
+
onFocus?: () => void;
|
|
90
|
+
/**
|
|
91
|
+
* 校验回调
|
|
92
|
+
*/
|
|
93
|
+
onValidate?: (isValid: boolean, errors: string[]) => void;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { BaseNumberInputProps, NumberInputState };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/number-input/utils/formatter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 数值格式化工具函数
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 格式化选项
|
|
7
|
+
*/
|
|
8
|
+
interface NumberFormatOptions {
|
|
9
|
+
/** 小数精度 */
|
|
10
|
+
precision?: number;
|
|
11
|
+
/** 是否使用千分位分隔符 */
|
|
12
|
+
useGrouping?: boolean;
|
|
13
|
+
/** 自定义格式化函数 */
|
|
14
|
+
formatter?: (value: number | null) => string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 格式化数值
|
|
18
|
+
*
|
|
19
|
+
* @param value 数值
|
|
20
|
+
* @param options 格式化选项
|
|
21
|
+
* @returns 格式化后的字符串,null 时返回 null
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* formatNumber(1234.567, { precision: 2, useGrouping: true })
|
|
25
|
+
* // 返回: "1,234.57"
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* formatNumber(1234, { precision: 0, useGrouping: true })
|
|
29
|
+
* // 返回: "1,234"
|
|
30
|
+
*/
|
|
31
|
+
declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* 添加千分位分隔符
|
|
34
|
+
*
|
|
35
|
+
* @param value 数值
|
|
36
|
+
* @returns 添加千分位后的字符串
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* addThousandsSeparator(1234567)
|
|
40
|
+
* // 返回: "1,234,567"
|
|
41
|
+
*/
|
|
42
|
+
declare function addThousandsSeparator(value: number): string;
|
|
43
|
+
/**
|
|
44
|
+
* 格式化精度
|
|
45
|
+
*
|
|
46
|
+
* @param value 数值
|
|
47
|
+
* @param precision 小数位数
|
|
48
|
+
* @returns 格式化后的数值
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* formatPrecision(1.2345, 2)
|
|
52
|
+
* // 返回: 1.23
|
|
53
|
+
*/
|
|
54
|
+
declare function formatPrecision(value: number, precision: number): number;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { NumberFormatOptions, addThousandsSeparator, formatNumber, formatPrecision };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/number-input/utils/formatter.ts
|
|
2
|
+
/**
|
|
3
|
+
* 格式化数值
|
|
4
|
+
*
|
|
5
|
+
* @param value 数值
|
|
6
|
+
* @param options 格式化选项
|
|
7
|
+
* @returns 格式化后的字符串,null 时返回 null
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* formatNumber(1234.567, { precision: 2, useGrouping: true })
|
|
11
|
+
* // 返回: "1,234.57"
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* formatNumber(1234, { precision: 0, useGrouping: true })
|
|
15
|
+
* // 返回: "1,234"
|
|
16
|
+
*/
|
|
17
|
+
function formatNumber(value, options = {}) {
|
|
18
|
+
if (value === null || value === void 0) return null;
|
|
19
|
+
const { precision, useGrouping = false, formatter } = options;
|
|
20
|
+
if (formatter) return formatter(value);
|
|
21
|
+
if (useGrouping || precision !== void 0) return value.toLocaleString("zh-CN", {
|
|
22
|
+
minimumFractionDigits: precision,
|
|
23
|
+
maximumFractionDigits: precision,
|
|
24
|
+
useGrouping
|
|
25
|
+
});
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 添加千分位分隔符
|
|
30
|
+
*
|
|
31
|
+
* @param value 数值
|
|
32
|
+
* @returns 添加千分位后的字符串
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* addThousandsSeparator(1234567)
|
|
36
|
+
* // 返回: "1,234,567"
|
|
37
|
+
*/
|
|
38
|
+
function addThousandsSeparator(value) {
|
|
39
|
+
return value.toLocaleString("zh-CN", { useGrouping: true });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 格式化精度
|
|
43
|
+
*
|
|
44
|
+
* @param value 数值
|
|
45
|
+
* @param precision 小数位数
|
|
46
|
+
* @returns 格式化后的数值
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* formatPrecision(1.2345, 2)
|
|
50
|
+
* // 返回: 1.23
|
|
51
|
+
*/
|
|
52
|
+
function formatPrecision(value, precision) {
|
|
53
|
+
return Number(value.toFixed(precision));
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.addThousandsSeparator = addThousandsSeparator;
|
|
57
|
+
exports.formatNumber = formatNumber;
|
|
58
|
+
exports.formatPrecision = formatPrecision;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ValidationResult } from "../../common/types.js";
|
|
2
|
+
import { BaseNumberInputProps } from "../types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/number-input/utils/validation.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* 校验数值输入
|
|
7
|
+
*
|
|
8
|
+
* 按照优先级执行校验规则:
|
|
9
|
+
* 1. 必填校验(required)
|
|
10
|
+
* 2. 最小值校验(min)
|
|
11
|
+
* 3. 最大值校验(max)
|
|
12
|
+
* 4. 自定义校验函数(validator)
|
|
13
|
+
*
|
|
14
|
+
* @param value 待校验的值
|
|
15
|
+
* @param props 校验配置
|
|
16
|
+
* @returns 校验结果对象,包含 isValid 和 errors
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* validateValue(10, { required: true, min: 0, max: 100 })
|
|
20
|
+
* // { isValid: true, errors: [] }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* validateValue(null, { required: true })
|
|
24
|
+
* // { isValid: false, errors: ['此字段为必填项'] }
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* validateValue(150, { min: 0, max: 100 })
|
|
28
|
+
* // { isValid: false, errors: ['不能大于 100'] }
|
|
29
|
+
*/
|
|
30
|
+
declare function validateValue(value: number | null | undefined, props: BaseNumberInputProps): ValidationResult;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { validateValue };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/number-input/utils/validation.ts
|
|
2
|
+
/**
|
|
3
|
+
* 校验数值输入
|
|
4
|
+
*
|
|
5
|
+
* 按照优先级执行校验规则:
|
|
6
|
+
* 1. 必填校验(required)
|
|
7
|
+
* 2. 最小值校验(min)
|
|
8
|
+
* 3. 最大值校验(max)
|
|
9
|
+
* 4. 自定义校验函数(validator)
|
|
10
|
+
*
|
|
11
|
+
* @param value 待校验的值
|
|
12
|
+
* @param props 校验配置
|
|
13
|
+
* @returns 校验结果对象,包含 isValid 和 errors
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* validateValue(10, { required: true, min: 0, max: 100 })
|
|
17
|
+
* // { isValid: true, errors: [] }
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* validateValue(null, { required: true })
|
|
21
|
+
* // { isValid: false, errors: ['此字段为必填项'] }
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* validateValue(150, { min: 0, max: 100 })
|
|
25
|
+
* // { isValid: false, errors: ['不能大于 100'] }
|
|
26
|
+
*/
|
|
27
|
+
function validateValue(value, props) {
|
|
28
|
+
const errors = [];
|
|
29
|
+
if (props.required && (value === null || value === void 0)) {
|
|
30
|
+
errors.push(props.errorMessage || "此字段为必填项");
|
|
31
|
+
return {
|
|
32
|
+
isValid: false,
|
|
33
|
+
errors
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (value === null || value === void 0) return {
|
|
37
|
+
isValid: true,
|
|
38
|
+
errors
|
|
39
|
+
};
|
|
40
|
+
if (props.min !== void 0 && value < props.min) errors.push(`不能小于 ${props.min}`);
|
|
41
|
+
if (props.max !== void 0 && value > props.max) errors.push(`不能大于 ${props.max}`);
|
|
42
|
+
if (props.validator) {
|
|
43
|
+
const result = props.validator(value);
|
|
44
|
+
if (result !== true) errors.push(typeof result === "string" ? result : "校验失败");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
isValid: errors.length === 0,
|
|
48
|
+
errors
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.validateValue = validateValue;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/otherUtils.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @title: 判断是否无痕模式
|
|
4
|
+
* @description:
|
|
5
|
+
* @return: *
|
|
6
|
+
* @Author: shengjie.zuo
|
|
7
|
+
* @Date: 2024-09-4 09:58:22
|
|
8
|
+
*/
|
|
9
|
+
declare const detectIncognito: () => Promise<{
|
|
10
|
+
isPrivate: boolean;
|
|
11
|
+
browserName: string;
|
|
12
|
+
} | {
|
|
13
|
+
isPrivate: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* @Description: 生成唯一id
|
|
17
|
+
* @Author: wzw
|
|
18
|
+
* @Date: 2020-12-01 14:20:29
|
|
19
|
+
* @param {*}
|
|
20
|
+
* @return {*}
|
|
21
|
+
*/
|
|
22
|
+
declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
|
|
23
|
+
/**
|
|
24
|
+
* @title: 对数组进行增|删
|
|
25
|
+
* @description: 用于多选选中和取消选中的处理
|
|
26
|
+
* @param {any} list
|
|
27
|
+
* @param {any} item
|
|
28
|
+
* @param {string} key
|
|
29
|
+
* @return {*}
|
|
30
|
+
* @Author: zhiwei.Wang
|
|
31
|
+
* @Date: 2023-12-19 16:44
|
|
32
|
+
*/
|
|
33
|
+
declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
|
|
34
|
+
/**
|
|
35
|
+
* @title: 判断某个字段是否在列表内
|
|
36
|
+
* @description:
|
|
37
|
+
* @param {*} T
|
|
38
|
+
* @param {boolean} param2
|
|
39
|
+
* @return {*}
|
|
40
|
+
* @Author: zhiwei.Wang
|
|
41
|
+
* @Date: 2023-12-19 16:54
|
|
42
|
+
*/
|
|
43
|
+
declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
|
|
44
|
+
declare const createArray: (length: number, returnItem: any) => unknown[];
|
|
45
|
+
/**
|
|
46
|
+
* 根据对象内容生成唯一id
|
|
47
|
+
* @param obj
|
|
48
|
+
*/
|
|
49
|
+
declare const generateUniqueIdByObj: (obj: Record<string, any>) => any;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { changeArray, createArray, detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId };
|