@pisell/utils 1.0.71 → 1.0.73

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.
Files changed (202) hide show
  1. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  2. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  3. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  4. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  5. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  6. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
  7. package/es/arrayUtils.d.ts +4 -1
  8. package/es/arrayUtils.js +15 -24
  9. package/es/common/stateHelper.d.ts +6 -2
  10. package/es/common/stateHelper.js +22 -24
  11. package/es/common/types.d.ts +13 -10
  12. package/es/componentStorage.d.ts +27 -25
  13. package/es/componentStorage.js +94 -130
  14. package/es/constants/index.js +7 -9
  15. package/es/date.d.ts +6 -3
  16. package/es/date.js +36 -53
  17. package/es/document.d.ts +6 -3
  18. package/es/document.js +43 -67
  19. package/es/escPosPrinter/EscPosPrinter.js +353 -490
  20. package/es/escPosPrinter/index.d.ts +9 -9
  21. package/es/escPosPrinter/index.js +37 -52
  22. package/es/format.d.ts +12 -11
  23. package/es/format.js +90 -116
  24. package/es/image.d.ts +13 -10
  25. package/es/image.js +48 -60
  26. package/es/index.d.ts +38 -23
  27. package/es/index.js +39 -34
  28. package/es/jsBridge/index.d.ts +8 -4
  29. package/es/jsBridge/index.js +57 -56
  30. package/es/jsBridge/regDeviceApi.js +107 -149
  31. package/es/jsBridge/types.d.ts +95 -115
  32. package/es/locales.d.ts +11 -8
  33. package/es/locales.js +77 -96
  34. package/es/log.d.ts +11 -6
  35. package/es/log.js +37 -59
  36. package/es/miniRedux.d.ts +20 -13
  37. package/es/miniRedux.js +42 -78
  38. package/es/number-input/hooks/useNumberInputState.d.ts +6 -2
  39. package/es/number-input/hooks/useNumberInputState.js +71 -128
  40. package/es/number-input/types.d.ts +88 -88
  41. package/es/number-input/utils/formatter.d.ts +13 -10
  42. package/es/number-input/utils/formatter.js +51 -77
  43. package/es/number-input/utils/validation.d.ts +7 -2
  44. package/es/number-input/utils/validation.js +51 -66
  45. package/es/otherUtils.d.ts +12 -9
  46. package/es/otherUtils.js +71 -129
  47. package/es/platform.d.ts +17 -9
  48. package/es/platform.js +78 -85
  49. package/es/select/hooks/useDebouncedSearch.d.ts +4 -1
  50. package/es/select/hooks/useDebouncedSearch.js +39 -53
  51. package/es/select/hooks/useSelectState.d.ts +7 -7
  52. package/es/select/hooks/useSelectState.js +56 -113
  53. package/es/select/index.d.ts +7 -8
  54. package/es/select/types.d.ts +211 -211
  55. package/es/select/utils/filterOptions.d.ts +7 -6
  56. package/es/select/utils/filterOptions.js +26 -31
  57. package/es/select/utils/helpers.d.ts +10 -9
  58. package/es/select/utils/helpers.js +42 -52
  59. package/es/select/utils/index.d.ts +4 -7
  60. package/es/select/utils/sortOptions.d.ts +6 -5
  61. package/es/select/utils/sortOptions.js +19 -31
  62. package/es/select/utils/tagAggregation.d.ts +6 -6
  63. package/es/select/utils/tagAggregation.js +34 -47
  64. package/es/text-input/hooks/useTextInputState.d.ts +6 -2
  65. package/es/text-input/hooks/useTextInputState.js +69 -126
  66. package/es/text-input/types.d.ts +48 -48
  67. package/es/text-input/utils/validation.d.ts +7 -2
  68. package/es/text-input/utils/validation.js +50 -70
  69. package/es/typeUtils.d.ts +11 -8
  70. package/es/typeUtils.js +61 -84
  71. package/es/walletValidity.d.ts +36 -34
  72. package/es/walletValidity.js +332 -456
  73. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  74. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  75. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  76. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  77. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  78. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
  79. package/lib/_virtual/_rolldown/runtime.js +23 -0
  80. package/lib/arrayUtils.d.ts +4 -1
  81. package/lib/arrayUtils.js +14 -39
  82. package/lib/common/stateHelper.d.ts +6 -2
  83. package/lib/common/stateHelper.js +21 -32
  84. package/lib/common/types.d.ts +13 -10
  85. package/lib/componentStorage.d.ts +27 -25
  86. package/lib/componentStorage.js +96 -126
  87. package/lib/constants/index.js +7 -36
  88. package/lib/date.d.ts +6 -3
  89. package/lib/date.js +43 -65
  90. package/lib/document.d.ts +6 -3
  91. package/lib/document.js +46 -62
  92. package/lib/escPosPrinter/EscPosPrinter.js +327 -403
  93. package/lib/escPosPrinter/index.d.ts +9 -9
  94. package/lib/escPosPrinter/index.js +38 -84
  95. package/lib/format.d.ts +12 -11
  96. package/lib/format.js +91 -99
  97. package/lib/image.d.ts +13 -10
  98. package/lib/image.js +48 -74
  99. package/lib/index.d.ts +38 -23
  100. package/lib/index.js +115 -78
  101. package/lib/jsBridge/index.d.ts +8 -4
  102. package/lib/jsBridge/index.js +58 -77
  103. package/lib/jsBridge/regDeviceApi.js +106 -153
  104. package/lib/jsBridge/types.d.ts +95 -115
  105. package/lib/locales.d.ts +11 -8
  106. package/lib/locales.js +79 -90
  107. package/lib/log.d.ts +11 -6
  108. package/lib/log.js +37 -61
  109. package/lib/miniRedux.d.ts +20 -13
  110. package/lib/miniRedux.js +43 -92
  111. package/lib/number-input/hooks/useNumberInputState.d.ts +6 -2
  112. package/lib/number-input/hooks/useNumberInputState.js +71 -81
  113. package/lib/number-input/types.d.ts +88 -88
  114. package/lib/number-input/utils/formatter.d.ts +13 -10
  115. package/lib/number-input/utils/formatter.js +52 -49
  116. package/lib/number-input/utils/validation.d.ts +7 -2
  117. package/lib/number-input/utils/validation.js +50 -52
  118. package/lib/otherUtils.d.ts +12 -9
  119. package/lib/otherUtils.js +86 -98
  120. package/lib/platform.d.ts +17 -9
  121. package/lib/platform.js +85 -122
  122. package/lib/select/hooks/useDebouncedSearch.d.ts +4 -1
  123. package/lib/select/hooks/useDebouncedSearch.js +40 -41
  124. package/lib/select/hooks/useSelectState.d.ts +7 -7
  125. package/lib/select/hooks/useSelectState.js +58 -93
  126. package/lib/select/index.d.ts +7 -8
  127. package/lib/select/types.d.ts +211 -211
  128. package/lib/select/utils/filterOptions.d.ts +7 -6
  129. package/lib/select/utils/filterOptions.js +26 -37
  130. package/lib/select/utils/helpers.d.ts +10 -9
  131. package/lib/select/utils/helpers.js +45 -41
  132. package/lib/select/utils/index.d.ts +4 -7
  133. package/lib/select/utils/sortOptions.d.ts +6 -5
  134. package/lib/select/utils/sortOptions.js +18 -39
  135. package/lib/select/utils/tagAggregation.d.ts +6 -6
  136. package/lib/select/utils/tagAggregation.js +33 -41
  137. package/lib/text-input/hooks/useTextInputState.d.ts +6 -2
  138. package/lib/text-input/hooks/useTextInputState.js +69 -79
  139. package/lib/text-input/types.d.ts +48 -48
  140. package/lib/text-input/utils/validation.d.ts +7 -2
  141. package/lib/text-input/utils/validation.js +49 -58
  142. package/lib/typeUtils.d.ts +11 -8
  143. package/lib/typeUtils.js +68 -73
  144. package/lib/walletValidity.d.ts +36 -34
  145. package/lib/walletValidity.js +345 -317
  146. package/package.json +1 -2
  147. package/es/common/index.d.ts +0 -5
  148. package/es/common/index.js +0 -5
  149. package/es/common/types.js +0 -1
  150. package/es/constants/index.d.ts +0 -7
  151. package/es/firebase/config/index.d.ts +0 -13
  152. package/es/firebase/config/index.js +0 -54
  153. package/es/firebase/index.d.ts +0 -28
  154. package/es/firebase/index.js +0 -232
  155. package/es/jsBridge/types.js +0 -1
  156. package/es/number-input/hooks/index.d.ts +0 -4
  157. package/es/number-input/hooks/index.js +0 -5
  158. package/es/number-input/index.d.ts +0 -14
  159. package/es/number-input/index.js +0 -21
  160. package/es/number-input/types.js +0 -1
  161. package/es/number-input/utils/index.d.ts +0 -7
  162. package/es/number-input/utils/index.js +0 -8
  163. package/es/select/hooks/index.d.ts +0 -5
  164. package/es/select/hooks/index.js +0 -6
  165. package/es/select/index.js +0 -13
  166. package/es/select/types.js +0 -1
  167. package/es/select/utils/index.js +0 -8
  168. package/es/text-input/hooks/index.d.ts +0 -4
  169. package/es/text-input/hooks/index.js +0 -5
  170. package/es/text-input/index.d.ts +0 -14
  171. package/es/text-input/index.js +0 -20
  172. package/es/text-input/types.js +0 -1
  173. package/es/text-input/utils/index.d.ts +0 -5
  174. package/es/text-input/utils/index.js +0 -7
  175. package/lib/common/index.d.ts +0 -5
  176. package/lib/common/index.js +0 -29
  177. package/lib/common/types.js +0 -17
  178. package/lib/constants/index.d.ts +0 -7
  179. package/lib/firebase/config/index.d.ts +0 -13
  180. package/lib/firebase/config/index.js +0 -79
  181. package/lib/firebase/index.d.ts +0 -28
  182. package/lib/firebase/index.js +0 -180
  183. package/lib/jsBridge/types.js +0 -17
  184. package/lib/number-input/hooks/index.d.ts +0 -4
  185. package/lib/number-input/hooks/index.js +0 -29
  186. package/lib/number-input/index.d.ts +0 -14
  187. package/lib/number-input/index.js +0 -41
  188. package/lib/number-input/types.js +0 -17
  189. package/lib/number-input/utils/index.d.ts +0 -7
  190. package/lib/number-input/utils/index.js +0 -39
  191. package/lib/select/hooks/index.d.ts +0 -5
  192. package/lib/select/hooks/index.js +0 -34
  193. package/lib/select/index.js +0 -53
  194. package/lib/select/types.js +0 -17
  195. package/lib/select/utils/index.js +0 -48
  196. package/lib/text-input/hooks/index.d.ts +0 -4
  197. package/lib/text-input/hooks/index.js +0 -29
  198. package/lib/text-input/index.d.ts +0 -14
  199. package/lib/text-input/index.js +0 -35
  200. package/lib/text-input/types.js +0 -17
  201. package/lib/text-input/utils/index.d.ts +0 -5
  202. package/lib/text-input/utils/index.js +0 -32
