@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/platform.js CHANGED
@@ -1,93 +1,86 @@
1
- var isBrowser = typeof window != 'undefined' && window.document;
2
- export var isIpad = function isIpad() {
3
- var ua = navigator.userAgent;
4
- var isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
5
- var isIphone = ua.indexOf("iPhone") != -1 && ua.indexOf("Version") != -1;
6
- var isIPad = isSafari && !isIphone && "ontouchend" in document;
7
- if (!/iphone|ios|ipad|android|mobile/i.test(navigator.userAgent.toLowerCase()) && !isIPad) {
8
- return false;
9
- }
10
- return true;
1
+ //#region src/platform.ts
2
+ const isBrowser = typeof window != "undefined" && window.document;
3
+ /**
4
+ * osServer 列表/平面图订阅及其 unsubscribe 仅在 webpos 宿主可用
5
+ *(`appHelper.utils.pisellos` 存在)。低代码 admin、纯 H5 等环境不应发 unsubscribe。
6
+ */
7
+ const isWebposOsServerEnv = () => {
8
+ if (!isBrowser) return false;
9
+ try {
10
+ var _engineCtx$appHelper;
11
+ const w = window;
12
+ const ctx = w.__appContext;
13
+ const injected = w.__injectedContext;
14
+ const engineCtx = ctx != null && Object.keys(ctx).length > 0 ? ctx : injected;
15
+ return Boolean(engineCtx === null || engineCtx === void 0 || (_engineCtx$appHelper = engineCtx.appHelper) === null || _engineCtx$appHelper === void 0 || (_engineCtx$appHelper = _engineCtx$appHelper.utils) === null || _engineCtx$appHelper === void 0 ? void 0 : _engineCtx$appHelper.pisellos);
16
+ } catch (_unused) {
17
+ return false;
18
+ }
11
19
  };
12
- export var isMobile = function isMobile() {
13
- var sUserAgent = window.navigator.userAgent.toLowerCase();
14
- var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
15
- var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
16
- var bIsMidp = sUserAgent.match(/midp/i) == "midp";
17
- var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
18
- var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
19
- var bIsAndroid = sUserAgent.match(/android/i) == "android";
20
- var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
21
- var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
22
- if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || isIpad()) {
23
- return true;
24
- } else {
25
- return false;
26
- }
20
+ const isIpad = () => {
21
+ var ua = navigator.userAgent;
22
+ var isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
23
+ var isIphone = ua.indexOf("iPhone") != -1 && ua.indexOf("Version") != -1;
24
+ var isIPad = isSafari && !isIphone && "ontouchend" in document;
25
+ if (!/iphone|ios|ipad|android|mobile/i.test(navigator.userAgent.toLowerCase()) && !isIPad) return false;
26
+ return true;
27
27
  };
28
-
29
- // 是否是安卓平台
30
- export var isAndroid = function isAndroid() {
31
- return navigator.userAgent.toLowerCase().indexOf("android") !== -1;
28
+ const isMobile = () => {
29
+ let sUserAgent = window.navigator.userAgent.toLowerCase();
30
+ let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
31
+ let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
32
+ let bIsMidp = sUserAgent.match(/midp/i) == "midp";
33
+ let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
34
+ let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
35
+ let bIsAndroid = sUserAgent.match(/android/i) == "android";
36
+ let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
37
+ let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
38
+ if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || isIpad()) return true;
39
+ else return false;
32
40
  };
33
-
34
- // 是否是ios平台
35
- export var isIos = function isIos() {
36
- return /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
41
+ const isAndroid = () => {
42
+ return navigator.userAgent.toLowerCase().indexOf("android") !== -1;
37
43
  };
38
- export var checkEnv = function checkEnv() {
39
- // 0: 非浏览器环境
40
- var env = 0;
41
- var userAgent = window.navigator.userAgent;
42
- var isOpera = userAgent.indexOf('Opera') > -1 || userAgent.indexOf('OPR') > -1; //判断是否Opera浏览器
43
- var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1; //判断是否IE7~IE10浏览器
44
- var isIE11 = userAgent.indexOf('compatible') === -1 && userAgent.indexOf('Trident') > -1; //判断是否IE11浏览器
45
- var isEdge = userAgent.indexOf('Edge') > -1; //判断是否IE的Edge浏览器
46
- var isFF = userAgent.indexOf('Firefox') > -1; //判断是否Firefox浏览器
47
- var isSafari = userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Chrome') === -1; //判断是否Safari浏览器
48
- var isChrome = userAgent.indexOf('Chrome') > -1 && userAgent.indexOf('; Win') > -1 && userAgent.indexOf('Safari') > -1; //判断Chrome浏览器
49
- //常用浏览器
50
- if (isOpera || isIE || isIE11 || isEdge || isFF || isSafari || isChrome) {
51
- env = 0;
52
- } else {
53
- env = 1;
54
- }
55
- return env;
44
+ const isIos = () => {
45
+ return /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
56
46
  };
57
- export var isWx = function isWx() {
58
- if (isBrowser) {
59
- var ua = '';
60
- if (isBrowser) {
61
- ua = window.navigator.userAgent.toLowerCase();
62
- }
63
- //@ts-ignore
64
- if (ua.match(/MicroMessenger/i) == 'micromessenger') {
65
- return true;
66
- }
67
- return false;
68
- }
69
- return false;
47
+ const checkEnv = () => {
48
+ let env = 0;
49
+ let userAgent = window.navigator.userAgent;
50
+ let isOpera = userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1;
51
+ let isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
52
+ let isIE11 = userAgent.indexOf("compatible") === -1 && userAgent.indexOf("Trident") > -1;
53
+ let isEdge = userAgent.indexOf("Edge") > -1;
54
+ let isFF = userAgent.indexOf("Firefox") > -1;
55
+ let isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1;
56
+ let isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("; Win") > -1 && userAgent.indexOf("Safari") > -1;
57
+ if (isOpera || isIE || isIE11 || isEdge || isFF || isSafari || isChrome) env = 0;
58
+ else env = 1;
59
+ return env;
70
60
  };
71
- export var isIOS = function isIOS() {
72
- if (isBrowser) {
73
- var u = navigator.userAgent;
74
- var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
75
- return isiOS;
76
- }
77
- return false;
61
+ const isWx = () => {
62
+ if (isBrowser) {
63
+ let ua = "";
64
+ if (isBrowser) ua = window.navigator.userAgent.toLowerCase();
65
+ if (ua.match(/MicroMessenger/i) == "micromessenger") return true;
66
+ return false;
67
+ }
68
+ return false;
78
69
  };
79
- export var isWxApp = function isWxApp() {
80
- if (isBrowser) {
81
- var u = navigator.userAgent;
82
- var isWxapp = u.indexOf('miniProgram') !== -1;
83
- return isWxapp;
84
- }
85
- return false;
70
+ const isIOS = () => {
71
+ if (isBrowser) return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
72
+ return false;
86
73
  };
87
- export var isSafari = function isSafari() {
88
- if (isBrowser) {
89
- var userAgent = window.navigator.userAgent;
90
- return userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Chrome') === -1 && userAgent.indexOf('CriOS') === -1 && userAgent.indexOf('ChannelName/Feishu') === -1;
91
- }
92
- return false;
93
- };
74
+ const isWxApp = () => {
75
+ if (isBrowser) return navigator.userAgent.indexOf("miniProgram") !== -1;
76
+ return false;
77
+ };
78
+ const isSafari = () => {
79
+ if (isBrowser) {
80
+ let userAgent = window.navigator.userAgent;
81
+ return userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") === -1 && userAgent.indexOf("CriOS") === -1 && userAgent.indexOf("ChannelName/Feishu") === -1;
82
+ }
83
+ return false;
84
+ };
85
+ //#endregion
86
+ export { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWebposOsServerEnv, isWx, isWxApp };
@@ -1,3 +1,4 @@
1
+ //#region src/select/hooks/useDebouncedSearch.d.ts
1
2
  /**
2
3
  * 防抖搜索 Hook
3
4
  * 对用户输入进行防抖处理,避免频繁触发搜索
@@ -17,4 +18,6 @@
17
18
  * });
18
19
  * ```
19
20
  */
20
- export declare function useDebouncedSearch<T = string>(initialValue: T, delay: number, callback?: (value: T) => void): [T, (value: T) => void];
21
+ declare function useDebouncedSearch<T = string>(initialValue: T, delay: number, callback?: (value: T) => void): [T, (value: T) => void];
22
+ //#endregion
23
+ export { useDebouncedSearch };
@@ -1,55 +1,41 @@
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; }
1
+ import { useEffect, useState } from "react";
2
+ //#region src/select/hooks/useDebouncedSearch.ts
7
3
  /**
8
- * 防抖搜索 Hook
9
- * 对用户输入进行防抖处理,避免频繁触发搜索
10
- */
11
-
12
- import { useState, useEffect } from 'react';
13
-
4
+ * 防抖搜索 Hook
5
+ * 对用户输入进行防抖处理,避免频繁触发搜索
6
+ */
14
7
  /**
15
- * 防抖搜索 Hook
16
- * @template T 值的类型
17
- * @param initialValue 初始值
18
- * @param delay 防抖延迟时间(毫秒)
19
- * @param callback 防抖后的回调函数
20
- * @returns [防抖后的值, 设置值函数]
21
- *
22
- * @example
23
- * ```tsx
24
- * const [debouncedSearch, setSearchInput] = useDebouncedSearch('', 300, (text) => {
25
- * console.log('搜索关键词:', text);
26
- * });
27
- * ```
28
- */
29
- export function useDebouncedSearch(initialValue, delay, callback) {
30
- // 实时值(用户输入)
31
- var _useState = useState(initialValue),
32
- _useState2 = _slicedToArray(_useState, 2),
33
- value = _useState2[0],
34
- setValue = _useState2[1];
35
-
36
- // 防抖后的值
37
- var _useState3 = useState(initialValue),
38
- _useState4 = _slicedToArray(_useState3, 2),
39
- debouncedValue = _useState4[0],
40
- setDebouncedValue = _useState4[1];
41
- useEffect(function () {
42
- // 创建定时器
43
- var timer = setTimeout(function () {
44
- setDebouncedValue(value);
45
- // 触发回调
46
- callback === null || callback === void 0 || callback(value);
47
- }, delay);
48
-
49
- // 清理定时器
50
- return function () {
51
- clearTimeout(timer);
52
- };
53
- }, [value, delay, callback]);
54
- return [debouncedValue, setValue];
55
- }
8
+ * 防抖搜索 Hook
9
+ * @template T 值的类型
10
+ * @param initialValue 初始值
11
+ * @param delay 防抖延迟时间(毫秒)
12
+ * @param callback 防抖后的回调函数
13
+ * @returns [防抖后的值, 设置值函数]
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const [debouncedSearch, setSearchInput] = useDebouncedSearch('', 300, (text) => {
18
+ * console.log('搜索关键词:', text);
19
+ * });
20
+ * ```
21
+ */
22
+ function useDebouncedSearch(initialValue, delay, callback) {
23
+ const [value, setValue] = useState(initialValue);
24
+ const [debouncedValue, setDebouncedValue] = useState(initialValue);
25
+ useEffect(() => {
26
+ const timer = setTimeout(() => {
27
+ setDebouncedValue(value);
28
+ callback === null || callback === void 0 || callback(value);
29
+ }, delay);
30
+ return () => {
31
+ clearTimeout(timer);
32
+ };
33
+ }, [
34
+ value,
35
+ delay,
36
+ callback
37
+ ]);
38
+ return [debouncedValue, setValue];
39
+ }
40
+ //#endregion
41
+ export { useDebouncedSearch };
@@ -1,19 +1,19 @@
1
- /**
2
- * Select 状态管理 Hook
3
- * 处理受控/非受控模式,适用于单选和多选
4
- */
5
- import type { UseSelectStateOptions, UseMultipleSelectStateOptions, SelectState, MultipleSelectState } from '../types';
1
+ import { MultipleSelectState, SelectState, UseMultipleSelectStateOptions, UseSelectStateOptions } from "../types.js";
2
+
3
+ //#region src/select/hooks/useSelectState.d.ts
6
4
  /**
7
5
  * 单选状态管理 Hook
8
6
  * @template T 值的类型
9
7
  * @param options Hook 配置选项
10
8
  * @returns 状态管理对象
11
9
  */
12
- export declare function useSelectState<T = string | number>(options: UseSelectStateOptions<T>): SelectState<T>;
10
+ declare function useSelectState<T = string | number>(options: UseSelectStateOptions<T>): SelectState<T>;
13
11
  /**
14
12
  * 多选状态管理 Hook
15
13
  * @template T 值的类型
16
14
  * @param options Hook 配置选项
17
15
  * @returns 状态管理对象
18
16
  */
19
- export declare function useMultipleSelectState<T = string | number>(options: UseMultipleSelectStateOptions<T>): MultipleSelectState<T>;
17
+ declare function useMultipleSelectState<T = string | number>(options: UseMultipleSelectStateOptions<T>): MultipleSelectState<T>;
18
+ //#endregion
19
+ export { useMultipleSelectState, useSelectState };
@@ -1,117 +1,60 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
- 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."); }
7
- 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); }
8
- 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; }
9
- 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; } }
10
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
+ import { useCallback, useState } from "react";
2
+ //#region src/select/hooks/useSelectState.ts
11
3
  /**
12
- * Select 状态管理 Hook
13
- * 处理受控/非受控模式,适用于单选和多选
14
- */
15
-
16
- import { useState, useCallback } from 'react';
4
+ * Select 状态管理 Hook
5
+ * 处理受控/非受控模式,适用于单选和多选
6
+ */
17
7
  /**
18
- * 单选状态管理 Hook
19
- * @template T 值的类型
20
- * @param options Hook 配置选项
21
- * @returns 状态管理对象
22
- */
23
- export function useSelectState(options) {
24
- var controlledValue = options.value,
25
- defaultValue = options.defaultValue,
26
- onChange = options.onChange;
27
-
28
- // 判断是否为受控组件
29
- var isControlled = controlledValue !== undefined;
30
-
31
- // 内部状态(非受控模式使用)
32
- var _useState = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null),
33
- _useState2 = _slicedToArray(_useState, 2),
34
- internalValue = _useState2[0],
35
- setInternalValue = _useState2[1];
36
-
37
- // 当前值
38
- var value = isControlled ? controlledValue : internalValue;
39
-
40
- // 设置值
41
- var setValue = useCallback(function (newValue) {
42
- if (!isControlled) {
43
- setInternalValue(newValue);
44
- }
45
- // 触发 onChange 回调
46
- onChange === null || onChange === void 0 || onChange(newValue, null); // TODO: 传入对应的 option 对象
47
- }, [isControlled, onChange]);
48
-
49
- // 清空值
50
- var clearValue = useCallback(function () {
51
- setValue(null);
52
- }, [setValue]);
53
- return {
54
- value: value,
55
- setValue: setValue,
56
- clearValue: clearValue
57
- };
8
+ * 单选状态管理 Hook
9
+ * @template T 值的类型
10
+ * @param options Hook 配置选项
11
+ * @returns 状态管理对象
12
+ */
13
+ function useSelectState(options) {
14
+ const { value: controlledValue, defaultValue, onChange } = options;
15
+ const isControlled = controlledValue !== void 0;
16
+ const [internalValue, setInternalValue] = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null);
17
+ const value = isControlled ? controlledValue : internalValue;
18
+ const setValue = useCallback((newValue) => {
19
+ if (!isControlled) setInternalValue(newValue);
20
+ onChange === null || onChange === void 0 || onChange(newValue, null);
21
+ }, [isControlled, onChange]);
22
+ return {
23
+ value,
24
+ setValue,
25
+ clearValue: useCallback(() => {
26
+ setValue(null);
27
+ }, [setValue])
28
+ };
58
29
  }
59
-
60
30
  /**
61
- * 多选状态管理 Hook
62
- * @template T 值的类型
63
- * @param options Hook 配置选项
64
- * @returns 状态管理对象
65
- */
66
- export function useMultipleSelectState(options) {
67
- var controlledValue = options.value,
68
- defaultValue = options.defaultValue,
69
- onChange = options.onChange;
70
-
71
- // 判断是否为受控组件
72
- var isControlled = controlledValue !== undefined;
73
-
74
- // 内部状态(非受控模式使用)
75
- var _useState3 = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : []),
76
- _useState4 = _slicedToArray(_useState3, 2),
77
- internalValue = _useState4[0],
78
- setInternalValue = _useState4[1];
79
-
80
- // 当前值
81
- var value = isControlled ? controlledValue !== null && controlledValue !== void 0 ? controlledValue : [] : internalValue;
82
-
83
- // 设置值
84
- var setValue = useCallback(function (newValue) {
85
- if (!isControlled) {
86
- setInternalValue(newValue);
87
- }
88
- // 触发 onChange 回调
89
- onChange === null || onChange === void 0 || onChange(newValue, []); // TODO: 传入对应的 options 数组
90
- }, [isControlled, onChange]);
91
-
92
- // 添加一个值
93
- var addValue = useCallback(function (val) {
94
- var newValue = [].concat(_toConsumableArray(value), [val]);
95
- setValue(newValue);
96
- }, [value, setValue]);
97
-
98
- // 移除一个值
99
- var removeValue = useCallback(function (val) {
100
- var newValue = value.filter(function (v) {
101
- return v !== val;
102
- });
103
- setValue(newValue);
104
- }, [value, setValue]);
105
-
106
- // 清空所有值
107
- var clearValue = useCallback(function () {
108
- setValue([]);
109
- }, [setValue]);
110
- return {
111
- value: value,
112
- setValue: setValue,
113
- addValue: addValue,
114
- removeValue: removeValue,
115
- clearValue: clearValue
116
- };
117
- }
31
+ * 多选状态管理 Hook
32
+ * @template T 值的类型
33
+ * @param options Hook 配置选项
34
+ * @returns 状态管理对象
35
+ */
36
+ function useMultipleSelectState(options) {
37
+ const { value: controlledValue, defaultValue, onChange } = options;
38
+ const isControlled = controlledValue !== void 0;
39
+ const [internalValue, setInternalValue] = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : []);
40
+ const value = isControlled ? controlledValue !== null && controlledValue !== void 0 ? controlledValue : [] : internalValue;
41
+ const setValue = useCallback((newValue) => {
42
+ if (!isControlled) setInternalValue(newValue);
43
+ onChange === null || onChange === void 0 || onChange(newValue, []);
44
+ }, [isControlled, onChange]);
45
+ return {
46
+ value,
47
+ setValue,
48
+ addValue: useCallback((val) => {
49
+ setValue([...value, val]);
50
+ }, [value, setValue]),
51
+ removeValue: useCallback((val) => {
52
+ setValue(value.filter((v) => v !== val));
53
+ }, [value, setValue]),
54
+ clearValue: useCallback(() => {
55
+ setValue([]);
56
+ }, [setValue])
57
+ };
58
+ }
59
+ //#endregion
60
+ export { useMultipleSelectState, useSelectState };
@@ -1,8 +1,7 @@
1
- /**
2
- * Select 组件相关工具和类型导出
3
- * 供 PisellSingleSelect、PisellMultipleSelect 等组件使用
4
- */
5
- export type { SelectOption, FilterOptionFunc, SortDirection, SelectState, MultipleSelectState, TagDisplayInfo, UseSelectStateOptions, UseMultipleSelectStateOptions, BaseSelectProps, } from './types';
6
- export { useSelectState, useMultipleSelectState } from './hooks/useSelectState';
7
- export { useDebouncedSearch } from './hooks/useDebouncedSearch';
8
- export { filterOptions, defaultFilterOption, sortOptions, calculateTagDisplay, findOptionByValue, findOptionsByValues, isOptionSelected, isOptionSelectedInMultiple, generateId, } from './utils';
1
+ import { BaseSelectProps, FilterOptionFunc, MultipleSelectState, SelectOption, SelectState, SortDirection, TagDisplayInfo, UseMultipleSelectStateOptions, UseSelectStateOptions } from "./types.js";
2
+ import { useMultipleSelectState, useSelectState } from "./hooks/useSelectState.js";
3
+ import { useDebouncedSearch } from "./hooks/useDebouncedSearch.js";
4
+ import { calculateTagDisplay } from "./utils/tagAggregation.js";
5
+ import { defaultFilterOption, filterOptions } from "./utils/filterOptions.js";
6
+ import { sortOptions } from "./utils/sortOptions.js";
7
+ import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./utils/helpers.js";