@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,55 +1,51 @@
1
- //#region src/select/utils/helpers.ts
2
- /**
3
- * 根据值查找选项对象
4
- * @template T 选项值的类型
5
- * @param value 选项值
6
- * @param options 选项列表
7
- * @returns 找到的选项对象,如果没找到返回 undefined
8
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/select/utils/helpers.ts
20
+ var helpers_exports = {};
21
+ __export(helpers_exports, {
22
+ findOptionByValue: () => findOptionByValue,
23
+ findOptionsByValues: () => findOptionsByValues,
24
+ generateId: () => generateId,
25
+ isOptionSelected: () => isOptionSelected,
26
+ isOptionSelectedInMultiple: () => isOptionSelectedInMultiple
27
+ });
28
+ module.exports = __toCommonJS(helpers_exports);
9
29
  function findOptionByValue(value, options) {
10
- return options.find((opt) => opt.value === value);
30
+ return options.find((opt) => opt.value === value);
11
31
  }
12
- /**
13
- * 根据值数组查找选项对象数组
14
- * @template T 选项值的类型
15
- * @param values 选项值数组
16
- * @param options 选项列表
17
- * @returns 找到的选项对象数组
18
- */
19
32
  function findOptionsByValues(values, options) {
20
- return values.map((val) => findOptionByValue(val, options)).filter(Boolean);
33
+ return values.map((val) => findOptionByValue(val, options)).filter(Boolean);
21
34
  }
22
- /**
23
- * 判断选项是否被选中(单选)
24
- * @template T 选项值的类型
25
- * @param optionValue 选项值
26
- * @param selectedValue 当前选中值
27
- * @returns 是否选中
28
- */
29
35
  function isOptionSelected(optionValue, selectedValue) {
30
- return selectedValue !== null && selectedValue !== void 0 && optionValue === selectedValue;
36
+ return selectedValue !== null && selectedValue !== void 0 && optionValue === selectedValue;
31
37
  }
32
- /**
33
- * 判断选项是否被选中(多选)
34
- * @template T 选项值的类型
35
- * @param optionValue 选项值
36
- * @param selectedValues 当前选中值数组
37
- * @returns 是否选中
38
- */
39
38
  function isOptionSelectedInMultiple(optionValue, selectedValues) {
40
- return selectedValues.includes(optionValue);
39
+ return selectedValues.includes(optionValue);
41
40
  }
42
- /**
43
- * 生成唯一 ID
44
- * @param prefix ID 前缀
45
- * @returns 唯一 ID
46
- */
47
41
  function generateId(prefix = "select") {
48
- return `${prefix}-${Math.random().toString(36).substr(2, 9)}`;
42
+ return `${prefix}-${Math.random().toString(36).substr(2, 9)}`;
49
43
  }
