@pisell/utils 1.0.55 → 1.0.57

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 (129) hide show
  1. package/es/common/index.d.ts +5 -0
  2. package/es/common/index.js +5 -0
  3. package/es/common/stateHelper.d.ts +18 -0
  4. package/es/common/stateHelper.js +25 -0
  5. package/es/common/types.d.ts +28 -0
  6. package/es/common/types.js +1 -0
  7. package/es/format.js +6 -2
  8. package/es/index.d.ts +4 -0
  9. package/es/index.js +4 -0
  10. package/es/miniRedux.js +3 -1
  11. package/es/number-input/hooks/index.d.ts +4 -0
  12. package/es/number-input/hooks/index.js +5 -0
  13. package/es/number-input/hooks/useNumberInputState.d.ts +25 -0
  14. package/es/number-input/hooks/useNumberInputState.js +129 -0
  15. package/es/number-input/index.d.ts +14 -0
  16. package/es/number-input/index.js +21 -0
  17. package/es/number-input/types.d.ts +96 -0
  18. package/es/number-input/types.js +1 -0
  19. package/es/number-input/utils/formatter.d.ts +53 -0
  20. package/es/number-input/utils/formatter.js +82 -0
  21. package/es/number-input/utils/index.d.ts +7 -0
  22. package/es/number-input/utils/index.js +8 -0
  23. package/es/number-input/utils/validation.d.ts +27 -0
  24. package/es/number-input/utils/validation.js +67 -0
  25. package/es/otherUtils.js +15 -6
  26. package/es/select/hooks/index.d.ts +5 -0
  27. package/es/select/hooks/index.js +6 -0
  28. package/es/select/hooks/useDebouncedSearch.d.ts +20 -0
  29. package/es/select/hooks/useDebouncedSearch.js +55 -0
  30. package/es/select/hooks/useSelectState.d.ts +19 -0
  31. package/es/select/hooks/useSelectState.js +117 -0
  32. package/es/select/index.d.ts +8 -0
  33. package/es/select/index.js +13 -0
  34. package/es/select/types.d.ts +256 -0
  35. package/es/select/types.js +1 -0
  36. package/es/select/utils/filterOptions.d.ts +22 -0
  37. package/es/select/utils/filterOptions.js +34 -0
  38. package/es/select/utils/helpers.d.ts +42 -0
  39. package/es/select/utils/helpers.js +61 -0
  40. package/es/select/utils/index.d.ts +7 -0
  41. package/es/select/utils/index.js +8 -0
  42. package/es/select/utils/sortOptions.d.ts +12 -0
  43. package/es/select/utils/sortOptions.js +32 -0
  44. package/es/select/utils/tagAggregation.d.ts +25 -0
  45. package/es/select/utils/tagAggregation.js +48 -0
  46. package/es/text-input/hooks/index.d.ts +4 -0
  47. package/es/text-input/hooks/index.js +5 -0
  48. package/es/text-input/hooks/useTextInputState.d.ts +24 -0
  49. package/es/text-input/hooks/useTextInputState.js +127 -0
  50. package/es/text-input/index.d.ts +14 -0
  51. package/es/text-input/index.js +20 -0
  52. package/es/text-input/types.d.ts +56 -0
  53. package/es/text-input/types.js +1 -0
  54. package/es/text-input/utils/index.d.ts +5 -0
  55. package/es/text-input/utils/index.js +7 -0
  56. package/es/text-input/utils/validation.d.ts +23 -0
  57. package/es/text-input/utils/validation.js +71 -0
  58. package/lib/common/index.d.ts +5 -0
  59. package/lib/common/index.js +29 -0
  60. package/lib/common/stateHelper.d.ts +18 -0
  61. package/lib/common/stateHelper.js +34 -0
  62. package/lib/common/types.d.ts +28 -0
  63. package/lib/common/types.js +17 -0
  64. package/lib/format.js +8 -2
  65. package/lib/index.d.ts +4 -0
  66. package/lib/index.js +9 -1
  67. package/lib/miniRedux.js +7 -4
  68. package/lib/number-input/hooks/index.d.ts +4 -0
  69. package/lib/number-input/hooks/index.js +29 -0
  70. package/lib/number-input/hooks/useNumberInputState.d.ts +25 -0
  71. package/lib/number-input/hooks/useNumberInputState.js +83 -0
  72. package/lib/number-input/index.d.ts +14 -0
  73. package/lib/number-input/index.js +41 -0
  74. package/lib/number-input/types.d.ts +96 -0
  75. package/lib/number-input/types.js +17 -0
  76. package/lib/number-input/utils/formatter.d.ts +53 -0
  77. package/lib/number-input/utils/formatter.js +55 -0
  78. package/lib/number-input/utils/index.d.ts +7 -0
  79. package/lib/number-input/utils/index.js +39 -0
  80. package/lib/number-input/utils/validation.d.ts +27 -0
  81. package/lib/number-input/utils/validation.js +54 -0
  82. package/lib/otherUtils.js +9 -2
  83. package/lib/select/hooks/index.d.ts +5 -0
  84. package/lib/select/hooks/index.js +34 -0
  85. package/lib/select/hooks/useDebouncedSearch.d.ts +20 -0
  86. package/lib/select/hooks/useDebouncedSearch.js +43 -0
  87. package/lib/select/hooks/useSelectState.d.ts +19 -0
  88. package/lib/select/hooks/useSelectState.js +97 -0
  89. package/lib/select/index.d.ts +8 -0
  90. package/lib/select/index.js +53 -0
  91. package/lib/select/types.d.ts +256 -0
  92. package/lib/select/types.js +17 -0
  93. package/lib/select/utils/filterOptions.d.ts +22 -0
  94. package/lib/select/utils/filterOptions.js +41 -0
  95. package/lib/select/utils/helpers.d.ts +42 -0
  96. package/lib/select/utils/helpers.js +51 -0
  97. package/lib/select/utils/index.d.ts +7 -0
  98. package/lib/select/utils/index.js +48 -0
  99. package/lib/select/utils/sortOptions.d.ts +12 -0
  100. package/lib/select/utils/sortOptions.js +41 -0
  101. package/lib/select/utils/tagAggregation.d.ts +25 -0
  102. package/lib/select/utils/tagAggregation.js +43 -0
  103. package/lib/text-input/hooks/index.d.ts +4 -0
  104. package/lib/text-input/hooks/index.js +29 -0
  105. package/lib/text-input/hooks/useTextInputState.d.ts +24 -0
  106. package/lib/text-input/hooks/useTextInputState.js +81 -0
  107. package/lib/text-input/index.d.ts +14 -0
  108. package/lib/text-input/index.js +35 -0
  109. package/lib/text-input/types.d.ts +56 -0
  110. package/lib/text-input/types.js +17 -0
  111. package/lib/text-input/utils/index.d.ts +5 -0
  112. package/lib/text-input/utils/index.js +32 -0
  113. package/lib/text-input/utils/validation.d.ts +23 -0
  114. package/lib/text-input/utils/validation.js +60 -0
  115. package/package.json +2 -1
  116. package/es/constants/index.d.ts +0 -7
  117. package/es/format.d.ts +0 -28
  118. package/es/jsBridge/index.d.ts +0 -22
  119. package/es/jsBridge/types.d.ts +0 -149
  120. package/es/locales.d.ts +0 -12
  121. package/es/miniRedux.d.ts +0 -16
  122. package/es/otherUtils.d.ts +0 -48
  123. package/lib/constants/index.d.ts +0 -7
  124. package/lib/format.d.ts +0 -28
  125. package/lib/jsBridge/index.d.ts +0 -22
  126. package/lib/jsBridge/types.d.ts +0 -149
  127. package/lib/locales.d.ts +0 -12
  128. package/lib/miniRedux.d.ts +0 -16
  129. package/lib/otherUtils.d.ts +0 -48
