@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.
Files changed (200) hide show
  1. package/es/arrayUtils.d.ts +23 -26
  2. package/es/arrayUtils.js +157 -97
  3. package/es/common/index.d.ts +5 -0
  4. package/es/common/index.js +5 -0
  5. package/es/common/stateHelper.d.ts +2 -6
  6. package/es/common/stateHelper.js +24 -22
  7. package/es/common/types.d.ts +10 -13
  8. package/es/common/types.js +1 -0
  9. package/es/componentStorage.d.ts +25 -27
  10. package/es/componentStorage.js +130 -94
  11. package/es/constants/index.js +9 -7
  12. package/es/date.js +53 -36
  13. package/es/document.js +67 -43
  14. package/es/escPosPrinter/EscPosPrinter.js +490 -353
  15. package/es/escPosPrinter/index.d.ts +9 -9
  16. package/es/escPosPrinter/index.js +52 -37
  17. package/es/firebase/config/index.js +54 -0
  18. package/es/firebase/index.js +232 -0
  19. package/es/format.d.ts +15 -12
  20. package/es/format.js +156 -89
  21. package/es/image.js +60 -48
  22. package/es/index.d.ts +24 -39
  23. package/es/index.js +35 -40
  24. package/es/jsBridge/index.d.ts +4 -8
  25. package/es/jsBridge/index.js +55 -56
  26. package/es/jsBridge/regDeviceApi.js +126 -87
  27. package/es/jsBridge/types.d.ts +115 -95
  28. package/es/jsBridge/types.js +1 -0
  29. package/es/locales.d.ts +8 -11
  30. package/es/locales.js +96 -77
  31. package/es/log.d.ts +6 -11
  32. package/es/log.js +59 -37
  33. package/es/miniRedux.d.ts +13 -20
  34. package/es/miniRedux.js +76 -42
  35. package/es/number-input/hooks/index.d.ts +4 -0
  36. package/es/number-input/hooks/index.js +5 -0
  37. package/es/number-input/hooks/useNumberInputState.d.ts +2 -6
  38. package/es/number-input/hooks/useNumberInputState.js +128 -71
  39. package/es/number-input/index.d.ts +14 -0
  40. package/es/number-input/index.js +21 -0
  41. package/es/number-input/types.d.ts +88 -88
  42. package/es/number-input/types.js +1 -0
  43. package/es/number-input/utils/formatter.d.ts +10 -13
  44. package/es/number-input/utils/formatter.js +77 -51
  45. package/es/number-input/utils/index.d.ts +7 -0
  46. package/es/number-input/utils/index.js +8 -0
  47. package/es/number-input/utils/validation.d.ts +2 -7
  48. package/es/number-input/utils/validation.js +66 -51
  49. package/es/otherUtils.d.ts +9 -12
  50. package/es/otherUtils.js +129 -71
  51. package/es/platform.d.ts +9 -12
  52. package/es/platform.js +85 -61
  53. package/es/select/hooks/index.d.ts +5 -0
  54. package/es/select/hooks/index.js +6 -0
  55. package/es/select/hooks/useDebouncedSearch.d.ts +1 -4
  56. package/es/select/hooks/useDebouncedSearch.js +53 -39
  57. package/es/select/hooks/useSelectState.d.ts +7 -7
  58. package/es/select/hooks/useSelectState.js +113 -56
  59. package/es/select/index.d.ts +8 -7
  60. package/es/select/index.js +13 -0
  61. package/es/select/types.d.ts +211 -211
  62. package/es/select/types.js +1 -0
  63. package/es/select/utils/filterOptions.d.ts +6 -7
  64. package/es/select/utils/filterOptions.js +31 -26
  65. package/es/select/utils/helpers.d.ts +9 -10
  66. package/es/select/utils/helpers.js +52 -42
  67. package/es/select/utils/index.d.ts +7 -4
  68. package/es/select/utils/index.js +8 -0
  69. package/es/select/utils/sortOptions.d.ts +5 -6
  70. package/es/select/utils/sortOptions.js +31 -19
  71. package/es/select/utils/tagAggregation.d.ts +6 -6
  72. package/es/select/utils/tagAggregation.js +47 -34
  73. package/es/text-input/hooks/index.d.ts +4 -0
  74. package/es/text-input/hooks/index.js +5 -0
  75. package/es/text-input/hooks/useTextInputState.d.ts +2 -6
  76. package/es/text-input/hooks/useTextInputState.js +126 -69
  77. package/es/text-input/index.d.ts +14 -0
  78. package/es/text-input/index.js +20 -0
  79. package/es/text-input/types.d.ts +48 -48
  80. package/es/text-input/types.js +1 -0
  81. package/es/text-input/utils/index.d.ts +5 -0
  82. package/es/text-input/utils/index.js +7 -0
  83. package/es/text-input/utils/validation.d.ts +2 -7
  84. package/es/text-input/utils/validation.js +70 -50
  85. package/es/typeUtils.js +84 -61
  86. package/es/walletValidity.d.ts +42 -44
  87. package/es/walletValidity.js +557 -396
  88. package/es/weighing.d.ts +45 -48
  89. package/es/weighing.js +106 -83
  90. package/lib/arrayUtils.d.ts +23 -26
  91. package/lib/arrayUtils.js +111 -101
  92. package/lib/common/index.d.ts +5 -0
  93. package/lib/common/index.js +29 -0
  94. package/lib/common/stateHelper.d.ts +2 -6
  95. package/lib/common/stateHelper.js +32 -21
  96. package/lib/common/types.d.ts +10 -13
  97. package/lib/common/types.js +17 -0
  98. package/lib/componentStorage.d.ts +25 -27
  99. package/lib/componentStorage.js +126 -96
  100. package/lib/constants/index.js +36 -7
  101. package/lib/date.js +65 -43
  102. package/lib/document.js +62 -46
  103. package/lib/escPosPrinter/EscPosPrinter.js +403 -327
  104. package/lib/escPosPrinter/index.d.ts +9 -9
  105. package/lib/escPosPrinter/index.js +84 -38
  106. package/lib/firebase/config/index.js +79 -0
  107. package/lib/firebase/index.js +180 -0
  108. package/lib/format.d.ts +15 -12
  109. package/lib/format.js +133 -91
  110. package/lib/image.js +74 -48
  111. package/lib/index.d.ts +24 -39
  112. package/lib/index.js +80 -137
  113. package/lib/jsBridge/index.d.ts +4 -8
  114. package/lib/jsBridge/index.js +76 -57
  115. package/lib/jsBridge/regDeviceApi.js +133 -86
  116. package/lib/jsBridge/types.d.ts +115 -95
  117. package/lib/jsBridge/types.js +17 -0
  118. package/lib/locales.d.ts +8 -11
  119. package/lib/locales.js +90 -79
  120. package/lib/log.d.ts +6 -11
  121. package/lib/log.js +61 -37
  122. package/lib/miniRedux.d.ts +13 -20
  123. package/lib/miniRedux.js +89 -43
  124. package/lib/number-input/hooks/index.d.ts +4 -0
  125. package/lib/number-input/hooks/index.js +29 -0
  126. package/lib/number-input/hooks/useNumberInputState.d.ts +2 -6
  127. package/lib/number-input/hooks/useNumberInputState.js +81 -71
  128. package/lib/number-input/index.d.ts +14 -0
  129. package/lib/number-input/index.js +41 -0
  130. package/lib/number-input/types.d.ts +88 -88
  131. package/lib/number-input/types.js +17 -0
  132. package/lib/number-input/utils/formatter.d.ts +10 -13
  133. package/lib/number-input/utils/formatter.js +49 -52
  134. package/lib/number-input/utils/index.d.ts +7 -0
  135. package/lib/number-input/utils/index.js +39 -0
  136. package/lib/number-input/utils/validation.d.ts +2 -7
  137. package/lib/number-input/utils/validation.js +52 -50
  138. package/lib/otherUtils.d.ts +9 -12
  139. package/lib/otherUtils.js +98 -86
  140. package/lib/platform.d.ts +9 -12
  141. package/lib/platform.js +123 -68
  142. package/lib/select/hooks/index.d.ts +5 -0
  143. package/lib/select/hooks/index.js +34 -0
  144. package/lib/select/hooks/useDebouncedSearch.d.ts +1 -4
  145. package/lib/select/hooks/useDebouncedSearch.js +41 -40
  146. package/lib/select/hooks/useSelectState.d.ts +7 -7
  147. package/lib/select/hooks/useSelectState.js +93 -58
  148. package/lib/select/index.d.ts +8 -7
  149. package/lib/select/index.js +53 -0
  150. package/lib/select/types.d.ts +211 -211
  151. package/lib/select/types.js +17 -0
  152. package/lib/select/utils/filterOptions.d.ts +6 -7
  153. package/lib/select/utils/filterOptions.js +37 -26
  154. package/lib/select/utils/helpers.d.ts +9 -10
  155. package/lib/select/utils/helpers.js +41 -45
  156. package/lib/select/utils/index.d.ts +7 -4
  157. package/lib/select/utils/index.js +48 -0
  158. package/lib/select/utils/sortOptions.d.ts +5 -6
  159. package/lib/select/utils/sortOptions.js +39 -18
  160. package/lib/select/utils/tagAggregation.d.ts +6 -6
  161. package/lib/select/utils/tagAggregation.js +41 -33
  162. package/lib/text-input/hooks/index.d.ts +4 -0
  163. package/lib/text-input/hooks/index.js +29 -0
  164. package/lib/text-input/hooks/useTextInputState.d.ts +2 -6
  165. package/lib/text-input/hooks/useTextInputState.js +79 -69
  166. package/lib/text-input/index.d.ts +14 -0
  167. package/lib/text-input/index.js +35 -0
  168. package/lib/text-input/types.d.ts +48 -48
  169. package/lib/text-input/types.js +17 -0
  170. package/lib/text-input/utils/index.d.ts +5 -0
  171. package/lib/text-input/utils/index.js +32 -0
  172. package/lib/text-input/utils/validation.d.ts +2 -7
  173. package/lib/text-input/utils/validation.js +58 -49
  174. package/lib/typeUtils.js +73 -68
  175. package/lib/walletValidity.d.ts +42 -44
  176. package/lib/walletValidity.js +393 -410
  177. package/lib/weighing.d.ts +45 -48
  178. package/lib/weighing.js +149 -104
  179. package/package.json +1 -1
  180. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  181. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  182. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  183. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  184. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  185. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -11
  186. package/es/date.d.ts +0 -31
  187. package/es/document.d.ts +0 -16
  188. package/es/image.d.ts +0 -14
  189. package/es/typeUtils.d.ts +0 -45
  190. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  191. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  192. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  193. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  194. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  195. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -16
  196. package/lib/_virtual/_rolldown/runtime.js +0 -23
  197. package/lib/date.d.ts +0 -31
  198. package/lib/document.d.ts +0 -16
  199. package/lib/image.d.ts +0 -14
  200. package/lib/typeUtils.d.ts +0 -45
