@pisell/utils 3.0.5 → 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 (157) hide show
  1. package/es/arrayUtils.d.ts +72 -0
  2. package/es/arrayUtils.js +142 -3
  3. package/es/common/index.d.ts +5 -0
  4. package/es/common/index.js +5 -0
  5. package/es/common/stateHelper.d.ts +18 -0
  6. package/es/common/stateHelper.js +25 -0
  7. package/es/common/types.d.ts +28 -0
  8. package/es/common/types.js +1 -0
  9. package/es/componentStorage.d.ts +36 -0
  10. package/es/componentStorage.js +142 -0
  11. package/es/format.d.ts +5 -1
  12. package/es/format.js +53 -8
  13. package/es/index.d.ts +6 -0
  14. package/es/index.js +6 -0
  15. package/es/jsBridge/index.d.ts +9 -105
  16. package/es/jsBridge/index.js +28 -12
  17. package/es/jsBridge/types.d.ts +149 -0
  18. package/es/jsBridge/types.js +1 -0
  19. package/es/locales.d.ts +2 -5
  20. package/es/locales.js +36 -7
  21. package/es/miniRedux.js +7 -2
  22. package/es/number-input/hooks/index.d.ts +4 -0
  23. package/es/number-input/hooks/index.js +5 -0
  24. package/es/number-input/hooks/useNumberInputState.d.ts +25 -0
  25. package/es/number-input/hooks/useNumberInputState.js +129 -0
  26. package/es/number-input/index.d.ts +14 -0
  27. package/es/number-input/index.js +21 -0
  28. package/es/number-input/types.d.ts +96 -0
  29. package/es/number-input/types.js +1 -0
  30. package/es/number-input/utils/formatter.d.ts +53 -0
  31. package/es/number-input/utils/formatter.js +82 -0
  32. package/es/number-input/utils/index.d.ts +7 -0
  33. package/es/number-input/utils/index.js +8 -0
  34. package/es/number-input/utils/validation.d.ts +27 -0
  35. package/es/number-input/utils/validation.js +67 -0
  36. package/es/otherUtils.d.ts +48 -0
  37. package/es/select/hooks/index.d.ts +5 -0
  38. package/es/select/hooks/index.js +6 -0
  39. package/es/select/hooks/useDebouncedSearch.d.ts +20 -0
  40. package/es/select/hooks/useDebouncedSearch.js +55 -0
  41. package/es/select/hooks/useSelectState.d.ts +19 -0
  42. package/es/select/hooks/useSelectState.js +117 -0
  43. package/es/select/index.d.ts +8 -0
  44. package/es/select/index.js +13 -0
  45. package/es/select/types.d.ts +256 -0
  46. package/es/select/types.js +1 -0
  47. package/es/select/utils/filterOptions.d.ts +22 -0
  48. package/es/select/utils/filterOptions.js +34 -0
  49. package/es/select/utils/helpers.d.ts +42 -0
  50. package/es/select/utils/helpers.js +61 -0
  51. package/es/select/utils/index.d.ts +7 -0
  52. package/es/select/utils/index.js +8 -0
  53. package/es/select/utils/sortOptions.d.ts +12 -0
  54. package/es/select/utils/sortOptions.js +32 -0
  55. package/es/select/utils/tagAggregation.d.ts +25 -0
  56. package/es/select/utils/tagAggregation.js +48 -0
  57. package/es/text-input/hooks/index.d.ts +4 -0
  58. package/es/text-input/hooks/index.js +5 -0
  59. package/es/text-input/hooks/useTextInputState.d.ts +24 -0
  60. package/es/text-input/hooks/useTextInputState.js +127 -0
  61. package/es/text-input/index.d.ts +14 -0
  62. package/es/text-input/index.js +20 -0
  63. package/es/text-input/types.d.ts +56 -0
  64. package/es/text-input/types.js +1 -0
  65. package/es/text-input/utils/index.d.ts +5 -0
  66. package/es/text-input/utils/index.js +7 -0
  67. package/es/text-input/utils/validation.d.ts +23 -0
  68. package/es/text-input/utils/validation.js +71 -0
  69. package/es/walletValidity.d.ts +55 -0
  70. package/es/walletValidity.js +143 -38
  71. package/es/weighing.d.ts +62 -0
  72. package/es/weighing.js +119 -0
  73. package/lib/arrayUtils.d.ts +72 -0
  74. package/lib/arrayUtils.js +75 -0
  75. package/lib/common/index.d.ts +5 -0
  76. package/lib/common/index.js +29 -0
  77. package/lib/common/stateHelper.d.ts +18 -0
  78. package/lib/common/stateHelper.js +34 -0
  79. package/lib/common/types.d.ts +28 -0
  80. package/lib/common/types.js +17 -0
  81. package/lib/componentStorage.d.ts +36 -0
  82. package/lib/componentStorage.js +144 -0
  83. package/lib/format.d.ts +5 -1
  84. package/lib/format.js +45 -5
  85. package/lib/index.d.ts +6 -0
  86. package/lib/index.js +13 -1
  87. package/lib/jsBridge/index.d.ts +9 -105
  88. package/lib/jsBridge/index.js +20 -1
  89. package/lib/jsBridge/types.d.ts +149 -0
  90. package/lib/jsBridge/types.js +17 -0
  91. package/lib/locales.d.ts +2 -5
  92. package/lib/locales.js +34 -7
  93. package/lib/miniRedux.js +5 -7
  94. package/lib/number-input/hooks/index.d.ts +4 -0
  95. package/lib/number-input/hooks/index.js +29 -0
  96. package/lib/number-input/hooks/useNumberInputState.d.ts +25 -0
  97. package/lib/number-input/hooks/useNumberInputState.js +83 -0
  98. package/lib/number-input/index.d.ts +14 -0
  99. package/lib/number-input/index.js +41 -0
  100. package/lib/number-input/types.d.ts +96 -0
  101. package/lib/number-input/types.js +17 -0
  102. package/lib/number-input/utils/formatter.d.ts +53 -0
  103. package/lib/number-input/utils/formatter.js +55 -0
  104. package/lib/number-input/utils/index.d.ts +7 -0
  105. package/lib/number-input/utils/index.js +39 -0
  106. package/lib/number-input/utils/validation.d.ts +27 -0
  107. package/lib/number-input/utils/validation.js +54 -0
  108. package/lib/otherUtils.d.ts +48 -0
  109. package/lib/select/hooks/index.d.ts +5 -0
  110. package/lib/select/hooks/index.js +34 -0
  111. package/lib/select/hooks/useDebouncedSearch.d.ts +20 -0
  112. package/lib/select/hooks/useDebouncedSearch.js +43 -0
  113. package/lib/select/hooks/useSelectState.d.ts +19 -0
  114. package/lib/select/hooks/useSelectState.js +97 -0
  115. package/lib/select/index.d.ts +8 -0
  116. package/lib/select/index.js +53 -0
  117. package/lib/select/types.d.ts +256 -0
  118. package/lib/select/types.js +17 -0
  119. package/lib/select/utils/filterOptions.d.ts +22 -0
  120. package/lib/select/utils/filterOptions.js +41 -0
  121. package/lib/select/utils/helpers.d.ts +42 -0
  122. package/lib/select/utils/helpers.js +51 -0
  123. package/lib/select/utils/index.d.ts +7 -0
  124. package/lib/select/utils/index.js +48 -0
  125. package/lib/select/utils/sortOptions.d.ts +12 -0
  126. package/lib/select/utils/sortOptions.js +41 -0
  127. package/lib/select/utils/tagAggregation.d.ts +25 -0
  128. package/lib/select/utils/tagAggregation.js +43 -0
  129. package/lib/text-input/hooks/index.d.ts +4 -0
  130. package/lib/text-input/hooks/index.js +29 -0
  131. package/lib/text-input/hooks/useTextInputState.d.ts +24 -0
  132. package/lib/text-input/hooks/useTextInputState.js +81 -0
  133. package/lib/text-input/index.d.ts +14 -0
  134. package/lib/text-input/index.js +35 -0
  135. package/lib/text-input/types.d.ts +56 -0
  136. package/lib/text-input/types.js +17 -0
  137. package/lib/text-input/utils/index.d.ts +5 -0
  138. package/lib/text-input/utils/index.js +32 -0
  139. package/lib/text-input/utils/validation.d.ts +23 -0
  140. package/lib/text-input/utils/validation.js +60 -0
  141. package/lib/walletValidity.d.ts +55 -0
  142. package/lib/walletValidity.js +120 -40
  143. package/lib/weighing.d.ts +62 -0
  144. package/lib/weighing.js +159 -0
  145. package/package.json +1 -1
  146. package/es/date.d.ts +0 -28
  147. package/es/document.d.ts +0 -13
  148. package/es/firebase/config/index.d.ts +0 -13
  149. package/es/firebase/index.d.ts +0 -28
  150. package/es/image.d.ts +0 -11
  151. package/es/typeUtils.d.ts +0 -42
  152. package/lib/date.d.ts +0 -28
  153. package/lib/document.d.ts +0 -13
  154. package/lib/firebase/config/index.d.ts +0 -13
  155. package/lib/firebase/index.d.ts +0 -28
  156. package/lib/image.d.ts +0 -11
  157. package/lib/typeUtils.d.ts +0 -42
