@pisell/utils 3.0.6 → 3.0.7
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/arrayUtils.d.ts +23 -26
- package/es/arrayUtils.js +157 -97
- package/es/common/index.d.ts +5 -0
- package/es/common/index.js +5 -0
- package/es/common/stateHelper.d.ts +2 -6
- package/es/common/stateHelper.js +24 -22
- package/es/common/types.d.ts +10 -13
- package/es/common/types.js +1 -0
- package/es/componentStorage.d.ts +25 -27
- package/es/componentStorage.js +130 -94
- package/es/constants/index.js +9 -7
- package/es/date.js +53 -36
- package/es/document.js +67 -43
- package/es/escPosPrinter/EscPosPrinter.js +490 -353
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +52 -37
- package/es/firebase/config/index.js +54 -0
- package/es/firebase/index.js +232 -0
- package/es/format.d.ts +15 -12
- package/es/format.js +156 -89
- package/es/image.js +60 -48
- package/es/index.d.ts +24 -39
- package/es/index.js +35 -40
- package/es/jsBridge/index.d.ts +4 -8
- package/es/jsBridge/index.js +55 -56
- package/es/jsBridge/regDeviceApi.js +126 -87
- package/es/jsBridge/types.d.ts +115 -95
- package/es/jsBridge/types.js +1 -0
- package/es/locales.d.ts +8 -11
- package/es/locales.js +96 -77
- package/es/log.d.ts +6 -11
- package/es/log.js +59 -37
- package/es/miniRedux.d.ts +13 -20
- package/es/miniRedux.js +76 -42
- package/es/number-input/hooks/index.d.ts +4 -0
- package/es/number-input/hooks/index.js +5 -0
- package/es/number-input/hooks/useNumberInputState.d.ts +2 -6
- package/es/number-input/hooks/useNumberInputState.js +128 -71
- package/es/number-input/index.d.ts +14 -0
- package/es/number-input/index.js +21 -0
- package/es/number-input/types.d.ts +88 -88
- package/es/number-input/types.js +1 -0
- package/es/number-input/utils/formatter.d.ts +10 -13
- package/es/number-input/utils/formatter.js +77 -51
- package/es/number-input/utils/index.d.ts +7 -0
- package/es/number-input/utils/index.js +8 -0
- package/es/number-input/utils/validation.d.ts +2 -7
- package/es/number-input/utils/validation.js +66 -51
- package/es/otherUtils.d.ts +9 -12
- package/es/otherUtils.js +129 -71
- package/es/platform.d.ts +9 -12
- package/es/platform.js +85 -61
- package/es/select/hooks/index.d.ts +5 -0
- package/es/select/hooks/index.js +6 -0
- package/es/select/hooks/useDebouncedSearch.d.ts +1 -4
- package/es/select/hooks/useDebouncedSearch.js +53 -39
- package/es/select/hooks/useSelectState.d.ts +7 -7
- package/es/select/hooks/useSelectState.js +113 -56
- package/es/select/index.d.ts +8 -7
- package/es/select/index.js +13 -0
- package/es/select/types.d.ts +211 -211
- package/es/select/types.js +1 -0
- package/es/select/utils/filterOptions.d.ts +6 -7
- package/es/select/utils/filterOptions.js +31 -26
- package/es/select/utils/helpers.d.ts +9 -10
- package/es/select/utils/helpers.js +52 -42
- package/es/select/utils/index.d.ts +7 -4
- package/es/select/utils/index.js +8 -0
- package/es/select/utils/sortOptions.d.ts +5 -6
- package/es/select/utils/sortOptions.js +31 -19
- package/es/select/utils/tagAggregation.d.ts +6 -6
- package/es/select/utils/tagAggregation.js +47 -34
- package/es/text-input/hooks/index.d.ts +4 -0
- package/es/text-input/hooks/index.js +5 -0
- package/es/text-input/hooks/useTextInputState.d.ts +2 -6
- package/es/text-input/hooks/useTextInputState.js +126 -69
- package/es/text-input/index.d.ts +14 -0
- package/es/text-input/index.js +20 -0
- package/es/text-input/types.d.ts +48 -48
- package/es/text-input/types.js +1 -0
- package/es/text-input/utils/index.d.ts +5 -0
- package/es/text-input/utils/index.js +7 -0
- package/es/text-input/utils/validation.d.ts +2 -7
- package/es/text-input/utils/validation.js +70 -50
- package/es/typeUtils.js +84 -61
- package/es/walletValidity.d.ts +42 -44
- package/es/walletValidity.js +557 -396
- package/es/weighing.d.ts +45 -48
- package/es/weighing.js +106 -83
- package/lib/arrayUtils.d.ts +23 -26
- package/lib/arrayUtils.js +111 -101
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +29 -0
- package/lib/common/stateHelper.d.ts +2 -6
- package/lib/common/stateHelper.js +32 -21
- package/lib/common/types.d.ts +10 -13
- package/lib/common/types.js +17 -0
- package/lib/componentStorage.d.ts +25 -27
- package/lib/componentStorage.js +126 -96
- package/lib/constants/index.js +36 -7
- package/lib/date.js +65 -43
- package/lib/document.js +62 -46
- package/lib/escPosPrinter/EscPosPrinter.js +403 -327
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +84 -38
- package/lib/firebase/config/index.js +79 -0
- package/lib/firebase/index.js +180 -0
- package/lib/format.d.ts +15 -12
- package/lib/format.js +133 -91
- package/lib/image.js +74 -48
- package/lib/index.d.ts +24 -39
- package/lib/index.js +80 -137
- package/lib/jsBridge/index.d.ts +4 -8
- package/lib/jsBridge/index.js +76 -57
- package/lib/jsBridge/regDeviceApi.js +133 -86
- package/lib/jsBridge/types.d.ts +115 -95
- package/lib/jsBridge/types.js +17 -0
- package/lib/locales.d.ts +8 -11
- package/lib/locales.js +90 -79
- package/lib/log.d.ts +6 -11
- package/lib/log.js +61 -37
- package/lib/miniRedux.d.ts +13 -20
- package/lib/miniRedux.js +89 -43
- package/lib/number-input/hooks/index.d.ts +4 -0
- package/lib/number-input/hooks/index.js +29 -0
- package/lib/number-input/hooks/useNumberInputState.d.ts +2 -6
- package/lib/number-input/hooks/useNumberInputState.js +81 -71
- package/lib/number-input/index.d.ts +14 -0
- package/lib/number-input/index.js +41 -0
- package/lib/number-input/types.d.ts +88 -88
- package/lib/number-input/types.js +17 -0
- package/lib/number-input/utils/formatter.d.ts +10 -13
- package/lib/number-input/utils/formatter.js +49 -52
- package/lib/number-input/utils/index.d.ts +7 -0
- package/lib/number-input/utils/index.js +39 -0
- package/lib/number-input/utils/validation.d.ts +2 -7
- package/lib/number-input/utils/validation.js +52 -50
- package/lib/otherUtils.d.ts +9 -12
- package/lib/otherUtils.js +98 -86
- package/lib/platform.d.ts +9 -12
- package/lib/platform.js +123 -68
- package/lib/select/hooks/index.d.ts +5 -0
- package/lib/select/hooks/index.js +34 -0
- package/lib/select/hooks/useDebouncedSearch.d.ts +1 -4
- package/lib/select/hooks/useDebouncedSearch.js +41 -40
- package/lib/select/hooks/useSelectState.d.ts +7 -7
- package/lib/select/hooks/useSelectState.js +93 -58
- package/lib/select/index.d.ts +8 -7
- package/lib/select/index.js +53 -0
- package/lib/select/types.d.ts +211 -211
- package/lib/select/types.js +17 -0
- package/lib/select/utils/filterOptions.d.ts +6 -7
- package/lib/select/utils/filterOptions.js +37 -26
- package/lib/select/utils/helpers.d.ts +9 -10
- package/lib/select/utils/helpers.js +41 -45
- package/lib/select/utils/index.d.ts +7 -4
- package/lib/select/utils/index.js +48 -0
- package/lib/select/utils/sortOptions.d.ts +5 -6
- package/lib/select/utils/sortOptions.js +39 -18
- package/lib/select/utils/tagAggregation.d.ts +6 -6
- package/lib/select/utils/tagAggregation.js +41 -33
- package/lib/text-input/hooks/index.d.ts +4 -0
- package/lib/text-input/hooks/index.js +29 -0
- package/lib/text-input/hooks/useTextInputState.d.ts +2 -6
- package/lib/text-input/hooks/useTextInputState.js +79 -69
- package/lib/text-input/index.d.ts +14 -0
- package/lib/text-input/index.js +35 -0
- package/lib/text-input/types.d.ts +48 -48
- package/lib/text-input/types.js +17 -0
- package/lib/text-input/utils/index.d.ts +5 -0
- package/lib/text-input/utils/index.js +32 -0
- package/lib/text-input/utils/validation.d.ts +2 -7
- package/lib/text-input/utils/validation.js +58 -49
- package/lib/typeUtils.js +73 -68
- package/lib/walletValidity.d.ts +42 -44
- package/lib/walletValidity.js +393 -410
- package/lib/weighing.d.ts +45 -48
- package/lib/weighing.js +149 -104
- package/package.json +1 -1
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -11
- package/es/date.d.ts +0 -31
- package/es/document.d.ts +0 -16
- package/es/image.d.ts +0 -14
- package/es/typeUtils.d.ts +0 -45
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -16
- package/lib/_virtual/_rolldown/runtime.js +0 -23
- package/lib/date.d.ts +0 -31
- package/lib/document.d.ts +0 -16
- package/lib/image.d.ts +0 -14
- package/lib/typeUtils.d.ts +0 -45
package/lib/miniRedux.js
CHANGED
|
@@ -1,44 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
};
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
42
10
|
};
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
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
|
+
const contextValue = (0, import_react.useMemo)(() => ({
|
|
65
|
+
[namespace]: providerState,
|
|
66
|
+
dispatch: _dispatch
|
|
67
|
+
}), [providerState, _dispatch]);
|
|
68
|
+
let _props = {
|
|
69
|
+
...props,
|
|
70
|
+
[namespace]: providerState,
|
|
71
|
+
dispatch: _dispatch
|
|
72
|
+
};
|
|
73
|
+
let _ref = null;
|
|
74
|
+
if (_props.forwardedRef) {
|
|
75
|
+
_ref = _props.forwardedRef;
|
|
76
|
+
delete _props.forwardedRef;
|
|
77
|
+
}
|
|
78
|
+
return /* @__PURE__ */ import_react.default.createElement(Context.Provider, { value: contextValue }, /* @__PURE__ */ import_react.default.createElement(ComponentUi, { ..._props, ref }));
|
|
79
|
+
});
|
|
80
|
+
return Components;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
Context,
|
|
84
|
+
Provider
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
miniRedux
|
|
90
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/number-input/hooks/index.ts
|
|
20
|
+
var hooks_exports = {};
|
|
21
|
+
__export(hooks_exports, {
|
|
22
|
+
useNumberInputState: () => import_useNumberInputState.useNumberInputState
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
25
|
+
var import_useNumberInputState = require("./useNumberInputState");
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
useNumberInputState
|
|
29
|
+
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { BaseNumberInputProps, NumberInputState } from
|
|
2
|
-
|
|
3
|
-
//#region src/number-input/hooks/useNumberInputState.d.ts
|
|
1
|
+
import type { BaseNumberInputProps, NumberInputState } from '../types';
|
|
4
2
|
/**
|
|
5
3
|
* 数值输入状态管理 Hook
|
|
6
4
|
*
|
|
@@ -24,6 +22,4 @@ import { BaseNumberInputProps, NumberInputState } from "../types.js";
|
|
|
24
22
|
* // 非受控模式
|
|
25
23
|
* const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
|
|
26
24
|
*/
|
|
27
|
-
declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { useNumberInputState };
|
|
25
|
+
export declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
|
|
@@ -1,73 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/number-input/hooks/useNumberInputState.ts
|
|
20
|
+
var useNumberInputState_exports = {};
|
|
21
|
+
__export(useNumberInputState_exports, {
|
|
22
|
+
useNumberInputState: () => useNumberInputState
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useNumberInputState_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_validation = require("../utils/validation");
|
|
28
27
|
function useNumberInputState(props) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
28
|
+
const isControlled = props.value !== void 0;
|
|
29
|
+
const [innerValue, setInnerValue] = (0, import_react.useState)(
|
|
30
|
+
props.defaultValue ?? null
|
|
31
|
+
);
|
|
32
|
+
const [isTouched, setIsTouched] = (0, import_react.useState)(false);
|
|
33
|
+
const [isValid, setIsValid] = (0, import_react.useState)(true);
|
|
34
|
+
const [errors, setErrors] = (0, import_react.useState)([]);
|
|
35
|
+
const currentValue = isControlled ? props.value : innerValue;
|
|
36
|
+
const handleChange = (0, import_react.useCallback)(
|
|
37
|
+
(newValue) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (!isControlled) {
|
|
40
|
+
setInnerValue(newValue);
|
|
41
|
+
}
|
|
42
|
+
const shouldValidate = props.validateTrigger === "onChange" || props.validateTrigger === "both";
|
|
43
|
+
if (shouldValidate) {
|
|
44
|
+
const validation = (0, import_validation.validateValue)(newValue, props);
|
|
45
|
+
setIsValid(validation.isValid);
|
|
46
|
+
setErrors(validation.errors);
|
|
47
|
+
(_a = props.onValidate) == null ? void 0 : _a.call(props, validation.isValid, validation.errors);
|
|
48
|
+
}
|
|
49
|
+
(_b = props.onChange) == null ? void 0 : _b.call(props, newValue);
|
|
50
|
+
},
|
|
51
|
+
[isControlled, props]
|
|
52
|
+
);
|
|
53
|
+
const handleBlur = (0, import_react.useCallback)(() => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
setIsTouched(true);
|
|
56
|
+
const shouldValidate = props.validateTrigger !== "onChange";
|
|
57
|
+
if (shouldValidate) {
|
|
58
|
+
const validation = (0, import_validation.validateValue)(currentValue, props);
|
|
59
|
+
setIsValid(validation.isValid);
|
|
60
|
+
setErrors(validation.errors);
|
|
61
|
+
(_a = props.onValidate) == null ? void 0 : _a.call(props, validation.isValid, validation.errors);
|
|
62
|
+
}
|
|
63
|
+
(_b = props.onBlur) == null ? void 0 : _b.call(props, currentValue ?? null);
|
|
64
|
+
}, [currentValue, props]);
|
|
65
|
+
const handleFocus = (0, import_react.useCallback)(() => {
|
|
66
|
+
var _a;
|
|
67
|
+
setIsTouched(true);
|
|
68
|
+
(_a = props.onFocus) == null ? void 0 : _a.call(props);
|
|
69
|
+
}, [props]);
|
|
70
|
+
return {
|
|
71
|
+
value: currentValue,
|
|
72
|
+
isTouched,
|
|
73
|
+
isValid,
|
|
74
|
+
errors,
|
|
75
|
+
handleChange,
|
|
76
|
+
handleBlur,
|
|
77
|
+
handleFocus
|
|
78
|
+
};
|
|
71
79
|
}
|
|
72
|
-
|
|
73
|
-
exports
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
useNumberInputState
|
|
83
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数值输入组件公共逻辑导出
|
|
3
|
+
*
|
|
4
|
+
* 供以下组件使用:
|
|
5
|
+
* - PisellNumber
|
|
6
|
+
* - PisellCurrency
|
|
7
|
+
* - PisellPercent
|
|
8
|
+
* - 其他数值输入组件
|
|
9
|
+
*/
|
|
10
|
+
export type { DisplayState, ValidationResult, NumberInputState, BaseNumberInputProps, } from './types';
|
|
11
|
+
export { useNumberInputState } from './hooks';
|
|
12
|
+
export { getDisplayState, formatNumber, addThousandsSeparator, formatPrecision, } from './utils';
|
|
13
|
+
export { validateValue as validateNumberValue } from './utils';
|
|
14
|
+
export type { NumberFormatOptions } from './utils';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/number-input/index.ts
|
|
20
|
+
var number_input_exports = {};
|
|
21
|
+
__export(number_input_exports, {
|
|
22
|
+
addThousandsSeparator: () => import_utils.addThousandsSeparator,
|
|
23
|
+
formatNumber: () => import_utils.formatNumber,
|
|
24
|
+
formatPrecision: () => import_utils.formatPrecision,
|
|
25
|
+
getDisplayState: () => import_utils.getDisplayState,
|
|
26
|
+
useNumberInputState: () => import_hooks.useNumberInputState,
|
|
27
|
+
validateNumberValue: () => import_utils2.validateValue
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(number_input_exports);
|
|
30
|
+
var import_hooks = require("./hooks");
|
|
31
|
+
var import_utils = require("./utils");
|
|
32
|
+
var import_utils2 = require("./utils");
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
addThousandsSeparator,
|
|
36
|
+
formatNumber,
|
|
37
|
+
formatPrecision,
|
|
38
|
+
getDisplayState,
|
|
39
|
+
useNumberInputState,
|
|
40
|
+
validateNumberValue
|
|
41
|
+
});
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 数值输入组件公共类型定义
|
|
3
|
+
* 供 PisellNumber、PisellCurrency、PisellPercent 等组件使用
|
|
4
|
+
*/
|
|
5
|
+
export type { DisplayState, ValidationResult } from '../common';
|
|
4
6
|
/**
|
|
5
7
|
* 数值输入状态 Hook 返回值
|
|
6
8
|
*/
|
|
7
|
-
interface NumberInputState {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
export interface NumberInputState {
|
|
10
|
+
/**
|
|
11
|
+
* 当前值
|
|
12
|
+
*/
|
|
13
|
+
value: number | null | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 是否已被触摸(交互过)
|
|
16
|
+
*/
|
|
17
|
+
isTouched: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 是否校验通过
|
|
20
|
+
*/
|
|
21
|
+
isValid: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 错误信息数组
|
|
24
|
+
*/
|
|
25
|
+
errors: string[];
|
|
26
|
+
/**
|
|
27
|
+
* 值变更处理函数
|
|
28
|
+
*/
|
|
29
|
+
handleChange: (value: number | null) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 失焦处理函数
|
|
32
|
+
*/
|
|
33
|
+
handleBlur: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* 聚焦处理函数
|
|
36
|
+
*/
|
|
37
|
+
handleFocus: () => void;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* 基础数值输入 Props(供校验和状态管理使用)
|
|
39
41
|
*/
|
|
40
|
-
interface BaseNumberInputProps {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
42
|
+
export interface BaseNumberInputProps {
|
|
43
|
+
/**
|
|
44
|
+
* 当前值(受控)
|
|
45
|
+
*/
|
|
46
|
+
value?: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* 默认值(非受控)
|
|
49
|
+
*/
|
|
50
|
+
defaultValue?: number | null;
|
|
51
|
+
/**
|
|
52
|
+
* 是否必填
|
|
53
|
+
*/
|
|
54
|
+
required?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 最小值
|
|
57
|
+
*/
|
|
58
|
+
min?: number;
|
|
59
|
+
/**
|
|
60
|
+
* 最大值
|
|
61
|
+
*/
|
|
62
|
+
max?: number;
|
|
63
|
+
/**
|
|
64
|
+
* 自定义校验函数
|
|
65
|
+
* @param value 当前值
|
|
66
|
+
* @returns true 表示通过,false 或错误信息字符串表示不通过
|
|
67
|
+
*/
|
|
68
|
+
validator?: (value: number | null) => boolean | string;
|
|
69
|
+
/**
|
|
70
|
+
* 校验触发时机
|
|
71
|
+
* - onChange: 输入时即时校验
|
|
72
|
+
* - onBlur: 失焦时校验
|
|
73
|
+
* - both: 输入和失焦时都校验
|
|
74
|
+
*/
|
|
75
|
+
validateTrigger?: 'onChange' | 'onBlur' | 'both';
|
|
76
|
+
/**
|
|
77
|
+
* 自定义错误提示信息
|
|
78
|
+
*/
|
|
79
|
+
errorMessage?: string;
|
|
80
|
+
/**
|
|
81
|
+
* 值变更回调
|
|
82
|
+
*/
|
|
83
|
+
onChange?: (value: number | null) => void;
|
|
84
|
+
/**
|
|
85
|
+
* 失焦回调
|
|
86
|
+
*/
|
|
87
|
+
onBlur?: (value: number | null) => void;
|
|
88
|
+
/**
|
|
89
|
+
* 聚焦回调
|
|
90
|
+
*/
|
|
91
|
+
onFocus?: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* 校验回调
|
|
94
|
+
*/
|
|
95
|
+
onValidate?: (isValid: boolean, errors: string[]) => void;
|
|
94
96
|
}
|
|
95
|
-
//#endregion
|
|
96
|
-
export { BaseNumberInputProps, NumberInputState };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/number-input/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
//#region src/number-input/utils/formatter.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* 数值格式化工具函数
|
|
4
3
|
*/
|
|
5
4
|
/**
|
|
6
5
|
* 格式化选项
|
|
7
6
|
*/
|
|
8
|
-
interface NumberFormatOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export interface NumberFormatOptions {
|
|
8
|
+
/** 小数精度 */
|
|
9
|
+
precision?: number;
|
|
10
|
+
/** 是否使用千分位分隔符 */
|
|
11
|
+
useGrouping?: boolean;
|
|
12
|
+
/** 自定义格式化函数 */
|
|
13
|
+
formatter?: (value: number | null) => string;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* 格式化数值
|
|
@@ -28,7 +27,7 @@ interface NumberFormatOptions {
|
|
|
28
27
|
* formatNumber(1234, { precision: 0, useGrouping: true })
|
|
29
28
|
* // 返回: "1,234"
|
|
30
29
|
*/
|
|
31
|
-
declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
|
|
30
|
+
export declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
|
|
32
31
|
/**
|
|
33
32
|
* 添加千分位分隔符
|
|
34
33
|
*
|
|
@@ -39,7 +38,7 @@ declare function formatNumber(value: number | null | undefined, options?: Number
|
|
|
39
38
|
* addThousandsSeparator(1234567)
|
|
40
39
|
* // 返回: "1,234,567"
|
|
41
40
|
*/
|
|
42
|
-
declare function addThousandsSeparator(value: number): string;
|
|
41
|
+
export declare function addThousandsSeparator(value: number): string;
|
|
43
42
|
/**
|
|
44
43
|
* 格式化精度
|
|
45
44
|
*
|
|
@@ -51,6 +50,4 @@ declare function addThousandsSeparator(value: number): string;
|
|
|
51
50
|
* formatPrecision(1.2345, 2)
|
|
52
51
|
* // 返回: 1.23
|
|
53
52
|
*/
|
|
54
|
-
declare function formatPrecision(value: number, precision: number): number;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { NumberFormatOptions, addThousandsSeparator, formatNumber, formatPrecision };
|
|
53
|
+
export declare function formatPrecision(value: number, precision: number): number;
|