@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.
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
- package/es/arrayUtils.d.ts +4 -1
- package/es/arrayUtils.js +15 -24
- package/es/common/stateHelper.d.ts +6 -2
- package/es/common/stateHelper.js +22 -24
- package/es/common/types.d.ts +13 -10
- package/es/componentStorage.d.ts +27 -25
- package/es/componentStorage.js +94 -130
- package/es/constants/index.js +7 -9
- package/es/date.d.ts +6 -3
- package/es/date.js +36 -53
- package/es/document.d.ts +6 -3
- package/es/document.js +43 -67
- package/es/escPosPrinter/EscPosPrinter.js +353 -490
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +37 -52
- package/es/format.d.ts +12 -11
- package/es/format.js +90 -116
- package/es/image.d.ts +13 -10
- package/es/image.js +48 -60
- package/es/index.d.ts +38 -23
- package/es/index.js +39 -34
- package/es/jsBridge/index.d.ts +8 -4
- package/es/jsBridge/index.js +57 -56
- package/es/jsBridge/regDeviceApi.js +107 -149
- package/es/jsBridge/types.d.ts +95 -115
- package/es/locales.d.ts +11 -8
- package/es/locales.js +77 -96
- package/es/log.d.ts +11 -6
- package/es/log.js +37 -59
- package/es/miniRedux.d.ts +20 -13
- package/es/miniRedux.js +42 -78
- package/es/number-input/hooks/useNumberInputState.d.ts +6 -2
- package/es/number-input/hooks/useNumberInputState.js +71 -128
- package/es/number-input/types.d.ts +88 -88
- package/es/number-input/utils/formatter.d.ts +13 -10
- package/es/number-input/utils/formatter.js +51 -77
- package/es/number-input/utils/validation.d.ts +7 -2
- package/es/number-input/utils/validation.js +51 -66
- package/es/otherUtils.d.ts +12 -9
- package/es/otherUtils.js +71 -129
- package/es/platform.d.ts +17 -9
- package/es/platform.js +78 -85
- package/es/select/hooks/useDebouncedSearch.d.ts +4 -1
- package/es/select/hooks/useDebouncedSearch.js +39 -53
- package/es/select/hooks/useSelectState.d.ts +7 -7
- package/es/select/hooks/useSelectState.js +56 -113
- package/es/select/index.d.ts +7 -8
- package/es/select/types.d.ts +211 -211
- package/es/select/utils/filterOptions.d.ts +7 -6
- package/es/select/utils/filterOptions.js +26 -31
- package/es/select/utils/helpers.d.ts +10 -9
- package/es/select/utils/helpers.js +42 -52
- package/es/select/utils/index.d.ts +4 -7
- package/es/select/utils/sortOptions.d.ts +6 -5
- package/es/select/utils/sortOptions.js +19 -31
- package/es/select/utils/tagAggregation.d.ts +6 -6
- package/es/select/utils/tagAggregation.js +34 -47
- package/es/text-input/hooks/useTextInputState.d.ts +6 -2
- package/es/text-input/hooks/useTextInputState.js +69 -126
- package/es/text-input/types.d.ts +48 -48
- package/es/text-input/utils/validation.d.ts +7 -2
- package/es/text-input/utils/validation.js +50 -70
- package/es/typeUtils.d.ts +11 -8
- package/es/typeUtils.js +61 -84
- package/es/walletValidity.d.ts +36 -34
- package/es/walletValidity.js +332 -456
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
- package/lib/_virtual/_rolldown/runtime.js +23 -0
- package/lib/arrayUtils.d.ts +4 -1
- package/lib/arrayUtils.js +14 -39
- package/lib/common/stateHelper.d.ts +6 -2
- package/lib/common/stateHelper.js +21 -32
- package/lib/common/types.d.ts +13 -10
- package/lib/componentStorage.d.ts +27 -25
- package/lib/componentStorage.js +96 -126
- package/lib/constants/index.js +7 -36
- package/lib/date.d.ts +6 -3
- package/lib/date.js +43 -65
- package/lib/document.d.ts +6 -3
- package/lib/document.js +46 -62
- package/lib/escPosPrinter/EscPosPrinter.js +327 -403
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +38 -84
- package/lib/format.d.ts +12 -11
- package/lib/format.js +91 -99
- package/lib/image.d.ts +13 -10
- package/lib/image.js +48 -74
- package/lib/index.d.ts +38 -23
- package/lib/index.js +115 -78
- package/lib/jsBridge/index.d.ts +8 -4
- package/lib/jsBridge/index.js +58 -77
- package/lib/jsBridge/regDeviceApi.js +106 -153
- package/lib/jsBridge/types.d.ts +95 -115
- package/lib/locales.d.ts +11 -8
- package/lib/locales.js +79 -90
- package/lib/log.d.ts +11 -6
- package/lib/log.js +37 -61
- package/lib/miniRedux.d.ts +20 -13
- package/lib/miniRedux.js +43 -92
- package/lib/number-input/hooks/useNumberInputState.d.ts +6 -2
- package/lib/number-input/hooks/useNumberInputState.js +71 -81
- package/lib/number-input/types.d.ts +88 -88
- package/lib/number-input/utils/formatter.d.ts +13 -10
- package/lib/number-input/utils/formatter.js +52 -49
- package/lib/number-input/utils/validation.d.ts +7 -2
- package/lib/number-input/utils/validation.js +50 -52
- package/lib/otherUtils.d.ts +12 -9
- package/lib/otherUtils.js +86 -98
- package/lib/platform.d.ts +17 -9
- package/lib/platform.js +85 -122
- package/lib/select/hooks/useDebouncedSearch.d.ts +4 -1
- package/lib/select/hooks/useDebouncedSearch.js +40 -41
- package/lib/select/hooks/useSelectState.d.ts +7 -7
- package/lib/select/hooks/useSelectState.js +58 -93
- package/lib/select/index.d.ts +7 -8
- package/lib/select/types.d.ts +211 -211
- package/lib/select/utils/filterOptions.d.ts +7 -6
- package/lib/select/utils/filterOptions.js +26 -37
- package/lib/select/utils/helpers.d.ts +10 -9
- package/lib/select/utils/helpers.js +45 -41
- package/lib/select/utils/index.d.ts +4 -7
- package/lib/select/utils/sortOptions.d.ts +6 -5
- package/lib/select/utils/sortOptions.js +18 -39
- package/lib/select/utils/tagAggregation.d.ts +6 -6
- package/lib/select/utils/tagAggregation.js +33 -41
- package/lib/text-input/hooks/useTextInputState.d.ts +6 -2
- package/lib/text-input/hooks/useTextInputState.js +69 -79
- package/lib/text-input/types.d.ts +48 -48
- package/lib/text-input/utils/validation.d.ts +7 -2
- package/lib/text-input/utils/validation.js +49 -58
- package/lib/typeUtils.d.ts +11 -8
- package/lib/typeUtils.js +68 -73
- package/lib/walletValidity.d.ts +36 -34
- package/lib/walletValidity.js +345 -317
- package/package.json +1 -2
- package/es/common/index.d.ts +0 -5
- package/es/common/index.js +0 -5
- package/es/common/types.js +0 -1
- package/es/constants/index.d.ts +0 -7
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/config/index.js +0 -54
- package/es/firebase/index.d.ts +0 -28
- package/es/firebase/index.js +0 -232
- package/es/jsBridge/types.js +0 -1
- package/es/number-input/hooks/index.d.ts +0 -4
- package/es/number-input/hooks/index.js +0 -5
- package/es/number-input/index.d.ts +0 -14
- package/es/number-input/index.js +0 -21
- package/es/number-input/types.js +0 -1
- package/es/number-input/utils/index.d.ts +0 -7
- package/es/number-input/utils/index.js +0 -8
- package/es/select/hooks/index.d.ts +0 -5
- package/es/select/hooks/index.js +0 -6
- package/es/select/index.js +0 -13
- package/es/select/types.js +0 -1
- package/es/select/utils/index.js +0 -8
- package/es/text-input/hooks/index.d.ts +0 -4
- package/es/text-input/hooks/index.js +0 -5
- package/es/text-input/index.d.ts +0 -14
- package/es/text-input/index.js +0 -20
- package/es/text-input/types.js +0 -1
- package/es/text-input/utils/index.d.ts +0 -5
- package/es/text-input/utils/index.js +0 -7
- package/lib/common/index.d.ts +0 -5
- package/lib/common/index.js +0 -29
- package/lib/common/types.js +0 -17
- package/lib/constants/index.d.ts +0 -7
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/config/index.js +0 -79
- package/lib/firebase/index.d.ts +0 -28
- package/lib/firebase/index.js +0 -180
- package/lib/jsBridge/types.js +0 -17
- package/lib/number-input/hooks/index.d.ts +0 -4
- package/lib/number-input/hooks/index.js +0 -29
- package/lib/number-input/index.d.ts +0 -14
- package/lib/number-input/index.js +0 -41
- package/lib/number-input/types.js +0 -17
- package/lib/number-input/utils/index.d.ts +0 -7
- package/lib/number-input/utils/index.js +0 -39
- package/lib/select/hooks/index.d.ts +0 -5
- package/lib/select/hooks/index.js +0 -34
- package/lib/select/index.js +0 -53
- package/lib/select/types.js +0 -17
- package/lib/select/utils/index.js +0 -48
- package/lib/text-input/hooks/index.d.ts +0 -4
- package/lib/text-input/hooks/index.js +0 -29
- package/lib/text-input/index.d.ts +0 -14
- package/lib/text-input/index.js +0 -35
- package/lib/text-input/types.js +0 -17
- package/lib/text-input/utils/index.d.ts +0 -5
- package/lib/text-input/utils/index.js +0 -32
|
@@ -1,61 +1,51 @@
|
|
|
1
|
+
//#region src/select/utils/helpers.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @returns 找到的选项对象,如果没找到返回 undefined
|
|
11
|
-
*/
|
|
12
|
-
export function findOptionByValue(value, options) {
|
|
13
|
-
return options.find(function (opt) {
|
|
14
|
-
return opt.value === value;
|
|
15
|
-
});
|
|
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);
|
|
16
11
|
}
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return findOptionByValue(val, options);
|
|
28
|
-
}).filter(Boolean);
|
|
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);
|
|
29
21
|
}
|
|
30
|
-
|
|
31
22
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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;
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
* 判断选项是否被选中(多选)
|
|
34
|
+
* @template T 选项值的类型
|
|
35
|
+
* @param optionValue 选项值
|
|
36
|
+
* @param selectedValues 当前选中值数组
|
|
37
|
+
* @returns 是否选中
|
|
38
|
+
*/
|
|
39
|
+
function isOptionSelectedInMultiple(optionValue, selectedValues) {
|
|
40
|
+
return selectedValues.includes(optionValue);
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
export { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { filterOptions, defaultFilterOption } from './filterOptions';
|
|
6
|
-
export { sortOptions } from './sortOptions';
|
|
7
|
-
export { findOptionByValue, findOptionsByValues, isOptionSelected, isOptionSelectedInMultiple, generateId, } from './helpers';
|
|
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,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { SelectOption, SortDirection } from '../types';
|
|
1
|
+
import { SelectOption, SortDirection } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/select/utils/sortOptions.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* 排序选项列表
|
|
7
6
|
* @template T 选项值的类型
|
|
@@ -9,4 +8,6 @@ import type { SelectOption, SortDirection } from '../types';
|
|
|
9
8
|
* @param direction 排序方向('asc' 升序 | 'desc' 降序)
|
|
10
9
|
* @returns 排序后的选项列表(新数组)
|
|
11
10
|
*/
|
|
12
|
-
|
|
11
|
+
declare function sortOptions<T = string | number>(options: SelectOption<T>[], direction?: SortDirection): SelectOption<T>[];
|
|
12
|
+
//#endregion
|
|
13
|
+
export { sortOptions };
|
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
|
|
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; }
|
|
1
|
+
//#region src/select/utils/sortOptions.ts
|
|
7
2
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return labelA.localeCompare(labelB);
|
|
27
|
-
} else {
|
|
28
|
-
return labelB.localeCompare(labelA);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return sortedOptions;
|
|
32
|
-
}
|
|
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 };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
import type { SelectOption, TagDisplayInfo } from '../types';
|
|
1
|
+
import { SelectOption, TagDisplayInfo } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/select/utils/tagAggregation.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* 计算需要显示的标签和聚合信息
|
|
8
6
|
* @template T 选项值的类型
|
|
@@ -22,4 +20,6 @@ import type { SelectOption, TagDisplayInfo } from '../types';
|
|
|
22
20
|
* // }
|
|
23
21
|
* ```
|
|
24
22
|
*/
|
|
25
|
-
|
|
23
|
+
declare function calculateTagDisplay<T = string | number>(selectedValues: T[], options: SelectOption<T>[], maxTagCount: number): TagDisplayInfo<T>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { calculateTagDisplay };
|
|
@@ -1,48 +1,35 @@
|
|
|
1
|
+
//#region src/select/utils/tagAggregation.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
}
|
|
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 };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BaseTextInputProps, TextInputState } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/text-input/hooks/useTextInputState.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* 文本输入状态管理 Hook
|
|
4
6
|
*
|
|
@@ -21,4 +23,6 @@ import type { BaseTextInputProps, TextInputState } from '../types';
|
|
|
21
23
|
* // 非受控模式
|
|
22
24
|
* const state = useTextInputState({ defaultValue: 'hello' });
|
|
23
25
|
*/
|
|
24
|
-
|
|
26
|
+
declare function useTextInputState(props: BaseTextInputProps): TextInputState;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { useTextInputState };
|
|
@@ -1,127 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import { useState, useCallback } from 'react';
|
|
8
|
-
import { validateValue } from "../utils/validation";
|
|
1
|
+
import { validateValue } from "../utils/validation.js";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
//#region src/text-input/hooks/useTextInputState.ts
|
|
9
4
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
}
|
|
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 };
|
package/es/text-input/types.d.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export type { DisplayState, ValidationResult } from '../common';
|
|
1
|
+
import { DisplayState, ValidationResult } from "../common/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/text-input/types.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* 文本输入状态 Hook 返回值
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
38
36
|
}
|
|
39
37
|
/**
|
|
40
38
|
* 基础文本输入 Props(供校验和状态管理使用)
|
|
41
39
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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;
|
|
56
54
|
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { BaseTextInputProps, TextInputState };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ValidationResult } from "../../common/types.js";
|
|
2
|
+
import { BaseTextInputProps } from "../types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/text-input/utils/validation.d.ts
|
|
2
5
|
/**
|
|
3
6
|
* 校验文本输入值
|
|
4
7
|
*
|
|
@@ -20,4 +23,6 @@ import type { BaseTextInputProps, ValidationResult } from '../types';
|
|
|
20
23
|
* validateValue('', { required: true })
|
|
21
24
|
* // { isValid: false, errors: ['此字段为必填项'] }
|
|
22
25
|
*/
|
|
23
|
-
|
|
26
|
+
declare function validateValue(value: string, props: BaseTextInputProps): ValidationResult;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { validateValue };
|