@@ -0,0 +1,96 @@
1
+ /**
2
+ * 数值输入组件公共类型定义
3
+ * 供 PisellNumber、PisellCurrency、PisellPercent 等组件使用
4
+ */
5
+ export type { DisplayState, ValidationResult } from '../common';
6
+ /**
7
+ * 数值输入状态 Hook 返回值
8
+ */
9
+ export interface NumberInputState {
10
+ /**
11
+ * 当前值
12
+ */
13
+ value: number | null | undefined;
14
+ /**
15
+ * 是否已被触摸(交互过)
16
+ */
17
+ isTouched: boolean;
18
+ /**
19
+ * 是否校验通过
20
+ */
21
+ isValid: boolean;
22
+ /**
23
+ * 错误信息数组
24
+ */
25
+ errors: string[];
26
+ /**
27
+ * 值变更处理函数
28
+ */
29
+ handleChange: (value: number | null) => void;
30
+ /**
31
+ * 失焦处理函数
32
+ */
33
+ handleBlur: () => void;
34
+ /**
35
+ * 聚焦处理函数
36
+ */
37
+ handleFocus: () => void;
38
+ }
39
+ /**
40
+ * 基础数值输入 Props(供校验和状态管理使用)
41
+ */
42
+ export interface BaseNumberInputProps {
43
+ /**
44
+ * 当前值(受控)
45
+ */
46
+ value?: number | null;
47
+ /**
48
+ * 默认值(非受控)
49
+ */
50
+ defaultValue?: number | null;
51
+ /**
52
+ * 是否必填
53
+ */
54
+ required?: boolean;
55
+ /**
56
+ * 最小值
57
+ */
58
+ min?: number;
59
+ /**
60
+ * 最大值
61
+ */
62
+ max?: number;
63
+ /**
64
+ * 自定义校验函数
65
+ * @param value 当前值
66
+ * @returns true 表示通过,false 或错误信息字符串表示不通过
67
+ */
68
+ validator?: (value: number | null) => boolean | string;
69
+ /**
70
+ * 校验触发时机
71
+ * - onChange: 输入时即时校验
72
+ * - onBlur: 失焦时校验
73
+ * - both: 输入和失焦时都校验
74
+ */
75
+ validateTrigger?: 'onChange' | 'onBlur' | 'both';
76
+ /**
77
+ * 自定义错误提示信息
78
+ */
79
+ errorMessage?: string;
80
+ /**
81
+ * 值变更回调
82
+ */
83
+ onChange?: (value: number | null) => void;
84
+ /**
85
+ * 失焦回调
86
+ */
87
+ onBlur?: (value: number | null) => void;
88
+ /**
89
+ * 聚焦回调
90
+ */
91
+ onFocus?: () => void;
92
+ /**
93
+ * 校验回调
94
+ */
95
+ onValidate?: (isValid: boolean, errors: string[]) => void;
96
+ }
@@ -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/number-input/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 数值格式化工具函数
3
+ */
4
+ /**
5
+ * 格式化选项
6
+ */
7
+ export interface NumberFormatOptions {
8
+ /** 小数精度 */
9
+ precision?: number;
10
+ /** 是否使用千分位分隔符 */
11
+ useGrouping?: boolean;
12
+ /** 自定义格式化函数 */
13
+ formatter?: (value: number | null) => string;
14
+ }
15
+ /**
16
+ * 格式化数值
17
+ *
18
+ * @param value 数值
19
+ * @param options 格式化选项
20
+ * @returns 格式化后的字符串,null 时返回 null
21
+ *
22
+ * @example
23
+ * formatNumber(1234.567, { precision: 2, useGrouping: true })
24
+ * // 返回: "1,234.57"
25
+ *
26
+ * @example
27
+ * formatNumber(1234, { precision: 0, useGrouping: true })
28
+ * // 返回: "1,234"
29
+ */
30
+ export declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
31
+ /**
32
+ * 添加千分位分隔符
33
+ *
34
+ * @param value 数值
35
+ * @returns 添加千分位后的字符串
36
+ *
37
+ * @example
38
+ * addThousandsSeparator(1234567)
39
+ * // 返回: "1,234,567"
40
+ */
41
+ export declare function addThousandsSeparator(value: number): string;
42
+ /**
43
+ * 格式化精度
44
+ *
45
+ * @param value 数值
46
+ * @param precision 小数位数
47
+ * @returns 格式化后的数值
48
+ *
49
+ * @example
50
+ * formatPrecision(1.2345, 2)
51
+ * // 返回: 1.23
52
+ */
53
+ export declare function formatPrecision(value: number, precision: number): number;
@@ -0,0 +1,55 @@
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/formatter.ts
20
+ var formatter_exports = {};
21
+ __export(formatter_exports, {
22
+ addThousandsSeparator: () => addThousandsSeparator,
23
+ formatNumber: () => formatNumber,
24
+ formatPrecision: () => formatPrecision
25
+ });
26
+ module.exports = __toCommonJS(formatter_exports);
27
+ function formatNumber(value, options = {}) {
28
+ if (value === null || value === void 0) {
29
+ return null;
30
+ }
31
+ const { precision, useGrouping = false, formatter } = options;
32
+ if (formatter) {
33
+ return formatter(value);
34
+ }
35
+ if (useGrouping || precision !== void 0) {
36
+ return value.toLocaleString("zh-CN", {
37
+ minimumFractionDigits: precision,
38
+ maximumFractionDigits: precision,
39
+ useGrouping
40
+ });
41
+ }
42
+ return String(value);
43
+ }
44
+ function addThousandsSeparator(value) {
45
+ return value.toLocaleString("zh-CN", { useGrouping: true });
46
+ }
47
+ function formatPrecision(value, precision) {
48
+ return Number(value.toFixed(precision));
49
+ }
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ addThousandsSeparator,
53
+ formatNumber,
54
+ formatPrecision
55
+ });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 数值输入工具函数导出
3
+ */
4
+ export { validateValue } from './validation';
5
+ export { getDisplayState } from '../../common';
6
+ export { formatNumber, addThousandsSeparator, formatPrecision } from './formatter';
7
+ export type { NumberFormatOptions } from './formatter';
@@ -0,0 +1,39 @@
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/index.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ addThousandsSeparator: () => import_formatter.addThousandsSeparator,
23
+ formatNumber: () => import_formatter.formatNumber,
24
+ formatPrecision: () => import_formatter.formatPrecision,
25
+ getDisplayState: () => import_common.getDisplayState,
26
+ validateValue: () => import_validation.validateValue
27
+ });
28
+ module.exports = __toCommonJS(utils_exports);
29
+ var import_validation = require("./validation");
30
+ var import_common = require("../../common");
31
+ var import_formatter = require("./formatter");
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ addThousandsSeparator,
35
+ formatNumber,
36
+ formatPrecision,
37
+ getDisplayState,
38
+ validateValue
39
+ });
@@ -0,0 +1,27 @@
1
+ import type { BaseNumberInputProps, ValidationResult } from '../types';
2
+ /**
3
+ * 校验数值输入
4
+ *
5
+ * 按照优先级执行校验规则:
6
+ * 1. 必填校验(required)
7
+ * 2. 最小值校验(min)
8
+ * 3. 最大值校验(max)
9
+ * 4. 自定义校验函数(validator)
10
+ *
11
+ * @param value 待校验的值
12
+ * @param props 校验配置
13
+ * @returns 校验结果对象,包含 isValid 和 errors
14
+ *
15
+ * @example
16
+ * validateValue(10, { required: true, min: 0, max: 100 })
17
+ * // { isValid: true, errors: [] }
18
+ *
19
+ * @example
20
+ * validateValue(null, { required: true })
21
+ * // { isValid: false, errors: ['此字段为必填项'] }
22
+ *
23
+ * @example
24
+ * validateValue(150, { min: 0, max: 100 })
25
+ * // { isValid: false, errors: ['不能大于 100'] }
26
+ */
27
+ export declare function validateValue(value: number | null | undefined, props: BaseNumberInputProps): ValidationResult;
@@ -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
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @title: 判断是否无痕模式
3
+ * @description:
4
+ * @return: *
5
+ * @Author: shengjie.zuo
6
+ * @Date: 2024-09-4 09:58:22
7
+ */
8
+ export declare const detectIncognito: () => Promise<{
9
+ isPrivate: boolean;
10
+ browserName: string;
11
+ } | {
12
+ isPrivate: boolean;
13
+ }>;
14
+ /**
15
+ * @Description: 生成唯一id
16
+ * @Author: wzw
17
+ * @Date: 2020-12-01 14:20:29
18
+ * @param {*}
19
+ * @return {*}
20
+ */
21
+ export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
22
+ /**
23
+ * @title: 对数组进行增|删
24
+ * @description: 用于多选选中和取消选中的处理
25
+ * @param {any} list
26
+ * @param {any} item
27
+ * @param {string} key
28
+ * @return {*}
29
+ * @Author: zhiwei.Wang
30
+ * @Date: 2023-12-19 16:44
31
+ */
32
+ export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
33
+ /**
34
+ * @title: 判断某个字段是否在列表内
35
+ * @description:
36
+ * @param {*} T
37
+ * @param {boolean} param2
38
+ * @return {*}
39
+ * @Author: zhiwei.Wang
40
+ * @Date: 2023-12-19 16:54
41
+ */
42
+ export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
43
+ export declare const createArray: (length: number, returnItem: any) => unknown[];
44
+ /**
45
+ * 根据对象内容生成唯一id
46
+ * @param obj
47
+ */
48
+ export declare const generateUniqueIdByObj: (obj: Record<string, any>) => any;
@@ -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';