package/es/miniRedux.js CHANGED
@@ -1,78 +1,42 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- import React, { createContext, useCallback, useMemo, useReducer, forwardRef, useRef
14
- //@ts-ignore
15
- } from 'react';
16
- import { jsx as _jsx } from "react/jsx-runtime";
17
- export var miniRedux = function miniRedux(_ref2) {
18
- var _ref2$namespace = _ref2.namespace,
19
- namespace = _ref2$namespace === void 0 ? 'state' : _ref2$namespace,
20
- state = _ref2.state,
21
- _ref2$reducers = _ref2.reducers,
22
- reducers = _ref2$reducers === void 0 ? {} : _ref2$reducers,
23
- _ref2$effects = _ref2.effects,
24
- effects = _ref2$effects === void 0 ? {} : _ref2$effects;
25
- var Context = /*#__PURE__*/createContext({});
26
- var Provider = function Provider(ComponentUi) {
27
- var Components = /*#__PURE__*/forwardRef(function (props, ref) {
28
- var stateRef = useRef();
29
- var _useReducer = useReducer(function (state, _ref3) {
30
- var type = _ref3.type,
31
- payload = _ref3.payload;
32
- if (reducers[type]) {
33
- return reducers[type](state, payload) || state;
34
- } else {
35
- return state;
36
- }
37
- }, state),
38
- _useReducer2 = _slicedToArray(_useReducer, 2),
39
- providerState = _useReducer2[0],
40
- dispatch = _useReducer2[1];
41
- stateRef.current = providerState;
42
- var _dispatch = useCallback(function (_ref4) {
43
- var type = _ref4.type,
44
- payload = _ref4.payload;
45
- if (effects[type]) {
46
- effects[type].call(null, stateRef.current, payload, dispatch);
47
- } else if (reducers[type]) {
48
- dispatch({
49
- type: type,
50
- payload: payload
51
- });
52
- }
53
- }, []);
54
-
55
- // 缓存Context value,避免不必要的重新渲染
56
- var contextValue = useMemo(function () {
57
- return _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch);
58
- }, [providerState, _dispatch]);
59
- var _props = _objectSpread(_objectSpread({}, props), {}, _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch));
60
- var _ref = null;
61
- if (_props.forwardedRef) {
62
- _ref = _props.forwardedRef;
63
- delete _props.forwardedRef;
64
- }
65
- return /*#__PURE__*/_jsx(Context.Provider, {
66
- value: contextValue,
67
- children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
68
- ref: ref
69
- }))
70
- });
71
- });
72
- return Components;
73
- };
74
- return {
75
- Context: Context,
76
- Provider: Provider
77
- };
78
- };
1
+ import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ import React, { createContext, forwardRef, useCallback, useMemo, useReducer, useRef } from "react";
3
+ //#region src/miniRedux.tsx
4
+ const miniRedux = ({ namespace = "state", state, reducers = {}, effects = {} }) => {
5
+ const Context = createContext({});
6
+ const Provider = (ComponentUi) => {
7
+ return forwardRef((props, ref) => {
8
+ const stateRef = useRef();
9
+ const [providerState, dispatch] = useReducer((state, { type, payload }) => {
10
+ if (reducers[type]) return reducers[type](state, payload) || state;
11
+ else return state;
12
+ }, state);
13
+ stateRef.current = providerState;
14
+ const _dispatch = useCallback(({ type, payload }) => {
15
+ if (effects[type]) effects[type].call(null, stateRef.current, payload, dispatch);
16
+ else if (reducers[type]) dispatch({
17
+ type,
18
+ payload
19
+ });
20
+ }, []);
21
+ const contextValue = useMemo(() => ({
22
+ [namespace]: providerState,
23
+ dispatch: _dispatch
24
+ }), [providerState, _dispatch]);
25
+ let _props = _objectSpread2(_objectSpread2({}, props), {}, {
26
+ [namespace]: providerState,
27
+ dispatch: _dispatch
28
+ });
29
+ if (_props.forwardedRef) {
30
+ _props.forwardedRef;
31
+ delete _props.forwardedRef;
32
+ }
33
+ return /* @__PURE__ */ React.createElement(Context.Provider, { value: contextValue }, /* @__PURE__ */ React.createElement(ComponentUi, _objectSpread2(_objectSpread2({}, _props), {}, { ref })));
34
+ });
35
+ };
36
+ return {
37
+ Context,
38
+ Provider
39
+ };
40
+ };
41
+ //#endregion
42
+ export { miniRedux };
@@ -1,4 +1,6 @@
1
- import type { BaseNumberInputProps, NumberInputState } from '../types';
1
+ import { BaseNumberInputProps, NumberInputState } from "../types.js";
2
+
3
+ //#region src/number-input/hooks/useNumberInputState.d.ts
2
4
  /**
3
5
  * 数值输入状态管理 Hook
4
6
  *
@@ -22,4 +24,6 @@ import type { BaseNumberInputProps, NumberInputState } from '../types';
22
24
  * // 非受控模式
23
25
  * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
24
26
  */