@@ -1,51 +1,61 @@
1
- //#region src/select/utils/helpers.ts
2
1
  /**
3
- * 根据值查找选项对象
4
- * @template T 选项值的类型
5
- * @param value 选项值
6
- * @param options 选项列表
7
- * @returns 找到的选项对象,如果没找到返回 undefined
8
- */
9
- function findOptionByValue(value, options) {
10
- return options.find((opt) => opt.value === value);
11
- }
2
+ * Select 组件辅助函数
3
+ */
4
+
12
5
  /**
13
- * 根据值数组查找选项对象数组
14
- * @template T 选项值的类型
15
- * @param values 选项值数组
16
- * @param options 选项列表
17
- * @returns 找到的选项对象数组
18
- */
19
- function findOptionsByValues(values, options) {
20
- return values.map((val) => findOptionByValue(val, options)).filter(Boolean);
6
+ * 根据值查找选项对象
7
+ * @template T 选项值的类型
8
+ * @param value 选项值
9
+ * @param options 选项列表
10
+ * @returns 找到的选项对象,如果没找到返回 undefined
11
+ */
12
+ export function findOptionByValue(value, options) {
13
+ return options.find(function (opt) {
14
+ return opt.value === value;
15
+ });
21
16
  }
17
+
22
18
  /**
23
- * 判断选项是否被选中(单选)
24
- * @template T 选项值的类型
25
- * @param optionValue 选项值
26
- * @param selectedValue 当前选中值
27
- * @returns 是否选中
28
- */
29
- function isOptionSelected(optionValue, selectedValue) {
30
- return selectedValue !== null && selectedValue !== void 0 && optionValue === selectedValue;
19
+ * 根据值数组查找选项对象数组
20
+ * @template T 选项值的类型
21
+ * @param values 选项值数组
22
+ * @param options 选项列表
23
+ * @returns 找到的选项对象数组
24
+ */
25
+ export function findOptionsByValues(values, options) {
26
+ return values.map(function (val) {
27
+ return findOptionByValue(val, options);
28
+ }).filter(Boolean);
31
29
  }
30
+
32
31
  /**
33
- * 判断选项是否被选中(多选)
34
- * @template T 选项值的类型
35
- * @param optionValue 选项值
36
- * @param selectedValues 当前选中值数组
37
- * @returns 是否选中
38
- */
39
- function isOptionSelectedInMultiple(optionValue, selectedValues) {
40
- return selectedValues.includes(optionValue);
32
+ * 判断选项是否被选中(单选)
33
+ * @template T 选项值的类型
34
+ * @param optionValue 选项值
35
+ * @param selectedValue 当前选中值
36
+ * @returns 是否选中
37
+ */
38
+ export function isOptionSelected(optionValue, selectedValue) {
39
+ return selectedValue !== null && selectedValue !== undefined && optionValue === selectedValue;
41
40
  }
41
+
42
42
  /**
43
- * 生成唯一 ID
44
- * @param prefix ID 前缀
45
- * @returns 唯一 ID
46
- */
47
- function generateId(prefix = "select") {
48
- return `${prefix}-${Math.random().toString(36).substr(2, 9)}`;
43
+ * 判断选项是否被选中(多选)
44
+ * @template T 选项值的类型
45
+ * @param optionValue 选项值
46
+ * @param selectedValues 当前选中值数组
47
+ * @returns 是否选中
48
+ */
49
+ export function isOptionSelectedInMultiple(optionValue, selectedValues) {
50
+ return selectedValues.includes(optionValue);
49
51
  }
50
- //#endregion
51
- export { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple };
52
+
53
+ /**
54
+ * 生成唯一 ID
55
+ * @param prefix ID 前缀
56
+ * @returns 唯一 ID
57
+ */
58
+ export function generateId() {
59
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'select';
60
+ return "".concat(prefix, "-").concat(Math.random().toString(36).substr(2, 9));
61
+ }
@@ -1,4 +1,7 @@
1
- import { calculateTagDisplay } from "./tagAggregation.js";
2
- import { defaultFilterOption, filterOptions } from "./filterOptions.js";
3
- import { sortOptions } from "./sortOptions.js";
4
- import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./helpers.js";
1
+ /**
2
+ * Select 工具函数导出
3
+ */
4
+ export { calculateTagDisplay } from './tagAggregation';
5
+ export { filterOptions, defaultFilterOption } from './filterOptions';
6
+ export { sortOptions } from './sortOptions';
7
+ export { findOptionByValue, findOptionsByValues, isOptionSelected, isOptionSelectedInMultiple, generateId, } from './helpers';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Select 工具函数导出
3
+ */
4
+
5
+ export { calculateTagDisplay } from "./tagAggregation";
6
+ export { filterOptions, defaultFilterOption } from "./filterOptions";
7
+ export { sortOptions } from "./sortOptions";
8
+ export { findOptionByValue, findOptionsByValues, isOptionSelected, isOptionSelectedInMultiple, generateId } from "./helpers";
@@ -1,6 +1,7 @@
1
- import { SelectOption, SortDirection } from "../types.js";
2
-
3
- //#region src/select/utils/sortOptions.d.ts
1
+ /**
2
+ * 选项排序工具函数
3
+ */
4
+ import type { SelectOption, SortDirection } from '../types';
4
5
  /**
5
6
  * 排序选项列表
6
7
  * @template T 选项值的类型
@@ -8,6 +9,4 @@ import { SelectOption, SortDirection } from "../types.js";
8
9
  * @param direction 排序方向('asc' 升序 | 'desc' 降序)
9
10
  * @returns 排序后的选项列表(新数组)
10
11
  */
11
- declare function sortOptions<T = string | number>(options: SelectOption<T>[], direction?: SortDirection): SelectOption<T>[];
12
- //#endregion
13
- export { sortOptions };
12
+ export declare function sortOptions<T = string | number>(options: SelectOption<T>[], direction?: SortDirection): SelectOption<T>[];
@@ -1,20 +1,32 @@
1
- //#region src/select/utils/sortOptions.ts
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 _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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; }
2
7
  /**
3
- * 排序选项列表
4
- * @template T 选项值的类型
5
- * @param options 原始选项列表
6
- * @param direction 排序方向('asc' 升序 | 'desc' 降序)
7
- * @returns 排序后的选项列表(新数组)
8
- */
9
- function sortOptions(options, direction = "asc") {
10
- const sortedOptions = [...options];
11
- sortedOptions.sort((a, b) => {
12
- const labelA = a.label.toLowerCase();
13
- const labelB = b.label.toLowerCase();
14
- if (direction === "asc") return labelA.localeCompare(labelB);
15
- else return labelB.localeCompare(labelA);
16
- });
17
- return sortedOptions;
18
- }
19
- //#endregion
20
- export { sortOptions };
8
+ * 选项排序工具函数
9
+ */
10
+
11
+ /**
12
+ * 排序选项列表
13
+ * @template T 选项值的类型
14
+ * @param options 原始选项列表
15
+ * @param direction 排序方向('asc' 升序 | 'desc' 降序)
16
+ * @returns 排序后的选项列表(新数组)
17
+ */
18
+ export function sortOptions(options) {
19
+ var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'asc';
20
+ // 创建副本避免修改原数组
21
+ var sortedOptions = _toConsumableArray(options);
22
+ sortedOptions.sort(function (a, b) {
23
+ var labelA = a.label.toLowerCase();
24
+ var labelB = b.label.toLowerCase();
25
+ if (direction === 'asc') {
26
+ return labelA.localeCompare(labelB);
27
+ } else {
28
+ return labelB.localeCompare(labelA);
29
+ }
30
+ });
31
+ return sortedOptions;
32
+ }
@@ -1,6 +1,8 @@
1
- import { SelectOption, TagDisplayInfo } from "../types.js";
2
-
3
- //#region src/select/utils/tagAggregation.d.ts
1
+ /**
2
+ * 标签聚合工具函数
3
+ * 用于多选下拉组件的标签显示逻辑
4
+ */
5
+ import type { SelectOption, TagDisplayInfo } from '../types';
4
6
  /**
5
7
  * 计算需要显示的标签和聚合信息
6
8
  * @template T 选项值的类型
@@ -20,6 +22,4 @@ import { SelectOption, TagDisplayInfo } from "../types.js";
20
22
  * // }
21
23
  * ```
22
24
  */
23
- declare function calculateTagDisplay<T = string | number>(selectedValues: T[], options: SelectOption<T>[], maxTagCount: number): TagDisplayInfo<T>;
24
- //#endregion
25
- export { calculateTagDisplay };
25
+ export declare function calculateTagDisplay<T = string | number>(selectedValues: T[], options: SelectOption<T>[], maxTagCount: number): TagDisplayInfo<T>;
@@ -1,35 +1,48 @@
1
- //#region src/select/utils/tagAggregation.ts
2
1
  /**
3
- * 计算需要显示的标签和聚合信息
4
- * @template T 选项值的类型
5
- * @param selectedValues 当前选中的值数组
6
- * @param options 所有选项列表
7
- * @param maxTagCount 最多显示的标签数量
8
- * @returns 标签显示信息
9
- *
10
- * @example
11
- * ```tsx
12
- * const tagInfo = calculateTagDisplay(['a', 'b', 'c', 'd'], options, 2);
13
- * // 返回:
14
- * // {
15
- * // visibleTags: [option_a, option_b],
16
- * // hiddenTags: [option_c, option_d],
17
- * // hiddenCount: 2
18
- * // }
19
- * ```
20
- */
21
- function calculateTagDisplay(selectedValues, options, maxTagCount) {
22
- const selectedOptions = selectedValues.map((v) => options.find((opt) => opt.value === v)).filter(Boolean);
23
- if (selectedOptions.length <= maxTagCount) return {
24
- visibleTags: selectedOptions,
25
- hiddenTags: [],
26
- hiddenCount: 0
27
- };
28
- return {
29
- visibleTags: selectedOptions.slice(0, maxTagCount),
30
- hiddenTags: selectedOptions.slice(maxTagCount),
31
- hiddenCount: selectedOptions.length - maxTagCount
32
- };
33
- }
34
- //#endregion
35
- export { calculateTagDisplay };
2
+ * 标签聚合工具函数
3
+ * 用于多选下拉组件的标签显示逻辑
4
+ */
5
+
6
+ /**
7
+ * 计算需要显示的标签和聚合信息
8
+ * @template T 选项值的类型
9
+ * @param selectedValues 当前选中的值数组
10
+ * @param options 所有选项列表
11
+ * @param maxTagCount 最多显示的标签数量
12
+ * @returns 标签显示信息
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const tagInfo = calculateTagDisplay(['a', 'b', 'c', 'd'], options, 2);
17
+ * // 返回:
18
+ * // {
19
+ * // visibleTags: [option_a, option_b],
20
+ * // hiddenTags: [option_c, option_d],
21
+ * // hiddenCount: 2
22
+ * // }
23
+ * ```
24
+ */
25
+ export function calculateTagDisplay(selectedValues, options, maxTagCount) {
26
+ // 根据选中值找到对应的选项对象
27
+ var selectedOptions = selectedValues.map(function (v) {
28
+ return options.find(function (opt) {
29
+ return opt.value === v;
30
+ });
31
+ }).filter(Boolean);
32
+
33
+ // 如果选中数量不超过 maxTagCount,全部显示
34
+ if (selectedOptions.length <= maxTagCount) {
35
+ return {
36
+ visibleTags: selectedOptions,
37
+ hiddenTags: [],
38
+ hiddenCount: 0
39
+ };
40
+ }
41
+
42
+ // 否则进行聚合
43
+ return {
44
+ visibleTags: selectedOptions.slice(0, maxTagCount),
45
+ hiddenTags: selectedOptions.slice(maxTagCount),
46
+ hiddenCount: selectedOptions.length - maxTagCount
47
+ };
48
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 文本输入 Hooks 导出
3
+ */
4
+ export { useTextInputState } from './useTextInputState';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 文本输入 Hooks 导出
3
+ */
4
+
5
+ export { useTextInputState } from "./useTextInputState";
@@ -1,6 +1,4 @@
1
- import { BaseTextInputProps, TextInputState } from "../types.js";
2
-
3
- //#region src/text-input/hooks/useTextInputState.d.ts
1
+ import type { BaseTextInputProps, TextInputState } from '../types';
4
2
  /**
5
3
  * 文本输入状态管理 Hook
6
4
  *
@@ -23,6 +21,4 @@ import { BaseTextInputProps, TextInputState } from "../types.js";
23
21
  * // 非受控模式
24
22
  * const state = useTextInputState({ defaultValue: 'hello' });
25
23
  */
26
- declare function useTextInputState(props: BaseTextInputProps): TextInputState;
27
- //#endregion
28
- export { useTextInputState };
24
+ export declare function useTextInputState(props: BaseTextInputProps): TextInputState;
@@ -1,70 +1,127 @@
1
- import { validateValue } from "../utils/validation.js";
2
- import { useCallback, useState } from "react";
3
- //#region src/text-input/hooks/useTextInputState.ts
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";
4
9
  /**
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 = useTextInputState({ value: 'hello', onChange: (v) => console.log(v) });
22
- *
23
- * // 非受控模式
24
- * const state = useTextInputState({ defaultValue: 'hello' });
25
- */
26
- function useTextInputState(props) {
27
- const isControlled = props.value !== void 0;
28
- const [innerValue, setInnerValue] = useState(props.defaultValue || "");
29
- const [isTouched, setIsTouched] = useState(false);
30
- const [isValid, setIsValid] = useState(true);
31
- const [errors, setErrors] = useState([]);
32
- const currentValue = isControlled ? props.value : innerValue;
33
- return {
34
- value: currentValue,
35
- isTouched,
36
- isValid,
37
- errors,
38
- handleChange: useCallback((newValue) => {
39
- var _props$onChange;
40
- if (!isControlled) setInnerValue(newValue);
41
- if (props.validateTrigger === "onChange" || props.validateTrigger === "both") {
42
- var _props$onValidate;
43
- const validation = validateValue(newValue, props);
44
- setIsValid(validation.isValid);
45
- setErrors(validation.errors);
46
- (_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
47
- }
48
- (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
49
- }, [isControlled, props]),
50
- handleBlur: useCallback(() => {
51
- var _props$onBlur;
52
- setIsTouched(true);
53
- if (props.validateTrigger !== "onChange") {
54
- var _props$onValidate2;
55
- const validation = validateValue(currentValue || "", props);
56
- setIsValid(validation.isValid);
57
- setErrors(validation.errors);
58
- (_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
59
- }
60
- (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue || "");
61
- }, [currentValue, props]),
62
- handleFocus: useCallback(() => {
63
- var _props$onFocus;
64
- setIsTouched(true);
65
- (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
66
- }, [props])
67
- };
68
- }
69
- //#endregion
70
- export { useTextInputState };
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 = useTextInputState({ value: 'hello', onChange: (v) => console.log(v) });
27
+ *
28
+ * // 非受控模式
29
+ * const state = useTextInputState({ defaultValue: 'hello' });
30
+ */
31
+ export function useTextInputState(props) {
32
+ // 判断是否为受控组件
33
+ var isControlled = props.value !== undefined;
34
+
35
+ // 内部状态(仅非受控模式使用)
36
+ var _useState = useState(props.defaultValue || ''),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ innerValue = _useState2[0],
39
+ setInnerValue = _useState2[1];
40
+ var _useState3 = useState(false),
41
+ _useState4 = _slicedToArray(_useState3, 2),
42
+ isTouched = _useState4[0],
43
+ setIsTouched = _useState4[1];
44
+ var _useState5 = useState(true),
45
+ _useState6 = _slicedToArray(_useState5, 2),
46
+ isValid = _useState6[0],
47
+ setIsValid = _useState6[1];
48
+ var _useState7 = useState([]),
49
+ _useState8 = _slicedToArray(_useState7, 2),
50
+ errors = _useState8[0],
51
+ setErrors = _useState8[1];
52
+
53
+ // 当前值(受控模式优先使用 props.value)
54
+ var currentValue = isControlled ? props.value : innerValue;
55
+
56
+ /**
57
+ * 值变更处理函数
58
+ *
59
+ * 1. 更新内部状态(非受控模式)
60
+ * 2. 根据 validateTrigger 决定是否立即校验
61
+ * 3. 触发外部 onChange 回调
62
+ */
63
+ var handleChange = useCallback(function (newValue) {
64
+ var _props$onChange;
65
+ // 更新内部状态(非受控模式)
66
+ if (!isControlled) {
67
+ setInnerValue(newValue);
68
+ }
69
+
70
+ // 根据配置决定是否立即校验
71
+ var shouldValidate = props.validateTrigger === 'onChange' || props.validateTrigger === 'both';
72
+ if (shouldValidate) {
73
+ var _props$onValidate;
74
+ var validation = validateValue(newValue, props);
75
+ setIsValid(validation.isValid);
76
+ setErrors(validation.errors);
77
+ (_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
78
+ }
79
+
80
+ // 触发外部回调
81
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
82
+ }, [isControlled, props]);
83
+
84
+ /**
85
+ * 失焦处理函数
86
+ *
87
+ * 1. 标记为已触摸
88
+ * 2. 执行失焦时的校验(根据 validateTrigger)
89
+ * 3. 触发外部 onBlur 回调
90
+ */
91
+ var handleBlur = useCallback(function () {
92
+ var _props$onBlur;
93
+ setIsTouched(true);
94
+
95
+ // 失焦时执行校验(如果 validateTrigger 不是 'onChange')
96
+ var shouldValidate = props.validateTrigger !== 'onChange';
97
+ if (shouldValidate) {
98
+ var _props$onValidate2;
99
+ var validation = validateValue(currentValue || '', props);
100
+ setIsValid(validation.isValid);
101
+ setErrors(validation.errors);
102
+ (_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
103
+ }
104
+ (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue || '');
105
+ }, [currentValue, props]);
106
+
107
+ /**
108
+ * 聚焦处理函数
109
+ *
110
+ * 1. 标记为已触摸
111
+ * 2. 触发外部 onFocus 回调
112
+ */
113
+ var handleFocus = useCallback(function () {
114
+ var _props$onFocus;
115
+ setIsTouched(true);
116
+ (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
117
+ }, [props]);
118
+ return {
119
+ value: currentValue,
120
+ isTouched: isTouched,
121
+ isValid: isValid,
122
+ errors: errors,
123
+ handleChange: handleChange,
124
+ handleBlur: handleBlur,
125
+ handleFocus: handleFocus
126
+ };
127
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 文本输入组件公共逻辑导出
3
+ *
4
+ * 供以下组件使用:
5
+ * - PisellSingleLineText
6
+ * - PisellLongText
7
+ * - PisellPhone
8
+ * - PisellEmail
9
+ * - PisellUrl
10
+ */
11
+ export type { DisplayState, ValidationResult, TextInputState, BaseTextInputProps, } from './types';
12
+ export { useTextInputState } from './hooks';
13
+ export { getDisplayState } from './utils';
14
+ export { validateValue as validateTextValue } from './utils';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 文本输入组件公共逻辑导出
3
+ *
4
+ * 供以下组件使用:
5
+ * - PisellSingleLineText
6
+ * - PisellLongText
7
+ * - PisellPhone
8
+ * - PisellEmail
9
+ * - PisellUrl
10
+ */
11
+
12
+ // 类型
13
+
14
+ // Hooks
15
+ export { useTextInputState } from "./hooks";
16
+
17
+ // 工具函数
18
+ export { getDisplayState } from "./utils";
19
+ // 使用别名导出避免与 number-input 的 validateValue 重名
20
+ export { validateValue as validateTextValue } from "./utils";