@@ -0,0 +1,54 @@
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/number-input/utils/validation.ts
20
+ var validation_exports = {};
21
+ __export(validation_exports, {
22
+ validateValue: () => validateValue
23
+ });
24
+ module.exports = __toCommonJS(validation_exports);
25
+ function validateValue(value, props) {
26
+ const errors = [];
27
+ if (props.required && (value === null || value === void 0)) {
28
+ errors.push(props.errorMessage || "此字段为必填项");
29
+ return { isValid: false, errors };
30
+ }
31
+ if (value === null || value === void 0) {
32
+ return { isValid: true, errors };
33
+ }
34
+ if (props.min !== void 0 && value < props.min) {
35
+ errors.push(`不能小于 ${props.min}`);
36
+ }
37
+ if (props.max !== void 0 && value > props.max) {
38
+ errors.push(`不能大于 ${props.max}`);
39
+ }
40
+ if (props.validator) {
41
+ const result = props.validator(value);
42
+ if (result !== true) {
43
+ errors.push(typeof result === "string" ? result : "校验失败");
44
+ }
45
+ }
46
+ return {
47
+ isValid: errors.length === 0,
48
+ errors
49
+ };
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ validateValue
54
+ });
package/lib/otherUtils.js CHANGED
@@ -41,12 +41,19 @@ var import_md5 = __toESM(require("crypto-js/md5"));
41
41
  var import_enc_hex = __toESM(require("crypto-js/enc-hex"));