25
- export declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
27
+ declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
28
+ //#endregion
29
+ export { useNumberInputState };
@@ -1,129 +1,72 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { useState, useCallback } from 'react';
8
- import { validateValue } from "../utils/validation";
1
+ import { validateValue } from "../utils/validation.js";
2
+ import { useCallback, useState } from "react";
3
+ //#region src/number-input/hooks/useNumberInputState.ts
9
4
  /**
10
- * 数值输入状态管理 Hook
11
- *
12
- * 管理组件的内部状态,包括:
13
- * - 值管理(受控/非受控模式)
14
- * - 校验状态管理
15
- * - 事件处理函数封装
16
- *
17
- * 支持受控和非受控两种模式:
18
- * - 受控模式:value 由外部传入,组件不维护内部状态
19
- * - 非受控模式:使用 defaultValue,组件维护内部状态
20
- *
21
- * @param props 组件 Props(包含校验配置)
22
- * @returns 数值输入状态对象
23
- *
24
- * @example
25
- * // 受控模式
26
- * const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
27
- *
28
- * @example
29
- * // 非受控模式
30
- * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
31
- */
32
- export function useNumberInputState(props) {
33
- var _props$defaultValue;
34
- // 判断是否为受控组件
35
- var isControlled = props.value !== undefined;
36
-
37
- // 内部状态(仅非受控模式使用)
38
- var _useState = useState((_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : null),
39
- _useState2 = _slicedToArray(_useState, 2),
40
- innerValue = _useState2[0],
41
- setInnerValue = _useState2[1];
42
- var _useState3 = useState(false),
43
- _useState4 = _slicedToArray(_useState3, 2),
44
- isTouched = _useState4[0],
45
- setIsTouched = _useState4[1];
46
- var _useState5 = useState(true),
47
- _useState6 = _slicedToArray(_useState5, 2),
48
- isValid = _useState6[0],
49
- setIsValid = _useState6[1];
50
- var _useState7 = useState([]),
51
- _useState8 = _slicedToArray(_useState7, 2),
52
- errors = _useState8[0],
53
- setErrors = _useState8[1];
54
-
55
- // 当前值(受控模式优先使用 props.value)
56
- var currentValue = isControlled ? props.value : innerValue;
57
-
58
- /**
59
- * 值变更处理函数
60
- *
61
- * 1. 更新内部状态(非受控模式)
62
- * 2. 根据 validateTrigger 决定是否立即校验
63
- * 3. 触发外部 onChange 回调
64
- */
65
- var handleChange = useCallback(function (newValue) {
66
- var _props$onChange;
67
- // 更新内部状态(非受控模式)
68
- if (!isControlled) {
69
- setInnerValue(newValue);
70
- }
71
-
72
- // 根据配置决定是否立即校验
73
- var shouldValidate = props.validateTrigger === 'onChange' || props.validateTrigger === 'both';
74
- if (shouldValidate) {
75
- var _props$onValidate;
76
- var validation = validateValue(newValue, props);
77
- setIsValid(validation.isValid);
78
- setErrors(validation.errors);
79
- (_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
80
- }
81
-
82
- // 触发外部回调
83
- (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
84
- }, [isControlled, props]);
85
-
86
- /**
87
- * 失焦处理函数
88
- *
89
- * 1. 标记为已触摸
90
- * 2. 执行失焦时的校验(根据 validateTrigger)
91
- * 3. 触发外部 onBlur 回调
92
- */
93
- var handleBlur = useCallback(function () {
94
- var _props$onBlur;
95
- setIsTouched(true);
96
-
97
- // 失焦时执行校验(如果 validateTrigger 不是 'onChange')
98
- var shouldValidate = props.validateTrigger !== 'onChange';
99
- if (shouldValidate) {
100
- var _props$onValidate2;
101
- var validation = validateValue(currentValue, props);
102
- setIsValid(validation.isValid);
103
- setErrors(validation.errors);
104
- (_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
105
- }
106
- (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue !== null && currentValue !== void 0 ? currentValue : null);
107
- }, [currentValue, props]);
108
-
109
- /**
110
- * 聚焦处理函数
111
- *
112
- * 1. 标记为已触摸
113
- * 2. 触发外部 onFocus 回调
114
- */
115
- var handleFocus = useCallback(function () {
116
- var _props$onFocus;
117
- setIsTouched(true);
118
- (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
119
- }, [props]);
120
- return {
121
- value: currentValue,
122
- isTouched: isTouched,
123
- isValid: isValid,
124
- errors: errors,
125
- handleChange: handleChange,
126
- handleBlur: handleBlur,
127
- handleFocus: handleFocus
128
- };
129
- }
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
+ function useNumberInputState(props) {
28
+ var _props$defaultValue;
29
+ const isControlled = props.value !== void 0;
30
+ const [innerValue, setInnerValue] = useState((_props$defaultValue = props.defaultValue) !== null && _props$defaultValue !== void 0 ? _props$defaultValue : null);
31
+ const [isTouched, setIsTouched] = useState(false);
32
+ const [isValid, setIsValid] = useState(true);
33
+ const [errors, setErrors] = useState([]);
34
+ const currentValue = isControlled ? props.value : innerValue;
35
+ return {
36
+ value: currentValue,
37
+ isTouched,
38
+ isValid,
39
+ errors,
40
+ handleChange: useCallback((newValue) => {
41
+ var _props$onChange;
42
+ if (!isControlled) setInnerValue(newValue);
43
+ if (props.validateTrigger === "onChange" || props.validateTrigger === "both") {
44
+ var _props$onValidate;
45
+ const validation = validateValue(newValue, props);
46
+ setIsValid(validation.isValid);
47
+ setErrors(validation.errors);
48
+ (_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
49
+ }
50
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
51
+ }, [isControlled, props]),
52
+ handleBlur: useCallback(() => {
53
+ var _props$onBlur;
54
+ setIsTouched(true);
55
+ if (props.validateTrigger !== "onChange") {
56
+ var _props$onValidate2;
57
+ const validation = validateValue(currentValue, props);
58
+ setIsValid(validation.isValid);
59
+ setErrors(validation.errors);
60
+ (_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
61
+ }
62
+ (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue !== null && currentValue !== void 0 ? currentValue : null);
63
+ }, [currentValue, props]),
64
+ handleFocus: useCallback(() => {
65
+ var _props$onFocus;
66
+ setIsTouched(true);
67
+ (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
68
+ }, [props])
69
+ };
70
+ }
71
+ //#endregion
72
+ export { useNumberInputState };
@@ -1,96 +1,96 @@
1
- /**
2
- * 数值输入组件公共类型定义
3
- * 供 PisellNumber、PisellCurrency、PisellPercent 等组件使用
4
- */
5
- export type { DisplayState, ValidationResult } from '../common';
1
+ import { DisplayState, ValidationResult } from "../common/types.js";
2
+
3
+ //#region src/number-input/types.d.ts
6
4
  /**
7
5
  * 数值输入状态 Hook 返回值
8
6
  */
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;
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;
38
36
  }
39
37
  /**
40
38
  * 基础数值输入 Props(供校验和状态管理使用)
41
39
  */
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;
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;
96
94
  }
95
+ //#endregion
96
+ export { BaseNumberInputProps, NumberInputState };
@@ -1,16 +1,17 @@
1
+ //#region src/number-input/utils/formatter.d.ts
1
2
  /**
2
3
  * 数值格式化工具函数
3
4
  */
4
5
  /**
5
6
  * 格式化选项
6
7
  */
7
- export interface NumberFormatOptions {
8
- /** 小数精度 */
9
- precision?: number;
10
- /** 是否使用千分位分隔符 */
11
- useGrouping?: boolean;
12
- /** 自定义格式化函数 */
13
- formatter?: (value: number | null) => string;
8
+ interface NumberFormatOptions {
9
+ /** 小数精度 */
10
+ precision?: number;
11
+ /** 是否使用千分位分隔符 */
12
+ useGrouping?: boolean;
13
+ /** 自定义格式化函数 */
14
+ formatter?: (value: number | null) => string;
14
15
  }
15
16
  /**
16
17
  * 格式化数值
@@ -27,7 +28,7 @@ export interface NumberFormatOptions {
27
28
  * formatNumber(1234, { precision: 0, useGrouping: true })
28
29
  * // 返回: "1,234"
29
30
  */
30
- export declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
31
+ declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
31
32
  /**
32
33
  * 添加千分位分隔符
33
34
  *
@@ -38,7 +39,7 @@ export declare function formatNumber(value: number | null | undefined, options?:
38
39
  * addThousandsSeparator(1234567)
39
40
  * // 返回: "1,234,567"
40
41
  */
41
- export declare function addThousandsSeparator(value: number): string;
42
+ declare function addThousandsSeparator(value: number): string;
42
43
  /**
43
44
  * 格式化精度
44
45
  *
@@ -50,4 +51,6 @@ export declare function addThousandsSeparator(value: number): string;
50
51
  * formatPrecision(1.2345, 2)
51
52
  * // 返回: 1.23
52
53
  */
53
- export declare function formatPrecision(value: number, precision: number): number;
54
+ declare function formatPrecision(value: number, precision: number): number;
55
+ //#endregion
56
+ export { NumberFormatOptions, addThousandsSeparator, formatNumber, formatPrecision };