@pisell/utils 3.0.5 → 3.0.6

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 (158) 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 +76 -1
  8. package/es/arrayUtils.js +103 -24
  9. package/es/common/stateHelper.d.ts +22 -0
  10. package/es/common/stateHelper.js +23 -0
  11. package/es/common/types.d.ts +31 -0
  12. package/es/componentStorage.d.ts +38 -0
  13. package/es/componentStorage.js +106 -0
  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 -112
  24. package/es/image.d.ts +13 -10
  25. package/es/image.js +48 -60
  26. package/es/index.d.ts +39 -18
  27. package/es/index.js +40 -29
  28. package/es/jsBridge/index.d.ts +14 -106
  29. package/es/jsBridge/index.js +57 -40
  30. package/es/jsBridge/regDeviceApi.js +87 -126
  31. package/es/jsBridge/types.d.ts +129 -0
  32. package/es/locales.d.ts +11 -11
  33. package/es/locales.js +79 -69
  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 -71
  38. package/es/number-input/hooks/useNumberInputState.d.ts +29 -0
  39. package/es/number-input/hooks/useNumberInputState.js +72 -0
  40. package/es/number-input/types.d.ts +96 -0
  41. package/es/number-input/utils/formatter.d.ts +56 -0
  42. package/es/number-input/utils/formatter.js +56 -0
  43. package/es/number-input/utils/validation.d.ts +32 -0
  44. package/es/number-input/utils/validation.js +52 -0
  45. package/es/otherUtils.d.ts +51 -0
  46. package/es/otherUtils.js +71 -129
  47. package/es/platform.d.ts +12 -9
  48. package/es/platform.js +61 -85
  49. package/es/select/hooks/useDebouncedSearch.d.ts +23 -0
  50. package/es/select/hooks/useDebouncedSearch.js +41 -0
  51. package/es/select/hooks/useSelectState.d.ts +19 -0
  52. package/es/select/hooks/useSelectState.js +60 -0
  53. package/es/select/index.d.ts +7 -0
  54. package/es/select/types.d.ts +256 -0
  55. package/es/select/utils/filterOptions.d.ts +23 -0
  56. package/es/select/utils/filterOptions.js +29 -0
  57. package/es/select/utils/helpers.d.ts +43 -0
  58. package/es/select/utils/helpers.js +51 -0
  59. package/es/select/utils/index.d.ts +4 -0
  60. package/es/select/utils/sortOptions.d.ts +13 -0
  61. package/es/select/utils/sortOptions.js +20 -0
  62. package/es/select/utils/tagAggregation.d.ts +25 -0
  63. package/es/select/utils/tagAggregation.js +35 -0
  64. package/es/text-input/hooks/useTextInputState.d.ts +28 -0
  65. package/es/text-input/hooks/useTextInputState.js +70 -0
  66. package/es/text-input/types.d.ts +56 -0
  67. package/es/text-input/utils/validation.d.ts +28 -0
  68. package/es/text-input/utils/validation.js +51 -0
  69. package/es/typeUtils.d.ts +11 -8
  70. package/es/typeUtils.js +61 -84
  71. package/es/walletValidity.d.ts +57 -0
  72. package/es/walletValidity.js +404 -460
  73. package/es/weighing.d.ts +65 -0
  74. package/es/weighing.js +96 -0
  75. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  76. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  77. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  78. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  79. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  80. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
  81. package/lib/_virtual/_rolldown/runtime.js +23 -0
  82. package/lib/arrayUtils.d.ts +76 -1
  83. package/lib/arrayUtils.js +102 -37
  84. package/lib/common/stateHelper.d.ts +22 -0
  85. package/lib/common/stateHelper.js +23 -0
  86. package/lib/common/types.d.ts +31 -0
  87. package/lib/componentStorage.d.ts +38 -0
  88. package/lib/componentStorage.js +114 -0
  89. package/lib/constants/index.js +7 -36
  90. package/lib/date.d.ts +6 -3
  91. package/lib/date.js +43 -65
  92. package/lib/document.d.ts +6 -3
  93. package/lib/document.js +46 -62
  94. package/lib/escPosPrinter/EscPosPrinter.js +327 -403
  95. package/lib/escPosPrinter/index.d.ts +9 -9
  96. package/lib/escPosPrinter/index.js +38 -84
  97. package/lib/format.d.ts +12 -11
  98. package/lib/format.js +91 -93
  99. package/lib/image.d.ts +13 -10
  100. package/lib/image.js +48 -74
  101. package/lib/index.d.ts +39 -18
  102. package/lib/index.js +137 -68
  103. package/lib/jsBridge/index.d.ts +14 -106
  104. package/lib/jsBridge/index.js +60 -60
  105. package/lib/jsBridge/regDeviceApi.js +86 -133
  106. package/lib/jsBridge/types.d.ts +129 -0
  107. package/lib/locales.d.ts +11 -11
  108. package/lib/locales.js +79 -63
  109. package/lib/log.d.ts +11 -6
  110. package/lib/log.js +37 -61
  111. package/lib/miniRedux.d.ts +20 -13
  112. package/lib/miniRedux.js +43 -91
  113. package/lib/number-input/hooks/useNumberInputState.d.ts +29 -0
  114. package/lib/number-input/hooks/useNumberInputState.js +73 -0
  115. package/lib/number-input/types.d.ts +96 -0
  116. package/lib/number-input/utils/formatter.d.ts +56 -0
  117. package/lib/number-input/utils/formatter.js +58 -0
  118. package/lib/number-input/utils/validation.d.ts +32 -0
  119. package/lib/number-input/utils/validation.js +52 -0
  120. package/lib/otherUtils.d.ts +51 -0
  121. package/lib/otherUtils.js +86 -98
  122. package/lib/platform.d.ts +12 -9
  123. package/lib/platform.js +68 -123
  124. package/lib/select/hooks/useDebouncedSearch.d.ts +23 -0
  125. package/lib/select/hooks/useDebouncedSearch.js +42 -0
  126. package/lib/select/hooks/useSelectState.d.ts +19 -0
  127. package/lib/select/hooks/useSelectState.js +62 -0
  128. package/lib/select/index.d.ts +7 -0
  129. package/lib/select/types.d.ts +256 -0
  130. package/lib/select/utils/filterOptions.d.ts +23 -0
  131. package/lib/select/utils/filterOptions.js +30 -0
  132. package/lib/select/utils/helpers.d.ts +43 -0
  133. package/lib/select/utils/helpers.js +55 -0
  134. package/lib/select/utils/index.d.ts +4 -0
  135. package/lib/select/utils/sortOptions.d.ts +13 -0
  136. package/lib/select/utils/sortOptions.js +20 -0
  137. package/lib/select/utils/tagAggregation.d.ts +25 -0
  138. package/lib/select/utils/tagAggregation.js +35 -0
  139. package/lib/text-input/hooks/useTextInputState.d.ts +28 -0
  140. package/lib/text-input/hooks/useTextInputState.js +71 -0
  141. package/lib/text-input/types.d.ts +56 -0
  142. package/lib/text-input/utils/validation.d.ts +28 -0
  143. package/lib/text-input/utils/validation.js +51 -0
  144. package/lib/typeUtils.d.ts +11 -8
  145. package/lib/typeUtils.js +68 -73
  146. package/lib/walletValidity.d.ts +57 -0
  147. package/lib/walletValidity.js +420 -323
  148. package/lib/weighing.d.ts +65 -0
  149. package/lib/weighing.js +114 -0
  150. package/package.json +1 -1
  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/lib/firebase/config/index.d.ts +0 -13
  156. package/lib/firebase/config/index.js +0 -79
  157. package/lib/firebase/index.d.ts +0 -28
  158. package/lib/firebase/index.js +0 -180