42
42
  var import_detectincognitojs = require("detectincognitojs");
43
43
  var detectIncognito = async () => {
44
- if (navigator.userAgent.toLowerCase().includes("honor")) {
44
+ try {
45
+ if (navigator.userAgent.toLowerCase().includes("honor")) {
46
+ return {
47
+ isPrivate: false
48
+ };
49
+ }
50
+ return await (0, import_detectincognitojs.detectIncognito)();
51
+ } catch (error) {
52
+ console.warn("detectIncognito failed:", error);
45
53
  return {
46
54
  isPrivate: false
47
55
  };
48
56
  }
49
- return await (0, import_detectincognitojs.detectIncognito)();
50
57
  };
51
58
  var getUniqueId = (prefix = "", maxLength = 11) => {
52
59
  return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Select Hooks 导出
3
+ */
4
+ export { useSelectState, useMultipleSelectState } from './useSelectState';
5
+ export { useDebouncedSearch } from './useDebouncedSearch';
@@ -0,0 +1,34 @@
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/hooks/index.ts
20
+ var hooks_exports = {};
21
+ __export(hooks_exports, {
22
+ useDebouncedSearch: () => import_useDebouncedSearch.useDebouncedSearch,
23
+ useMultipleSelectState: () => import_useSelectState.useMultipleSelectState,
24
+ useSelectState: () => import_useSelectState.useSelectState
25
+ });
26
+ module.exports = __toCommonJS(hooks_exports);
27
+ var import_useSelectState = require("./useSelectState");
28
+ var import_useDebouncedSearch = require("./useDebouncedSearch");
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ useDebouncedSearch,
32
+ useMultipleSelectState,
33
+ useSelectState
34
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 防抖搜索 Hook
3
+ * 对用户输入进行防抖处理,避免频繁触发搜索
4
+ */
5
+ /**
6
+ * 防抖搜索 Hook
7
+ * @template T 值的类型
8
+ * @param initialValue 初始值
9
+ * @param delay 防抖延迟时间(毫秒)
10
+ * @param callback 防抖后的回调函数
11
+ * @returns [防抖后的值, 设置值函数]
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const [debouncedSearch, setSearchInput] = useDebouncedSearch('', 300, (text) => {
16
+ * console.log('搜索关键词:', text);
17
+ * });
18
+ * ```
19
+ */
20
+ export declare function useDebouncedSearch<T = string>(initialValue: T, delay: number, callback?: (value: T) => void): [T, (value: T) => void];
@@ -0,0 +1,43 @@
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/hooks/useDebouncedSearch.ts
20
+ var useDebouncedSearch_exports = {};
21
+ __export(useDebouncedSearch_exports, {
22
+ useDebouncedSearch: () => useDebouncedSearch
23
+ });
24
+ module.exports = __toCommonJS(useDebouncedSearch_exports);
25
+ var import_react = require("react");
26
+ function useDebouncedSearch(initialValue, delay, callback) {
27
+ const [value, setValue] = (0, import_react.useState)(initialValue);
28
+ const [debouncedValue, setDebouncedValue] = (0, import_react.useState)(initialValue);
29
+ (0, import_react.useEffect)(() => {
30
+ const timer = setTimeout(() => {
31
+ setDebouncedValue(value);
32
+ callback == null ? void 0 : callback(value);
33
+ }, delay);
34
+ return () => {
35
+ clearTimeout(timer);
36
+ };
37
+ }, [value, delay, callback]);
38
+ return [debouncedValue, setValue];
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ useDebouncedSearch
43
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Select 状态管理 Hook
3
+ * 处理受控/非受控模式,适用于单选和多选
4
+ */
5
+ import type { UseSelectStateOptions, UseMultipleSelectStateOptions, SelectState, MultipleSelectState } from '../types';
6
+ /**
7
+ * 单选状态管理 Hook
8
+ * @template T 值的类型
9
+ * @param options Hook 配置选项
10
+ * @returns 状态管理对象
11
+ */
12
+ export declare function useSelectState<T = string | number>(options: UseSelectStateOptions<T>): SelectState<T>;
13
+ /**
14
+ * 多选状态管理 Hook
15
+ * @template T 值的类型
16
+ * @param options Hook 配置选项
17
+ * @returns 状态管理对象
18
+ */
19
+ export declare function useMultipleSelectState<T = string | number>(options: UseMultipleSelectStateOptions<T>): MultipleSelectState<T>;
@@ -0,0 +1,97 @@
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/hooks/useSelectState.ts
20
+ var useSelectState_exports = {};
21
+ __export(useSelectState_exports, {
22
+ useMultipleSelectState: () => useMultipleSelectState,
23
+ useSelectState: () => useSelectState
24
+ });
25
+ module.exports = __toCommonJS(useSelectState_exports);
26
+ var import_react = require("react");
27
+ function useSelectState(options) {
28
+ const { value: controlledValue, defaultValue, onChange } = options;
29
+ const isControlled = controlledValue !== void 0;
30
+ const [internalValue, setInternalValue] = (0, import_react.useState)(
31
+ defaultValue ?? null
32
+ );
33
+ const value = isControlled ? controlledValue : internalValue;
34
+ const setValue = (0, import_react.useCallback)(
35
+ (newValue) => {
36
+ if (!isControlled) {
37
+ setInternalValue(newValue);
38
+ }
39
+ onChange == null ? void 0 : onChange(newValue, null);
40
+ },
41
+ [isControlled, onChange]
42
+ );
43
+ const clearValue = (0, import_react.useCallback)(() => {
44
+ setValue(null);
45
+ }, [setValue]);
46
+ return {
47
+ value,
48
+ setValue,
49
+ clearValue
50
+ };
51
+ }
52
+ function useMultipleSelectState(options) {
53
+ const { value: controlledValue, defaultValue, onChange } = options;
54
+ const isControlled = controlledValue !== void 0;
55
+ const [internalValue, setInternalValue] = (0, import_react.useState)(
56
+ defaultValue ?? []
57
+ );
58
+ const value = isControlled ? controlledValue ?? [] : internalValue;
59
+ const setValue = (0, import_react.useCallback)(
60
+ (newValue) => {
61
+ if (!isControlled) {
62
+ setInternalValue(newValue);
63
+ }
64
+ onChange == null ? void 0 : onChange(newValue, []);
65
+ },
66
+ [isControlled, onChange]
67
+ );
68
+ const addValue = (0, import_react.useCallback)(
69
+ (val) => {
70
+ const newValue = [...value, val];
71
+ setValue(newValue);
72
+ },
73
+ [value, setValue]
74
+ );
75
+ const removeValue = (0, import_react.useCallback)(
76
+ (val) => {
77
+ const newValue = value.filter((v) => v !== val);
78
+ setValue(newValue);
79
+ },
80
+ [value, setValue]
81
+ );
82
+ const clearValue = (0, import_react.useCallback)(() => {
83
+ setValue([]);
84
+ }, [setValue]);
85
+ return {
86
+ value,
87
+ setValue,
88
+ addValue,
89
+ removeValue,
90
+ clearValue
91
+ };
92
+ }
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ useMultipleSelectState,
96
+ useSelectState
97
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Select 组件相关工具和类型导出
3
+ * 供 PisellSingleSelect、PisellMultipleSelect 等组件使用
4
+ */
5
+ export type { SelectOption, FilterOptionFunc, SortDirection, SelectState, MultipleSelectState, TagDisplayInfo, UseSelectStateOptions, UseMultipleSelectStateOptions, BaseSelectProps, } from './types';
6
+ export { useSelectState, useMultipleSelectState } from './hooks/useSelectState';
7
+ export { useDebouncedSearch } from './hooks/useDebouncedSearch';
8
+ export { filterOptions, defaultFilterOption, sortOptions, calculateTagDisplay, findOptionByValue, findOptionsByValues, isOptionSelected, isOptionSelectedInMultiple, generateId, } from './utils';
@@ -0,0 +1,53 @@
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/index.ts
20
+ var select_exports = {};
21
+ __export(select_exports, {
22
+ calculateTagDisplay: () => import_utils.calculateTagDisplay,
23
+ defaultFilterOption: () => import_utils.defaultFilterOption,
24
+ filterOptions: () => import_utils.filterOptions,
25
+ findOptionByValue: () => import_utils.findOptionByValue,
26
+ findOptionsByValues: () => import_utils.findOptionsByValues,
27
+ generateId: () => import_utils.generateId,
28
+ isOptionSelected: () => import_utils.isOptionSelected,
29
+ isOptionSelectedInMultiple: () => import_utils.isOptionSelectedInMultiple,
30
+ sortOptions: () => import_utils.sortOptions,
31
+ useDebouncedSearch: () => import_useDebouncedSearch.useDebouncedSearch,
32
+ useMultipleSelectState: () => import_useSelectState.useMultipleSelectState,
33
+ useSelectState: () => import_useSelectState.useSelectState
34
+ });
35
+ module.exports = __toCommonJS(select_exports);
36
+ var import_useSelectState = require("./hooks/useSelectState");
37
+ var import_useDebouncedSearch = require("./hooks/useDebouncedSearch");
38
+ var import_utils = require("./utils");
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ calculateTagDisplay,
42
+ defaultFilterOption,
43
+ filterOptions,
44
+ findOptionByValue,
45
+ findOptionsByValues,
46
+ generateId,
47
+ isOptionSelected,
48
+ isOptionSelectedInMultiple,
49
+ sortOptions,
50
+ useDebouncedSearch,
51
+ useMultipleSelectState,
52
+ useSelectState
53
+ });
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Select 组件公共类型定义
3
+ * 供 PisellSingleSelect、PisellMultipleSelect 等组件使用
4
+ */
5
+ import React from 'react';
6
+ export type { DisplayState } from '../common';
7
+ /**
8
+ * 选项基础类型
9
+ * @template T 选项值的类型,默认为 string | number
10
+ */
11
+ export interface SelectOption<T = string | number> {
12
+ /**
13
+ * 选项值(唯一标识)
14
+ */
15
+ value: T;
16
+ /**
17
+ * 选项显示文本
18
+ */
19
+ label: string;
20
+ /**
21
+ * 是否禁用该选项
22
+ * @default false
23
+ */
24
+ disabled?: boolean;
25
+ /**
26
+ * 选项图标(可选)
27
+ */
28
+ icon?: React.ReactNode;
29
+ /**
30
+ * 标签背景色(多选时用于自定义标签颜色)
31
+ * @example '#61dafb'
32
+ */
33
+ color?: string;
34
+ }
35
+ /**
36
+ * 选项过滤函数类型
37
+ * @template T 选项值的类型
38
+ * @param input 用户输入的搜索文本
39
+ * @param option 当前选项对象
40
+ * @returns 是否保留该选项
41
+ */
42
+ export declare type FilterOptionFunc<T = string | number> = (input: string, option: SelectOption<T>) => boolean;
43
+ /**
44
+ * 排序方向
45
+ */
46
+ export declare type SortDirection = 'asc' | 'desc';
47
+ /**
48
+ * Select 状态 Hook 返回值(单选)
49
+ * @template T 值的类型
50
+ */
51
+ export interface SelectState<T = string | number> {
52
+ /**
53
+ * 当前选中值
54
+ */
55
+ value: T | null | undefined;
56
+ /**
57
+ * 设置选中值
58
+ */
59
+ setValue: (value: T | null) => void;
60
+ /**
61
+ * 清空选中值
62
+ */
63
+ clearValue: () => void;
64
+ }
65
+ /**
66
+ * Multiple Select 状态 Hook 返回值(多选)
67
+ * @template T 值的类型
68
+ */
69
+ export interface MultipleSelectState<T = string | number> {
70
+ /**
71
+ * 当前选中值数组
72
+ */
73
+ value: T[];
74
+ /**
75
+ * 设置选中值数组
76
+ */
77
+ setValue: (value: T[]) => void;
78
+ /**
79
+ * 添加一个选中值
80
+ */
81
+ addValue: (value: T) => void;
82
+ /**
83
+ * 移除一个选中值
84
+ */
85
+ removeValue: (value: T) => void;
86
+ /**
87
+ * 清空所有选中值
88
+ */
89
+ clearValue: () => void;
90
+ }
91
+ /**
92
+ * 标签显示信息(多选专用)
93
+ * @template T 选项值的类型
94
+ */
95
+ export interface TagDisplayInfo<T = string | number> {
96
+ /**
97
+ * 可见的标签列表
98
+ */
99
+ visibleTags: SelectOption<T>[];
100
+ /**
101
+ * 隐藏的标签列表
102
+ */
103
+ hiddenTags: SelectOption<T>[];
104
+ /**
105
+ * 隐藏的标签数量
106
+ */
107
+ hiddenCount: number;
108
+ }
109
+ /**
110
+ * useSelectState Hook 的配置选项(单选)
111
+ * @template T 值的类型
112
+ */
113
+ export interface UseSelectStateOptions<T = string | number> {
114
+ /**
115
+ * 受控模式:当前值
116
+ */
117
+ value?: T | null;
118
+ /**
119
+ * 非受控模式:默认值
120
+ */
121
+ defaultValue?: T;
122
+ /**
123
+ * 值变化回调
124
+ */
125
+ onChange?: (value: T | null, option: SelectOption<T> | null) => void;
126
+ /**
127
+ * 模式(用于类型区分)
128
+ */
129
+ mode: 'single';
130
+ }
131
+ /**
132
+ * useMultipleSelectState Hook 的配置选项(多选)
133
+ * @template T 值的类型
134
+ */
135
+ export interface UseMultipleSelectStateOptions<T = string | number> {
136
+ /**
137
+ * 受控模式:当前值数组
138
+ */
139
+ value?: T[];
140
+ /**
141
+ * 非受控模式:默认值数组
142
+ */
143
+ defaultValue?: T[];
144
+ /**
145
+ * 值变化回调
146
+ */
147
+ onChange?: (value: T[], options: SelectOption<T>[]) => void;
148
+ /**
149
+ * 模式(用于类型区分)
150
+ */
151
+ mode: 'multiple';
152
+ }
153
+ /**
154
+ * 基础 Select Props(公共属性)
155
+ * @template T 值的类型
156
+ */
157
+ export interface BaseSelectProps<T = string | number> {
158
+ /**
159
+ * 选项列表(必填)
160
+ */
161
+ options: SelectOption<T>[];
162
+ /**
163
+ * 占位符文本
164
+ * @default '请选择'
165
+ */
166
+ placeholder?: string;
167
+ /**
168
+ * 是否显示搜索框
169
+ * @default false
170
+ */
171
+ showSearch?: boolean;
172
+ /**
173
+ * 是否显示清空按钮
174
+ * @default false
175
+ */
176
+ allowClear?: boolean;
177
+ /**
178
+ * 是否禁用
179
+ * @default false
180
+ */
181
+ disabled?: boolean;
182
+ /**
183
+ * 是否只读
184
+ * @default false
185
+ */
186
+ readOnly?: boolean;
187
+ /**
188
+ * 尺寸
189
+ * @default 'middle'
190
+ */
191
+ size?: 'small' | 'middle' | 'large';
192
+ /**
193
+ * 自定义类名
194
+ */
195
+ className?: string;
196
+ /**
197
+ * 自定义样式
198
+ */
199
+ style?: React.CSSProperties;
200
+ /**
201
+ * 标签文本
202
+ */
203
+ label?: string;
204
+ /**
205
+ * 辅助提示文本
206
+ */
207
+ helperText?: string;
208
+ /**
209
+ * 是否必填
210
+ * @default false
211
+ */
212
+ required?: boolean;
213
+ /**
214
+ * 是否显示错误状态
215
+ * @default false
216
+ */
217
+ error?: boolean;
218
+ /**
219
+ * 错误提示文本
220
+ */
221
+ errorText?: string;
222
+ /**
223
+ * 是否启用过滤
224
+ * @default false
225
+ */
226
+ filterable?: boolean;
227
+ /**
228
+ * 自定义过滤函数
229
+ */
230
+ filterOption?: FilterOptionFunc<T>;
231
+ /**
232
+ * 是否启用排序
233
+ * @default false
234
+ */
235
+ sortable?: boolean;
236
+ /**
237
+ * 排序方向
238
+ */
239
+ sortDirection?: SortDirection;
240
+ /**
241
+ * 搜索输入回调
242
+ */
243
+ onSearch?: (value: string) => void;
244
+ /**
245
+ * 获得焦点回调
246
+ */
247
+ onFocus?: (event: React.FocusEvent) => void;
248
+ /**
249
+ * 失去焦点回调
250
+ */
251
+ onBlur?: (event: React.FocusEvent) => void;
252
+ /**
253
+ * 下拉框显隐回调
254
+ */
255
+ onDropdownVisibleChange?: (visible: boolean) => void;
256
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/select/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 选项过滤工具函数
3
+ */
4
+ import type { SelectOption, FilterOptionFunc } from '../types';
5
+ /**
6
+ * 默认的选项过滤函数
7
+ * 根据 label 进行模糊匹配(不区分大小写)
8
+ * @template T 选项值的类型
9
+ * @param input 搜索输入文本
10
+ * @param option 选项对象
11
+ * @returns 是否保留该选项
12
+ */
13
+ export declare function defaultFilterOption<T = string | number>(input: string, option: SelectOption<T>): boolean;
14
+ /**
15
+ * 过滤选项列表
16
+ * @template T 选项值的类型
17
+ * @param options 原始选项列表
18
+ * @param searchText 搜索文本
19
+ * @param filterFunc 自定义过滤函数(可选)
20
+ * @returns 过滤后的选项列表
21
+ */
22
+ export declare function filterOptions<T = string | number>(options: SelectOption<T>[], searchText: string, filterFunc?: FilterOptionFunc<T>): SelectOption<T>[];