50
- //#endregion
51
- exports.findOptionByValue = findOptionByValue;
52
- exports.findOptionsByValues = findOptionsByValues;
53
- exports.generateId = generateId;
54
- exports.isOptionSelected = isOptionSelected;
55
- exports.isOptionSelectedInMultiple = isOptionSelectedInMultiple;
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ findOptionByValue,
47
+ findOptionsByValues,
48
+ generateId,
49
+ isOptionSelected,
50
+ isOptionSelectedInMultiple
51
+ });
@@ -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,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/select/utils/index.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ calculateTagDisplay: () => import_tagAggregation.calculateTagDisplay,
23
+ defaultFilterOption: () => import_filterOptions.defaultFilterOption,
24
+ filterOptions: () => import_filterOptions.filterOptions,
25
+ findOptionByValue: () => import_helpers.findOptionByValue,
26
+ findOptionsByValues: () => import_helpers.findOptionsByValues,
27
+ generateId: () => import_helpers.generateId,
28
+ isOptionSelected: () => import_helpers.isOptionSelected,
29
+ isOptionSelectedInMultiple: () => import_helpers.isOptionSelectedInMultiple,
30
+ sortOptions: () => import_sortOptions.sortOptions
31
+ });
32
+ module.exports = __toCommonJS(utils_exports);
33
+ var import_tagAggregation = require("./tagAggregation");
34
+ var import_filterOptions = require("./filterOptions");
35
+ var import_sortOptions = require("./sortOptions");
36
+ var import_helpers = require("./helpers");
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ calculateTagDisplay,
40
+ defaultFilterOption,
41
+ filterOptions,
42
+ findOptionByValue,
43
+ findOptionsByValues,
44
+ generateId,
45
+ isOptionSelected,
46
+ isOptionSelectedInMultiple,
47
+ sortOptions
48
+ });
@@ -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,41 @@
1
- //#region src/select/utils/sortOptions.ts
2
- /**
3
- * 排序选项列表
4
- * @template T 选项值的类型
5
- * @param options 原始选项列表
6
- * @param direction 排序方向('asc' 升序 | 'desc' 降序)
7
- * @returns 排序后的选项列表(新数组)
8
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/select/utils/sortOptions.ts
20
+ var sortOptions_exports = {};
21
+ __export(sortOptions_exports, {
22
+ sortOptions: () => sortOptions
23
+ });
24
+ module.exports = __toCommonJS(sortOptions_exports);
9
25
  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;
26
+ const sortedOptions = [...options];
27
+ sortedOptions.sort((a, b) => {
28
+ const labelA = a.label.toLowerCase();
29
+ const labelB = b.label.toLowerCase();
30
+ if (direction === "asc") {
31
+ return labelA.localeCompare(labelB);
32
+ } else {
33
+ return labelB.localeCompare(labelA);
34
+ }
35
+ });
36
+ return sortedOptions;
18
37
  }
19
- //#endregion
20
- exports.sortOptions = sortOptions;
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ sortOptions
41
+ });
@@ -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,43 @@
1
- //#region src/select/utils/tagAggregation.ts
2
- /**
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
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/select/utils/tagAggregation.ts
20
+ var tagAggregation_exports = {};
21
+ __export(tagAggregation_exports, {
22
+ calculateTagDisplay: () => calculateTagDisplay
23
+ });
24
+ module.exports = __toCommonJS(tagAggregation_exports);
21
25
  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
- };
26
+ const selectedOptions = selectedValues.map((v) => options.find((opt) => opt.value === v)).filter(Boolean);
27
+ if (selectedOptions.length <= maxTagCount) {
28
+ return {
29
+ visibleTags: selectedOptions,
30
+ hiddenTags: [],
31
+ hiddenCount: 0
32
+ };
33
+ }
34
+ return {
35
+ visibleTags: selectedOptions.slice(0, maxTagCount),
36
+ hiddenTags: selectedOptions.slice(maxTagCount),
37
+ hiddenCount: selectedOptions.length - maxTagCount
38
+ };
33
39
  }
34
- //#endregion
35
- exports.calculateTagDisplay = calculateTagDisplay;
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ calculateTagDisplay
43
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 文本输入 Hooks 导出
3
+ */
4
+ export { useTextInputState } from './useTextInputState';
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/text-input/hooks/index.ts
20
+ var hooks_exports = {};
21
+ __export(hooks_exports, {
22
+ useTextInputState: () => import_useTextInputState.useTextInputState
23
+ });
24
+ module.exports = __toCommonJS(hooks_exports);
25
+ var import_useTextInputState = require("./useTextInputState");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ useTextInputState
29
+ });
@@ -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,71 +1,81 @@
1
- require("../../_virtual/_rolldown/runtime.js");
2
- const require_validation = require("../utils/validation.js");
3
- let react = require("react");
4
- //#region src/text-input/hooks/useTextInputState.ts
5
- /**
6
- * 文本输入状态管理 Hook
7
- *
8
- * 管理组件的内部状态,包括:
9
- * - 值管理(受控/非受控模式)
10
- * - 校验状态管理
11
- * - 事件处理函数封装
12
- *
13
- * 支持受控和非受控两种模式:
14
- * - 受控模式:value 由外部传入,组件不维护内部状态
15
- * - 非受控模式:使用 defaultValue,组件维护内部状态
16
- *
17
- * @param props 组件 Props(包含校验配置)
18
- * @returns 文本输入状态对象
19
- *
20
- * @example
21
- * // 受控模式
22
- * const state = useTextInputState({ value: 'hello', onChange: (v) => console.log(v) });
23
- *
24
- * // 非受控模式
25
- * const state = useTextInputState({ defaultValue: 'hello' });
26
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/text-input/hooks/useTextInputState.ts
20
+ var useTextInputState_exports = {};
21
+ __export(useTextInputState_exports, {
22
+ useTextInputState: () => useTextInputState
23
+ });
24
+ module.exports = __toCommonJS(useTextInputState_exports);
25
+ var import_react = require("react");
26
+ var import_validation = require("../utils/validation");
27
27
  function useTextInputState(props) {
28
- const isControlled = props.value !== void 0;
29
- const [innerValue, setInnerValue] = (0, react.useState)(props.defaultValue || "");
30
- const [isTouched, setIsTouched] = (0, react.useState)(false);
31
- const [isValid, setIsValid] = (0, react.useState)(true);
32
- const [errors, setErrors] = (0, react.useState)([]);
33
- const currentValue = isControlled ? props.value : innerValue;
34
- return {
35
- value: currentValue,
36
- isTouched,
37
- isValid,
38
- errors,
39
- handleChange: (0, react.useCallback)((newValue) => {
40
- var _props$onChange;
41
- if (!isControlled) setInnerValue(newValue);
42
- if (props.validateTrigger === "onChange" || props.validateTrigger === "both") {
43
- var _props$onValidate;
44
- const validation = require_validation.validateValue(newValue, props);
45
- setIsValid(validation.isValid);
46
- setErrors(validation.errors);
47
- (_props$onValidate = props.onValidate) === null || _props$onValidate === void 0 || _props$onValidate.call(props, validation.isValid, validation.errors);
48
- }
49
- (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
50
- }, [isControlled, props]),
51
- handleBlur: (0, react.useCallback)(() => {
52
- var _props$onBlur;
53
- setIsTouched(true);
54
- if (props.validateTrigger !== "onChange") {
55
- var _props$onValidate2;
56
- const validation = require_validation.validateValue(currentValue || "", props);
57
- setIsValid(validation.isValid);
58
- setErrors(validation.errors);
59
- (_props$onValidate2 = props.onValidate) === null || _props$onValidate2 === void 0 || _props$onValidate2.call(props, validation.isValid, validation.errors);
60
- }
61
- (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue || "");
62
- }, [currentValue, props]),
63
- handleFocus: (0, react.useCallback)(() => {
64
- var _props$onFocus;
65
- setIsTouched(true);
66
- (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 || _props$onFocus.call(props);
67
- }, [props])
68
- };
28
+ const isControlled = props.value !== void 0;
29
+ const [innerValue, setInnerValue] = (0, import_react.useState)(props.defaultValue || "");
30
+ const [isTouched, setIsTouched] = (0, import_react.useState)(false);
31
+ const [isValid, setIsValid] = (0, import_react.useState)(true);
32
+ const [errors, setErrors] = (0, import_react.useState)([]);
33
+ const currentValue = isControlled ? props.value : innerValue;
34
+ const handleChange = (0, import_react.useCallback)(
35
+ (newValue) => {
36
+ var _a, _b;
37
+ if (!isControlled) {
38
+ setInnerValue(newValue);
39
+ }
40
+ const shouldValidate = props.validateTrigger === "onChange" || props.validateTrigger === "both";
41
+ if (shouldValidate) {
42
+ const validation = (0, import_validation.validateValue)(newValue, props);
43
+ setIsValid(validation.isValid);
44
+ setErrors(validation.errors);
45
+ (_a = props.onValidate) == null ? void 0 : _a.call(props, validation.isValid, validation.errors);
46
+ }
47
+ (_b = props.onChange) == null ? void 0 : _b.call(props, newValue);
48
+ },
49
+ [isControlled, props]
50
+ );
51
+ const handleBlur = (0, import_react.useCallback)(() => {
52
+ var _a, _b;
53
+ setIsTouched(true);
54
+ const shouldValidate = props.validateTrigger !== "onChange";
55
+ if (shouldValidate) {
56
+ const validation = (0, import_validation.validateValue)(currentValue || "", props);
57
+ setIsValid(validation.isValid);
58
+ setErrors(validation.errors);
59
+ (_a = props.onValidate) == null ? void 0 : _a.call(props, validation.isValid, validation.errors);
60
+ }
61
+ (_b = props.onBlur) == null ? void 0 : _b.call(props, currentValue || "");
62
+ }, [currentValue, props]);
63
+ const handleFocus = (0, import_react.useCallback)(() => {
64
+ var _a;
65
+ setIsTouched(true);
66
+ (_a = props.onFocus) == null ? void 0 : _a.call(props);
67
+ }, [props]);
68
+ return {
69
+ value: currentValue,
70
+ isTouched,
71
+ isValid,
72
+ errors,
73
+ handleChange,
74
+ handleBlur,
75
+ handleFocus
76
+ };
69
77
  }
70
- //#endregion
71
- exports.useTextInputState = useTextInputState;
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ useTextInputState
81
+ });
@@ -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,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/text-input/index.ts
20
+ var text_input_exports = {};
21
+ __export(text_input_exports, {
22
+ getDisplayState: () => import_utils.getDisplayState,
23
+ useTextInputState: () => import_hooks.useTextInputState,
24
+ validateTextValue: () => import_utils2.validateValue
25
+ });
26
+ module.exports = __toCommonJS(text_input_exports);
27
+ var import_hooks = require("./hooks");
28
+ var import_utils = require("./utils");
29
+ var import_utils2 = require("./utils");
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ getDisplayState,
33
+ useTextInputState,
34
+ validateTextValue
35
+ });