@@ -0,0 +1,256 @@
1
+ import { DisplayState } from "../common/types.js";
2
+ import React from "react";
3
+
4
+ //#region src/select/types.d.ts
5
+ /**
6
+ * 选项基础类型
7
+ * @template T 选项值的类型,默认为 string | number
8
+ */
9
+ interface SelectOption<T = string | number> {
10
+ /**
11
+ * 选项值(唯一标识)
12
+ */
13
+ value: T;
14
+ /**
15
+ * 选项显示文本
16
+ */
17
+ label: string;
18
+ /**
19
+ * 是否禁用该选项
20
+ * @default false
21
+ */
22
+ disabled?: boolean;
23
+ /**
24
+ * 选项图标(可选)
25
+ */
26
+ icon?: React.ReactNode;
27
+ /**
28
+ * 标签背景色(多选时用于自定义标签颜色)
29
+ * @example '#61dafb'
30
+ */
31
+ color?: string;
32
+ }
33
+ /**
34
+ * 选项过滤函数类型
35
+ * @template T 选项值的类型
36
+ * @param input 用户输入的搜索文本
37
+ * @param option 当前选项对象
38
+ * @returns 是否保留该选项
39
+ */
40
+ type FilterOptionFunc<T = string | number> = (input: string, option: SelectOption<T>) => boolean;
41
+ /**
42
+ * 排序方向
43
+ */
44
+ type SortDirection = 'asc' | 'desc';
45
+ /**
46
+ * Select 状态 Hook 返回值(单选)
47
+ * @template T 值的类型
48
+ */
49
+ interface SelectState<T = string | number> {
50
+ /**
51
+ * 当前选中值
52
+ */
53
+ value: T | null | undefined;
54
+ /**
55
+ * 设置选中值
56
+ */
57
+ setValue: (value: T | null) => void;
58
+ /**
59
+ * 清空选中值
60
+ */
61
+ clearValue: () => void;
62
+ }
63
+ /**
64
+ * Multiple Select 状态 Hook 返回值(多选)
65
+ * @template T 值的类型
66
+ */
67
+ interface MultipleSelectState<T = string | number> {
68
+ /**
69
+ * 当前选中值数组
70
+ */
71
+ value: T[];
72
+ /**
73
+ * 设置选中值数组
74
+ */
75
+ setValue: (value: T[]) => void;
76
+ /**
77
+ * 添加一个选中值
78
+ */
79
+ addValue: (value: T) => void;
80
+ /**
81
+ * 移除一个选中值
82
+ */
83
+ removeValue: (value: T) => void;
84
+ /**
85
+ * 清空所有选中值
86
+ */
87
+ clearValue: () => void;
88
+ }
89
+ /**
90
+ * 标签显示信息(多选专用)
91
+ * @template T 选项值的类型
92
+ */
93
+ interface TagDisplayInfo<T = string | number> {
94
+ /**
95
+ * 可见的标签列表
96
+ */
97
+ visibleTags: SelectOption<T>[];
98
+ /**
99
+ * 隐藏的标签列表
100
+ */
101
+ hiddenTags: SelectOption<T>[];
102
+ /**
103
+ * 隐藏的标签数量
104
+ */
105
+ hiddenCount: number;
106
+ }
107
+ /**
108
+ * useSelectState Hook 的配置选项(单选)
109
+ * @template T 值的类型
110
+ */
111
+ interface UseSelectStateOptions<T = string | number> {
112
+ /**
113
+ * 受控模式:当前值
114
+ */
115
+ value?: T | null;
116
+ /**
117
+ * 非受控模式:默认值
118
+ */
119
+ defaultValue?: T;
120
+ /**
121
+ * 值变化回调
122
+ */
123
+ onChange?: (value: T | null, option: SelectOption<T> | null) => void;
124
+ /**
125
+ * 模式(用于类型区分)
126
+ */
127
+ mode: 'single';
128
+ }
129
+ /**
130
+ * useMultipleSelectState Hook 的配置选项(多选)
131
+ * @template T 值的类型
132
+ */
133
+ interface UseMultipleSelectStateOptions<T = string | number> {
134
+ /**
135
+ * 受控模式:当前值数组
136
+ */
137
+ value?: T[];
138
+ /**
139
+ * 非受控模式:默认值数组
140
+ */
141
+ defaultValue?: T[];
142
+ /**
143
+ * 值变化回调
144
+ */
145
+ onChange?: (value: T[], options: SelectOption<T>[]) => void;
146
+ /**
147
+ * 模式(用于类型区分)
148
+ */
149
+ mode: 'multiple';
150
+ }
151
+ /**
152
+ * 基础 Select Props(公共属性)
153
+ * @template T 值的类型
154
+ */
155
+ interface BaseSelectProps<T = string | number> {
156
+ /**
157
+ * 选项列表(必填)
158
+ */
159
+ options: SelectOption<T>[];
160
+ /**
161
+ * 占位符文本
162
+ * @default '请选择'
163
+ */
164
+ placeholder?: string;
165
+ /**
166
+ * 是否显示搜索框
167
+ * @default false
168
+ */
169
+ showSearch?: boolean;
170
+ /**
171
+ * 是否显示清空按钮
172
+ * @default false
173
+ */
174
+ allowClear?: boolean;
175
+ /**
176
+ * 是否禁用
177
+ * @default false
178
+ */
179
+ disabled?: boolean;
180
+ /**
181
+ * 是否只读
182
+ * @default false
183
+ */
184
+ readOnly?: boolean;
185
+ /**
186
+ * 尺寸
187
+ * @default 'middle'
188
+ */
189
+ size?: 'small' | 'middle' | 'large';
190
+ /**
191
+ * 自定义类名
192
+ */
193
+ className?: string;
194
+ /**
195
+ * 自定义样式
196
+ */
197
+ style?: React.CSSProperties;
198
+ /**
199
+ * 标签文本
200
+ */
201
+ label?: string;
202
+ /**
203
+ * 辅助提示文本
204
+ */
205
+ helperText?: string;
206
+ /**
207
+ * 是否必填
208
+ * @default false
209
+ */
210
+ required?: boolean;
211
+ /**
212
+ * 是否显示错误状态
213
+ * @default false
214
+ */
215
+ error?: boolean;
216
+ /**
217
+ * 错误提示文本
218
+ */
219
+ errorText?: string;
220
+ /**
221
+ * 是否启用过滤
222
+ * @default false
223
+ */
224
+ filterable?: boolean;
225
+ /**
226
+ * 自定义过滤函数
227
+ */
228
+ filterOption?: FilterOptionFunc<T>;
229
+ /**
230
+ * 是否启用排序
231
+ * @default false
232
+ */
233
+ sortable?: boolean;
234
+ /**
235
+ * 排序方向
236
+ */
237
+ sortDirection?: SortDirection;
238
+ /**
239
+ * 搜索输入回调
240
+ */
241
+ onSearch?: (value: string) => void;
242
+ /**
243
+ * 获得焦点回调
244
+ */
245
+ onFocus?: (event: React.FocusEvent) => void;
246
+ /**
247
+ * 失去焦点回调
248
+ */
249
+ onBlur?: (event: React.FocusEvent) => void;
250
+ /**
251
+ * 下拉框显隐回调
252
+ */
253
+ onDropdownVisibleChange?: (visible: boolean) => void;
254
+ }
255
+ //#endregion
256
+ export { BaseSelectProps, FilterOptionFunc, MultipleSelectState, SelectOption, SelectState, SortDirection, TagDisplayInfo, UseMultipleSelectStateOptions, UseSelectStateOptions };
@@ -0,0 +1,23 @@
1
+ import { FilterOptionFunc, SelectOption } from "../types.js";
2
+
3
+ //#region src/select/utils/filterOptions.d.ts
4
+ /**
5
+ * 默认的选项过滤函数
6
+ * 根据 label 进行模糊匹配(不区分大小写)
7
+ * @template T 选项值的类型
8
+ * @param input 搜索输入文本
9
+ * @param option 选项对象
10
+ * @returns 是否保留该选项
11
+ */
12
+ declare function defaultFilterOption<T = string | number>(input: string, option: SelectOption<T>): boolean;
13
+ /**
14
+ * 过滤选项列表
15
+ * @template T 选项值的类型
16
+ * @param options 原始选项列表
17
+ * @param searchText 搜索文本
18
+ * @param filterFunc 自定义过滤函数(可选)
19
+ * @returns 过滤后的选项列表
20
+ */
21
+ declare function filterOptions<T = string | number>(options: SelectOption<T>[], searchText: string, filterFunc?: FilterOptionFunc<T>): SelectOption<T>[];
22
+ //#endregion
23
+ export { defaultFilterOption, filterOptions };
@@ -0,0 +1,30 @@
1
+ //#region src/select/utils/filterOptions.ts
2
+ /**
3
+ * 默认的选项过滤函数
4
+ * 根据 label 进行模糊匹配(不区分大小写)
5
+ * @template T 选项值的类型
6
+ * @param input 搜索输入文本
7
+ * @param option 选项对象
8
+ * @returns 是否保留该选项
9
+ */
10
+ function defaultFilterOption(input, option) {
11
+ if (!input) return true;
12
+ const searchText = input.toLowerCase();
13
+ return option.label.toLowerCase().includes(searchText);
14
+ }
15
+ /**
16
+ * 过滤选项列表
17
+ * @template T 选项值的类型
18
+ * @param options 原始选项列表
19
+ * @param searchText 搜索文本
20
+ * @param filterFunc 自定义过滤函数(可选)
21
+ * @returns 过滤后的选项列表
22
+ */
23
+ function filterOptions(options, searchText, filterFunc) {
24
+ if (!searchText) return options;
25
+ const filterFn = filterFunc || defaultFilterOption;
26
+ return options.filter((opt) => filterFn(searchText, opt));
27
+ }
28
+ //#endregion
29
+ exports.defaultFilterOption = defaultFilterOption;
30
+ exports.filterOptions = filterOptions;
@@ -0,0 +1,43 @@
1
+ import { SelectOption } from "../types.js";
2
+
3
+ //#region src/select/utils/helpers.d.ts
4
+ /**
5
+ * 根据值查找选项对象
6
+ * @template T 选项值的类型
7
+ * @param value 选项值
8
+ * @param options 选项列表
9
+ * @returns 找到的选项对象,如果没找到返回 undefined
10
+ */
11
+ declare function findOptionByValue<T = string | number>(value: T, options: SelectOption<T>[]): SelectOption<T> | undefined;
12
+ /**
13
+ * 根据值数组查找选项对象数组
14
+ * @template T 选项值的类型
15
+ * @param values 选项值数组
16
+ * @param options 选项列表
17
+ * @returns 找到的选项对象数组
18
+ */
19
+ declare function findOptionsByValues<T = string | number>(values: T[], options: SelectOption<T>[]): SelectOption<T>[];
20
+ /**
21
+ * 判断选项是否被选中(单选)
22
+ * @template T 选项值的类型
23
+ * @param optionValue 选项值
24
+ * @param selectedValue 当前选中值
25
+ * @returns 是否选中
26
+ */
27
+ declare function isOptionSelected<T = string | number>(optionValue: T, selectedValue: T | null | undefined): boolean;
28
+ /**
29
+ * 判断选项是否被选中(多选)
30
+ * @template T 选项值的类型
31
+ * @param optionValue 选项值
32
+ * @param selectedValues 当前选中值数组
33
+ * @returns 是否选中
34
+ */
35
+ declare function isOptionSelectedInMultiple<T = string | number>(optionValue: T, selectedValues: T[]): boolean;
36
+ /**
37
+ * 生成唯一 ID
38
+ * @param prefix ID 前缀
39
+ * @returns 唯一 ID
40
+ */
41
+ declare function generateId(prefix?: string): string;
42
+ //#endregion
43
+ export { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple };
@@ -0,0 +1,55 @@
1
+ //#region src/select/utils/helpers.ts
2
+ /**
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
+ }
12
+ /**
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);
21
+ }
22
+ /**
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;
31
+ }
32
+ /**
33
+ * 判断选项是否被选中(多选)
34
+ * @template T 选项值的类型
35
+ * @param optionValue 选项值
36
+ * @param selectedValues 当前选中值数组
37
+ * @returns 是否选中
38
+ */
39
+ function isOptionSelectedInMultiple(optionValue, selectedValues) {
40
+ return selectedValues.includes(optionValue);
41
+ }
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)}`;
49
+ }
50
+ //#endregion
51
+ exports.findOptionByValue = findOptionByValue;
52
+ exports.findOptionsByValues = findOptionsByValues;
53
+ exports.generateId = generateId;
54
+ exports.isOptionSelected = isOptionSelected;
55
+ exports.isOptionSelectedInMultiple = isOptionSelectedInMultiple;
@@ -0,0 +1,4 @@
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";
@@ -0,0 +1,13 @@
1
+ import { SelectOption, SortDirection } from "../types.js";
2
+
3
+ //#region src/select/utils/sortOptions.d.ts
4
+ /**
5
+ * 排序选项列表
6
+ * @template T 选项值的类型
7
+ * @param options 原始选项列表
8
+ * @param direction 排序方向('asc' 升序 | 'desc' 降序)
9
+ * @returns 排序后的选项列表(新数组)
10
+ */
11
+ declare function sortOptions<T = string | number>(options: SelectOption<T>[], direction?: SortDirection): SelectOption<T>[];
12
+ //#endregion
13
+ export { sortOptions };
@@ -0,0 +1,20 @@
1
+ //#region src/select/utils/sortOptions.ts
2
+ /**
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
+ exports.sortOptions = sortOptions;
@@ -0,0 +1,25 @@
1
+ import { SelectOption, TagDisplayInfo } from "../types.js";
2
+
3
+ //#region src/select/utils/tagAggregation.d.ts
4
+ /**
5
+ * 计算需要显示的标签和聚合信息
6
+ * @template T 选项值的类型
7
+ * @param selectedValues 当前选中的值数组
8
+ * @param options 所有选项列表
9
+ * @param maxTagCount 最多显示的标签数量
10
+ * @returns 标签显示信息
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const tagInfo = calculateTagDisplay(['a', 'b', 'c', 'd'], options, 2);
15
+ * // 返回:
16
+ * // {
17
+ * // visibleTags: [option_a, option_b],
18
+ * // hiddenTags: [option_c, option_d],
19
+ * // hiddenCount: 2
20
+ * // }
21
+ * ```
22
+ */
23
+ declare function calculateTagDisplay<T = string | number>(selectedValues: T[], options: SelectOption<T>[], maxTagCount: number): TagDisplayInfo<T>;
24
+ //#endregion
25
+ export { calculateTagDisplay };
@@ -0,0 +1,35 @@
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
+ */
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
+ exports.calculateTagDisplay = calculateTagDisplay;
@@ -0,0 +1,28 @@
1
+ import { BaseTextInputProps, TextInputState } from "../types.js";
2
+
3
+ //#region src/text-input/hooks/useTextInputState.d.ts
4
+ /**
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
+ declare function useTextInputState(props: BaseTextInputProps): TextInputState;
27
+ //#endregion
28
+ export { useTextInputState };
@@ -0,0 +1,71 @@
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
+ */
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
+ };
69
+ }
70
+ //#endregion
71
+ exports.useTextInputState = useTextInputState;
@@ -0,0 +1,56 @@
1
+ import { DisplayState, ValidationResult } from "../common/types.js";
2
+
3
+ //#region src/text-input/types.d.ts
4
+ /**
5
+ * 文本输入状态 Hook 返回值
6
+ */
7
+ interface TextInputState {
8
+ /**
9
+ * 当前值
10
+ */
11
+ value: string | undefined;
12
+ /**
13
+ * 是否已被触摸(交互过)
14
+ */
15
+ isTouched: boolean;
16
+ /**
17
+ * 是否校验通过
18
+ */
19
+ isValid: boolean;
20
+ /**
21
+ * 错误信息数组
22
+ */
23
+ errors: string[];
24
+ /**
25
+ * 值变更处理函数
26
+ */
27
+ handleChange: (value: string) => void;
28
+ /**
29
+ * 失焦处理函数
30
+ */
31
+ handleBlur: () => void;
32
+ /**
33
+ * 聚焦处理函数
34
+ */
35
+ handleFocus: () => void;
36
+ }
37
+ /**
38
+ * 基础文本输入 Props(供校验和状态管理使用)
39
+ */
40
+ interface BaseTextInputProps {
41
+ value?: string;
42
+ defaultValue?: string;
43
+ required?: boolean;
44
+ minLength?: number;
45
+ maxLength?: number;
46
+ pattern?: string | RegExp;
47
+ validator?: (value: string) => boolean | string;
48
+ validateTrigger?: 'onChange' | 'onBlur' | 'both';
49
+ errorMessage?: string;
50
+ onChange?: (value: string) => void;
51
+ onBlur?: (value: string) => void;
52
+ onFocus?: () => void;
53
+ onValidate?: (isValid: boolean, errors: string[]) => void;
54
+ }
55
+ //#endregion
56
+ export { BaseTextInputProps, TextInputState };
@@ -0,0 +1,28 @@
1
+ import { ValidationResult } from "../../common/types.js";
2
+ import { BaseTextInputProps } from "../types.js";
3
+
4
+ //#region src/text-input/utils/validation.d.ts
5
+ /**
6
+ * 校验文本输入值
7
+ *
8
+ * 按照优先级执行校验规则:
9
+ * 1. 必填校验(required)
10
+ * 2. 最小长度校验(minLength)
11
+ * 3. 最大长度校验(maxLength)
12
+ * 4. 正则校验(pattern)
13
+ * 5. 自定义校验函数(validator)
14
+ *
15
+ * @param value 待校验的值
16
+ * @param props 校验配置
17
+ * @returns 校验结果对象,包含 isValid 和 errors
18
+ *
19
+ * @example
20
+ * validateValue('hello', { required: true, minLength: 3 })
21
+ * // { isValid: true, errors: [] }
22
+ *
23
+ * validateValue('', { required: true })
24
+ * // { isValid: false, errors: ['此字段为必填项'] }
25
+ */
26
+ declare function validateValue(value: string, props: BaseTextInputProps): ValidationResult;
27
+ //#endregion
28
+ export { validateValue };