@pisell/utils 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/es/arrayUtils.d.ts +23 -26
  2. package/es/arrayUtils.js +157 -97
  3. package/es/common/index.d.ts +5 -0
  4. package/es/common/index.js +5 -0
  5. package/es/common/stateHelper.d.ts +2 -6
  6. package/es/common/stateHelper.js +24 -22
  7. package/es/common/types.d.ts +10 -13
  8. package/es/common/types.js +1 -0
  9. package/es/componentStorage.d.ts +25 -27
  10. package/es/componentStorage.js +130 -94
  11. package/es/constants/index.js +9 -7
  12. package/es/date.js +53 -36
  13. package/es/document.js +67 -43
  14. package/es/escPosPrinter/EscPosPrinter.js +490 -353
  15. package/es/escPosPrinter/index.d.ts +9 -9
  16. package/es/escPosPrinter/index.js +52 -37
  17. package/es/firebase/config/index.js +54 -0
  18. package/es/firebase/index.js +232 -0
  19. package/es/format.d.ts +15 -12
  20. package/es/format.js +156 -89
  21. package/es/image.js +60 -48
  22. package/es/index.d.ts +24 -39
  23. package/es/index.js +35 -40
  24. package/es/jsBridge/index.d.ts +4 -8
  25. package/es/jsBridge/index.js +55 -56
  26. package/es/jsBridge/regDeviceApi.js +126 -87
  27. package/es/jsBridge/types.d.ts +115 -95
  28. package/es/jsBridge/types.js +1 -0
  29. package/es/locales.d.ts +8 -11
  30. package/es/locales.js +96 -77
  31. package/es/log.d.ts +6 -11
  32. package/es/log.js +59 -37
  33. package/es/miniRedux.d.ts +13 -20
  34. package/es/miniRedux.js +76 -42
  35. package/es/number-input/hooks/index.d.ts +4 -0
  36. package/es/number-input/hooks/index.js +5 -0
  37. package/es/number-input/hooks/useNumberInputState.d.ts +2 -6
  38. package/es/number-input/hooks/useNumberInputState.js +128 -71
  39. package/es/number-input/index.d.ts +14 -0
  40. package/es/number-input/index.js +21 -0
  41. package/es/number-input/types.d.ts +88 -88
  42. package/es/number-input/types.js +1 -0
  43. package/es/number-input/utils/formatter.d.ts +10 -13
  44. package/es/number-input/utils/formatter.js +77 -51
  45. package/es/number-input/utils/index.d.ts +7 -0
  46. package/es/number-input/utils/index.js +8 -0
  47. package/es/number-input/utils/validation.d.ts +2 -7
  48. package/es/number-input/utils/validation.js +66 -51
  49. package/es/otherUtils.d.ts +9 -12
  50. package/es/otherUtils.js +129 -71
  51. package/es/platform.d.ts +9 -12
  52. package/es/platform.js +85 -61
  53. package/es/select/hooks/index.d.ts +5 -0
  54. package/es/select/hooks/index.js +6 -0
  55. package/es/select/hooks/useDebouncedSearch.d.ts +1 -4
  56. package/es/select/hooks/useDebouncedSearch.js +53 -39
  57. package/es/select/hooks/useSelectState.d.ts +7 -7
  58. package/es/select/hooks/useSelectState.js +113 -56
  59. package/es/select/index.d.ts +8 -7
  60. package/es/select/index.js +13 -0
  61. package/es/select/types.d.ts +211 -211
  62. package/es/select/types.js +1 -0
  63. package/es/select/utils/filterOptions.d.ts +6 -7
  64. package/es/select/utils/filterOptions.js +31 -26
  65. package/es/select/utils/helpers.d.ts +9 -10
  66. package/es/select/utils/helpers.js +52 -42
  67. package/es/select/utils/index.d.ts +7 -4
  68. package/es/select/utils/index.js +8 -0
  69. package/es/select/utils/sortOptions.d.ts +5 -6
  70. package/es/select/utils/sortOptions.js +31 -19
  71. package/es/select/utils/tagAggregation.d.ts +6 -6
  72. package/es/select/utils/tagAggregation.js +47 -34
  73. package/es/text-input/hooks/index.d.ts +4 -0
  74. package/es/text-input/hooks/index.js +5 -0
  75. package/es/text-input/hooks/useTextInputState.d.ts +2 -6
  76. package/es/text-input/hooks/useTextInputState.js +126 -69
  77. package/es/text-input/index.d.ts +14 -0
  78. package/es/text-input/index.js +20 -0
  79. package/es/text-input/types.d.ts +48 -48
  80. package/es/text-input/types.js +1 -0
  81. package/es/text-input/utils/index.d.ts +5 -0
  82. package/es/text-input/utils/index.js +7 -0
  83. package/es/text-input/utils/validation.d.ts +2 -7
  84. package/es/text-input/utils/validation.js +70 -50
  85. package/es/typeUtils.js +84 -61
  86. package/es/walletValidity.d.ts +42 -44
  87. package/es/walletValidity.js +557 -396
  88. package/es/weighing.d.ts +45 -48
  89. package/es/weighing.js +106 -83
  90. package/lib/arrayUtils.d.ts +23 -26
  91. package/lib/arrayUtils.js +111 -101
  92. package/lib/common/index.d.ts +5 -0
  93. package/lib/common/index.js +29 -0
  94. package/lib/common/stateHelper.d.ts +2 -6
  95. package/lib/common/stateHelper.js +32 -21
  96. package/lib/common/types.d.ts +10 -13
  97. package/lib/common/types.js +17 -0
  98. package/lib/componentStorage.d.ts +25 -27
  99. package/lib/componentStorage.js +126 -96
  100. package/lib/constants/index.js +36 -7
  101. package/lib/date.js +65 -43
  102. package/lib/document.js +62 -46
  103. package/lib/escPosPrinter/EscPosPrinter.js +403 -327
  104. package/lib/escPosPrinter/index.d.ts +9 -9
  105. package/lib/escPosPrinter/index.js +84 -38
  106. package/lib/firebase/config/index.js +79 -0
  107. package/lib/firebase/index.js +180 -0
  108. package/lib/format.d.ts +15 -12
  109. package/lib/format.js +133 -91
  110. package/lib/image.js +74 -48
  111. package/lib/index.d.ts +24 -39
  112. package/lib/index.js +80 -137
  113. package/lib/jsBridge/index.d.ts +4 -8
  114. package/lib/jsBridge/index.js +76 -57
  115. package/lib/jsBridge/regDeviceApi.js +133 -86
  116. package/lib/jsBridge/types.d.ts +115 -95
  117. package/lib/jsBridge/types.js +17 -0
  118. package/lib/locales.d.ts +8 -11
  119. package/lib/locales.js +90 -79
  120. package/lib/log.d.ts +6 -11
  121. package/lib/log.js +61 -37
  122. package/lib/miniRedux.d.ts +13 -20
  123. package/lib/miniRedux.js +89 -43
  124. package/lib/number-input/hooks/index.d.ts +4 -0
  125. package/lib/number-input/hooks/index.js +29 -0
  126. package/lib/number-input/hooks/useNumberInputState.d.ts +2 -6
  127. package/lib/number-input/hooks/useNumberInputState.js +81 -71
  128. package/lib/number-input/index.d.ts +14 -0
  129. package/lib/number-input/index.js +41 -0
  130. package/lib/number-input/types.d.ts +88 -88
  131. package/lib/number-input/types.js +17 -0
  132. package/lib/number-input/utils/formatter.d.ts +10 -13
  133. package/lib/number-input/utils/formatter.js +49 -52
  134. package/lib/number-input/utils/index.d.ts +7 -0
  135. package/lib/number-input/utils/index.js +39 -0
  136. package/lib/number-input/utils/validation.d.ts +2 -7
  137. package/lib/number-input/utils/validation.js +52 -50
  138. package/lib/otherUtils.d.ts +9 -12
  139. package/lib/otherUtils.js +98 -86
  140. package/lib/platform.d.ts +9 -12
  141. package/lib/platform.js +123 -68
  142. package/lib/select/hooks/index.d.ts +5 -0
  143. package/lib/select/hooks/index.js +34 -0
  144. package/lib/select/hooks/useDebouncedSearch.d.ts +1 -4
  145. package/lib/select/hooks/useDebouncedSearch.js +41 -40
  146. package/lib/select/hooks/useSelectState.d.ts +7 -7
  147. package/lib/select/hooks/useSelectState.js +93 -58
  148. package/lib/select/index.d.ts +8 -7
  149. package/lib/select/index.js +53 -0
  150. package/lib/select/types.d.ts +211 -211
  151. package/lib/select/types.js +17 -0
  152. package/lib/select/utils/filterOptions.d.ts +6 -7
  153. package/lib/select/utils/filterOptions.js +37 -26
  154. package/lib/select/utils/helpers.d.ts +9 -10
  155. package/lib/select/utils/helpers.js +41 -45
  156. package/lib/select/utils/index.d.ts +7 -4
  157. package/lib/select/utils/index.js +48 -0
  158. package/lib/select/utils/sortOptions.d.ts +5 -6
  159. package/lib/select/utils/sortOptions.js +39 -18
  160. package/lib/select/utils/tagAggregation.d.ts +6 -6
  161. package/lib/select/utils/tagAggregation.js +41 -33
  162. package/lib/text-input/hooks/index.d.ts +4 -0
  163. package/lib/text-input/hooks/index.js +29 -0
  164. package/lib/text-input/hooks/useTextInputState.d.ts +2 -6
  165. package/lib/text-input/hooks/useTextInputState.js +79 -69
  166. package/lib/text-input/index.d.ts +14 -0
  167. package/lib/text-input/index.js +35 -0
  168. package/lib/text-input/types.d.ts +48 -48
  169. package/lib/text-input/types.js +17 -0
  170. package/lib/text-input/utils/index.d.ts +5 -0
  171. package/lib/text-input/utils/index.js +32 -0
  172. package/lib/text-input/utils/validation.d.ts +2 -7
  173. package/lib/text-input/utils/validation.js +58 -49
  174. package/lib/typeUtils.js +73 -68
  175. package/lib/walletValidity.d.ts +42 -44
  176. package/lib/walletValidity.js +393 -410
  177. package/lib/weighing.d.ts +45 -48
  178. package/lib/weighing.js +149 -104
  179. package/package.json +1 -1
  180. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  181. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  182. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  183. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  184. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  185. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -11
  186. package/es/date.d.ts +0 -31
  187. package/es/document.d.ts +0 -16
  188. package/es/image.d.ts +0 -14
  189. package/es/typeUtils.d.ts +0 -45
  190. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  191. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  192. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  193. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  194. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  195. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -16
  196. package/lib/_virtual/_rolldown/runtime.js +0 -23
  197. package/lib/date.d.ts +0 -31
  198. package/lib/document.d.ts +0 -16
  199. package/lib/image.d.ts +0 -14
  200. package/lib/typeUtils.d.ts +0 -45
@@ -1,10 +1,9 @@
1
- //#region src/arrayUtils.d.ts
2
- declare const uniqueByKey: <T>(arr: T[], key: keyof T) => T[];
1
+ export declare const uniqueByKey: <T>(arr: T[], key: keyof T) => T[];
3
2
  /**
4
3
  * 分组键的基础类型
5
4
  * @description 分组条件计算后得到的标量值
6
5
  */
7
- type GroupKey = string | number | boolean;
6
+ export declare type GroupKey = string | number | boolean;
8
7
  /**
9
8
  * 分组规则
10
9
  * @template T - 数据项类型
@@ -13,34 +12,34 @@ type GroupKey = string | number | boolean;
13
12
  * - `string[]`:多字段组合,按顺序拼接为组合键
14
13
  * - `(item, index) => GroupKey | GroupKey[]`:完全自定义分组键
15
14
  */
16
- type GroupBySpec<T> = string | string[] | ((item: T, index: number) => GroupKey | GroupKey[]);
15
+ export declare type GroupBySpec<T> = string | string[] | ((item: T, index: number) => GroupKey | GroupKey[]);
17
16
  /**
18
17
  * 单个分组的结果模型
19
18
  * @template T - 数据项类型
20
19
  */
21
- interface GroupResult<T> {
22
- /** 分组唯一标识(默认由各分组键以 `|` 拼接) */
23
- groupId: string;
24
- /** 分组键值数组,与 `GroupBySpec` 顺序对应 */
25
- keys: GroupKey[];
26
- /** 字段名 -> 键值映射,便于头部直接按字段名取值(自定义函数分组时为空对象) */
27
- keyMap: Record<string, GroupKey>;
28
- /** 该分组内的原始数据项(保持原数组中的相对顺序) */
29
- items: T[];
30
- /** 分组的最终顺序下标 */
31
- index: number;
20
+ export interface GroupResult<T> {
21
+ /** 分组唯一标识(默认由各分组键以 `|` 拼接) */
22
+ groupId: string;
23
+ /** 分组键值数组,与 `GroupBySpec` 顺序对应 */
24
+ keys: GroupKey[];
25
+ /** 字段名 -> 键值映射,便于头部直接按字段名取值(自定义函数分组时为空对象) */
26
+ keyMap: Record<string, GroupKey>;
27
+ /** 该分组内的原始数据项(保持原数组中的相对顺序) */
28
+ items: T[];
29
+ /** 分组的最终顺序下标 */
30
+ index: number;
32
31
  }
33
32
  /**
34
33
  * 分组可选项
35
34
  * @template T - 数据项类型
36
35
  */
37
- interface GroupByOptions<T> {
38
- /** 自定义分组 id 生成(默认 `keys.join('|')`) */
39
- getGroupId?: (keys: GroupKey[]) => string;
40
- /** 分组之间的排序;不传则保持各分组首次出现的顺序 */
41
- sortGroups?: (a: GroupResult<T>, b: GroupResult<T>) => number;
42
- /** 分组内数据项的排序;不传则保持原始相对顺序 */
43
- sortItems?: (a: T, b: T) => number;
36
+ export interface GroupByOptions<T> {
37
+ /** 自定义分组 id 生成(默认 `keys.join('|')`) */
38
+ getGroupId?: (keys: GroupKey[]) => string;
39
+ /** 分组之间的排序;不传则保持各分组首次出现的顺序 */
40
+ sortGroups?: (a: GroupResult<T>, b: GroupResult<T>) => number;
41
+ /** 分组内数据项的排序;不传则保持原始相对顺序 */
42
+ sortItems?: (a: T, b: T) => number;
44
43
  }
45
44
  /**
46
45
  * 按点路径安全取值
@@ -51,7 +50,7 @@ interface GroupByOptions<T> {
51
50
  * getByPath({ a: { b: 1 } }, 'a.b') // 1
52
51
  * getByPath({ id: 9 }, 'id') // 9
53
52
  */
54
- declare const getByPath: (obj: unknown, path: string) => unknown;
53
+ export declare const getByPath: (obj: unknown, path: string) => unknown;
55
54
  /**
56
55
  * 将数组按指定条件分组
57
56
  * @template T - 数据项类型
@@ -71,6 +70,4 @@ declare const getByPath: (obj: unknown, path: string) => unknown;
71
70
  * // 自定义键
72
71
  * groupBy(list, (item) => `${item.productId}_${item.time}`);
73
72
  */
74
- declare const groupBy: <T>(dataSource: T[], spec: GroupBySpec<T>, options?: GroupByOptions<T>) => GroupResult<T>[];
75
- //#endregion
76
- export { GroupByOptions, GroupBySpec, GroupKey, GroupResult, getByPath, groupBy, uniqueByKey };
73
+ export declare const groupBy: <T>(dataSource: T[], spec: GroupBySpec<T>, options?: GroupByOptions<T>) => GroupResult<T>[];
package/es/arrayUtils.js CHANGED
@@ -1,103 +1,163 @@
1
- //#region src/arrayUtils.ts
2
- const uniqueByKey = (arr, key) => {
3
- const seen = /* @__PURE__ */ new Set();
4
- const result = [];
5
- for (const item of arr) {
6
- const keyValue = item[key];
7
- if (!seen.has(keyValue)) {
8
- seen.add(keyValue);
9
- result.push(item);
10
- }
11
- }
12
- return result;
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ 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); }
3
+ 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; }
4
+ export var uniqueByKey = function uniqueByKey(arr, key) {
5
+ var seen = new Set();
6
+ var result = [];
7
+ var _iterator = _createForOfIteratorHelper(arr),
8
+ _step;
9
+ try {
10
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
11
+ var _item = _step.value;
12
+ var keyValue = _item[key];
13
+ if (!seen.has(keyValue)) {
14
+ seen.add(keyValue);
15
+ result.push(_item);
16
+ }
17
+ }
18
+ } catch (err) {
19
+ _iterator.e(err);
20
+ } finally {
21
+ _iterator.f();
22
+ }
23
+ return result;
13
24
  };
25
+
14
26
  /**
15
- * 按点路径安全取值
16
- * @param obj - 取值对象
17
- * @param path - 字段路径,支持 `'a.b.c'`
18
- * @returns 路径对应的值,路径不存在时返回 undefined
19
- * @example
20
- * getByPath({ a: { b: 1 } }, 'a.b') // 1
21
- * getByPath({ id: 9 }, 'id') // 9
22
- */
23
- const getByPath = (obj, path) => {
24
- if (obj === null || obj === void 0) return;
25
- if (path.indexOf(".") === -1) return obj[path];
26
- return path.split(".").reduce((acc, key) => {
27
- if (acc === null || acc === void 0) return;
28
- return acc[key];
29
- }, obj);
30
- };
27
+ * 分组键的基础类型
28
+ * @description 分组条件计算后得到的标量值
29
+ */
30
+
31
+ /**
32
+ * 分组规则
33
+ * @template T - 数据项类型
34
+ * @description
35
+ * - `string`:单字段路径,支持 `'a.b.c'` 点路径
36
+ * - `string[]`:多字段组合,按顺序拼接为组合键
37
+ * - `(item, index) => GroupKey | GroupKey[]`:完全自定义分组键
38
+ */
39
+
40
+ /**
41
+ * 单个分组的结果模型
42
+ * @template T - 数据项类型
43
+ */
44
+
31
45
  /**
32
- * 将任意值规范化为可用于分组的标量键
33
- * @description null/undefined 统一归一为空字符串,对象/数组等转为字符串,避免分组键不稳定
34
- */
35
- const normalizeGroupKey = (value) => {
36
- if (value === null || value === void 0) return "";
37
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
38
- return String(value);
46
+ * 分组可选项
47
+ * @template T - 数据项类型
48
+ */
49
+
50
+ /**
51
+ * 按点路径安全取值
52
+ * @param obj - 取值对象
53
+ * @param path - 字段路径,支持 `'a.b.c'`
54
+ * @returns 路径对应的值,路径不存在时返回 undefined
55
+ * @example
56
+ * getByPath({ a: { b: 1 } }, 'a.b') // 1
57
+ * getByPath({ id: 9 }, 'id') // 9
58
+ */
59
+ export var getByPath = function getByPath(obj, path) {
60
+ if (obj === null || obj === undefined) {
61
+ return undefined;
62
+ }
63
+ if (path.indexOf('.') === -1) {
64
+ return obj[path];
65
+ }
66
+ return path.split('.').reduce(function (acc, key) {
67
+ if (acc === null || acc === undefined) {
68
+ return undefined;
69
+ }
70
+ return acc[key];
71
+ }, obj);
39
72
  };
73
+
40
74
  /**
41
- * 将数组按指定条件分组
42
- * @template T - 数据项类型
43
- * @param dataSource - 待分组的数据数组
44
- * @param spec - 分组规则,详见 {@link GroupBySpec}
45
- * @param options - 可选项(自定义 groupId、分组/组内排序)
46
- * @returns 分组结果数组,默认保持各分组首次出现的顺序、组内保持原始相对顺序
47
- * @description
48
- * 该函数为纯函数,不修改入参(排序时对内部拷贝操作)。相同分组键的数据会被归入同一分组。
49
- * @example
50
- * // 单字段
51
- * groupBy(list, 'productId');
52
- * @example
53
- * // 商品 + 时间组合
54
- * groupBy(list, ['productId', 'time']);
55
- * @example
56
- * // 自定义键
57
- * groupBy(list, (item) => `${item.productId}_${item.time}`);
58
- */
59
- const groupBy = (dataSource, spec, options = {}) => {
60
- const { getGroupId, sortGroups, sortItems } = options;
61
- const fieldNames = Array.isArray(spec) ? spec : typeof spec === "string" ? [spec] : [];
62
- const groupMap = /* @__PURE__ */ new Map();
63
- const order = [];
64
- (dataSource || []).forEach((item, index) => {
65
- let keys;
66
- if (typeof spec === "function") {
67
- const result = spec(item, index);
68
- keys = (Array.isArray(result) ? result : [result]).map(normalizeGroupKey);
69
- } else if (Array.isArray(spec)) keys = spec.map((field) => normalizeGroupKey(getByPath(item, field)));
70
- else keys = [normalizeGroupKey(getByPath(item, spec))];
71
- const groupId = getGroupId ? getGroupId(keys) : keys.join("|");
72
- let group = groupMap.get(groupId);
73
- if (!group) {
74
- const keyMap = {};
75
- fieldNames.forEach((field, i) => {
76
- keyMap[field] = keys[i];
77
- });
78
- group = {
79
- groupId,
80
- keys,
81
- keyMap,
82
- items: [],
83
- index: order.length
84
- };
85
- groupMap.set(groupId, group);
86
- order.push(groupId);
87
- }
88
- group.items.push(item);
89
- });
90
- let groups = order.map((id) => groupMap.get(id));
91
- if (sortItems) groups.forEach((group) => {
92
- group.items.sort(sortItems);
93
- });
94
- if (sortGroups) {
95
- groups = groups.slice().sort(sortGroups);
96
- groups.forEach((group, i) => {
97
- group.index = i;
98
- });
99
- }
100
- return groups;
75
+ * 将任意值规范化为可用于分组的标量键
76
+ * @description null/undefined 统一归一为空字符串,对象/数组等转为字符串,避免分组键不稳定
77
+ */
78
+ var normalizeGroupKey = function normalizeGroupKey(value) {
79
+ if (value === null || value === undefined) {
80
+ return '';
81
+ }
82
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
83
+ return value;
84
+ }
85
+ return String(value);
101
86
  };
102
- //#endregion
103
- export { getByPath, groupBy, uniqueByKey };
87
+
88
+ /**
89
+ * 将数组按指定条件分组
90
+ * @template T - 数据项类型
91
+ * @param dataSource - 待分组的数据数组
92
+ * @param spec - 分组规则,详见 {@link GroupBySpec}
93
+ * @param options - 可选项(自定义 groupId、分组/组内排序)
94
+ * @returns 分组结果数组,默认保持各分组首次出现的顺序、组内保持原始相对顺序
95
+ * @description
96
+ * 该函数为纯函数,不修改入参(排序时对内部拷贝操作)。相同分组键的数据会被归入同一分组。
97
+ * @example
98
+ * // 单字段
99
+ * groupBy(list, 'productId');
100
+ * @example
101
+ * // 商品 + 时间组合
102
+ * groupBy(list, ['productId', 'time']);
103
+ * @example
104
+ * // 自定义键
105
+ * groupBy(list, (item) => `${item.productId}_${item.time}`);
106
+ */
107
+ export var groupBy = function groupBy(dataSource, spec) {
108
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
109
+ var getGroupId = options.getGroupId,
110
+ sortGroups = options.sortGroups,
111
+ sortItems = options.sortItems;
112
+
113
+ // 仅字段型分组才有可读字段名,用于 keyMap
114
+ var fieldNames = Array.isArray(spec) ? spec : typeof spec === 'string' ? [spec] : [];
115
+ var groupMap = new Map();
116
+ var order = [];
117
+ (dataSource || []).forEach(function (item, index) {
118
+ var keys;
119
+ if (typeof spec === 'function') {
120
+ var result = spec(item, index);
121
+ keys = (Array.isArray(result) ? result : [result]).map(normalizeGroupKey);
122
+ } else if (Array.isArray(spec)) {
123
+ keys = spec.map(function (field) {
124
+ return normalizeGroupKey(getByPath(item, field));
125
+ });
126
+ } else {
127
+ keys = [normalizeGroupKey(getByPath(item, spec))];
128
+ }
129
+ var groupId = getGroupId ? getGroupId(keys) : keys.join('|');
130
+ var group = groupMap.get(groupId);
131
+ if (!group) {
132
+ var keyMap = {};
133
+ fieldNames.forEach(function (field, i) {
134
+ keyMap[field] = keys[i];
135
+ });
136
+ group = {
137
+ groupId: groupId,
138
+ keys: keys,
139
+ keyMap: keyMap,
140
+ items: [],
141
+ index: order.length
142
+ };
143
+ groupMap.set(groupId, group);
144
+ order.push(groupId);
145
+ }
146
+ group.items.push(item);
147
+ });
148
+ var groups = order.map(function (id) {
149
+ return groupMap.get(id);
150
+ });
151
+ if (sortItems) {
152
+ groups.forEach(function (group) {
153
+ group.items.sort(sortItems);
154
+ });
155
+ }
156
+ if (sortGroups) {
157
+ groups = groups.slice().sort(sortGroups);
158
+ groups.forEach(function (group, i) {
159
+ group.index = i;
160
+ });
161
+ }
162
+ return groups;
163
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 公共工具和类型导出
3
+ */
4
+ export type { DisplayState, ValidationResult } from './types';
5
+ export { getDisplayState } from './stateHelper';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 公共工具和类型导出
3
+ */
4
+
5
+ export { getDisplayState } from "./stateHelper";
@@ -1,6 +1,4 @@
1
- import { DisplayState } from "./types.js";
2
-
3
- //#region src/common/stateHelper.d.ts
1
+ import type { DisplayState } from './types';
4
2
  /**
5
3
  * 根据 mode 和 disabled 计算组件的显示状态
6
4
  *
@@ -17,6 +15,4 @@ import { DisplayState } from "./types.js";
17
15
  * getDisplayState('edit', true) // 'disabled'
18
16
  * getDisplayState('read', true) // 'disabled'
19
17
  */
20
- declare function getDisplayState(mode?: 'read' | 'edit', disabled?: boolean): DisplayState;
21
- //#endregion
22
- export { getDisplayState };
18
+ export declare function getDisplayState(mode?: 'read' | 'edit', disabled?: boolean): DisplayState;
@@ -1,23 +1,25 @@
1
- //#region src/common/stateHelper.ts
2
1
  /**
3
- * 根据 mode 和 disabled 计算组件的显示状态
4
- *
5
- * 状态优先级:disabled > mode
6
- * 当 disabled=true 时,无论 mode 是什么,都显示为禁用态
7
- *
8
- * @param mode 状态模式('read' | 'edit')
9
- * @param disabled 是否禁用
10
- * @returns 显示状态('read' | 'edit' | 'disabled')
11
- *
12
- * @example
13
- * getDisplayState('edit', false) // 'edit'
14
- * getDisplayState('read', false) // 'read'
15
- * getDisplayState('edit', true) // 'disabled'
16
- * getDisplayState('read', true) // 'disabled'
17
- */
18
- function getDisplayState(mode, disabled) {
19
- if (disabled) return "disabled";
20
- return mode || "edit";
21
- }
22
- //#endregion
23
- export { getDisplayState };
2
+ * 根据 mode 和 disabled 计算组件的显示状态
3
+ *
4
+ * 状态优先级:disabled > mode
5
+ * 当 disabled=true 时,无论 mode 是什么,都显示为禁用态
6
+ *
7
+ * @param mode 状态模式('read' | 'edit')
8
+ * @param disabled 是否禁用
9
+ * @returns 显示状态('read' | 'edit' | 'disabled')
10
+ *
11
+ * @example
12
+ * getDisplayState('edit', false) // 'edit'
13
+ * getDisplayState('read', false) // 'read'
14
+ * getDisplayState('edit', true) // 'disabled'
15
+ * getDisplayState('read', true) // 'disabled'
16
+ */
17
+ export function getDisplayState(mode, disabled) {
18
+ // disabled 优先级最高
19
+ if (disabled) {
20
+ return 'disabled';
21
+ }
22
+
23
+ // 返回基础模式,默认为 edit
24
+ return mode || 'edit';
25
+ }
@@ -1,4 +1,3 @@
1
- //#region src/common/types.d.ts
2
1
  /**
3
2
  * 公共类型定义
4
3
  * 供所有输入组件使用
@@ -11,21 +10,19 @@
11
10
  * - edit: 编辑态,显示输入控件
12
11
  * - disabled: 禁用态,禁用的输入控件
13
12
  */
14
- type DisplayState = 'read' | 'edit' | 'disabled';
13
+ export declare type DisplayState = 'read' | 'edit' | 'disabled';
15
14
  /**
16
15
  * 校验结果类型
17
16
  *
18
17
  * 所有输入组件的校验结果统一格式
19
18
  */
20
- interface ValidationResult {
21
- /**
22
- * 是否校验通过
23
- */
24
- isValid: boolean;
25
- /**
26
- * 错误信息数组
27
- */
28
- errors: string[];
19
+ export interface ValidationResult {
20
+ /**
21
+ * 是否校验通过
22
+ */
23
+ isValid: boolean;
24
+ /**
25
+ * 错误信息数组
26
+ */
27
+ errors: string[];
29
28
  }
30
- //#endregion
31
- export { DisplayState, ValidationResult };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,38 +1,36 @@
1
- //#region src/componentStorage.d.ts
2
1
  /** 生成存储 key 的路径后缀:pathname 或 pathname#memory_key(来自 URL memory_key 参数) */
3
- declare function getStorageKeySuffix(): string;
2
+ export declare function getStorageKeySuffix(): string;
4
3
  /**
5
4
  * 生成组件实例的存储 key。
6
5
  * @param componentId 组件实例 id(如 __id)
7
6
  * @param prefix 前缀,如 'table-setting'、'record-board-column-visibility'
8
7
  */
9
- declare function getComponentStorageKey(componentId: string, prefix: string): string;
10
- interface ColumnSettingStorageItem {
11
- key: string;
12
- dataIndex: string;
13
- title?: unknown;
14
- titleString?: string;
15
- isShow: boolean;
16
- sortIndex?: number;
17
- fixed?: 'left' | 'right' | boolean;
8
+ export declare function getComponentStorageKey(componentId: string, prefix: string): string;
9
+ export interface ColumnSettingStorageItem {
10
+ key: string;
11
+ dataIndex: string;
12
+ title?: unknown;
13
+ titleString?: string;
14
+ isShow: boolean;
15
+ sortIndex?: number;
16
+ fixed?: 'left' | 'right' | boolean;
18
17
  }
19
- declare function saveColumnSettingToLocal(params: {
20
- componentId: string;
21
- columnSetting: ColumnSettingStorageItem[];
18
+ export declare function saveColumnSettingToLocal(params: {
19
+ componentId: string;
20
+ columnSetting: ColumnSettingStorageItem[];
22
21
  }): void;
23
- declare function getColumnSettingFromLocal(componentId?: string): ColumnSettingStorageItem[] | null;
24
- declare function clearColumnSettingFromLocal(componentId?: string): void;
25
- declare function saveColumnVisibilityToLocal(params: {
26
- componentId: string;
27
- columnVisibility: Record<string, boolean>; /** 列 key 顺序,用于列设置弹层拖拽排序后持久化 */
28
- columnOrder?: string[];
22
+ export declare function getColumnSettingFromLocal(componentId?: string): ColumnSettingStorageItem[] | null;
23
+ export declare function clearColumnSettingFromLocal(componentId?: string): void;
24
+ export declare function saveColumnVisibilityToLocal(params: {
25
+ componentId: string;
26
+ columnVisibility: Record<string, boolean>;
27
+ /** 列 key 顺序,用于列设置弹层拖拽排序后持久化 */
28
+ columnOrder?: string[];
29
29
  }): void;
30
- declare function getColumnVisibilityFromLocal(componentId?: string): Record<string, boolean> | null;
30
+ export declare function getColumnVisibilityFromLocal(componentId?: string): Record<string, boolean> | null;
31
31
  /** RecordBoard 列设置(显隐 + 顺序)从 localStorage 读取,用于列设置弹层拖拽排序与显隐持久化 */
32
- declare function getRecordBoardColumnSettingFromLocal(componentId?: string): {
33
- columnVisibility: Record<string, boolean>;
34
- columnOrder: string[] | null;
32
+ export declare function getRecordBoardColumnSettingFromLocal(componentId?: string): {
33
+ columnVisibility: Record<string, boolean>;
34
+ columnOrder: string[] | null;
35
35
  } | null;
36
- declare function clearColumnVisibilityFromLocal(componentId?: string): void;
37
- //#endregion
38
- export { ColumnSettingStorageItem, clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getRecordBoardColumnSettingFromLocal, getStorageKeySuffix, saveColumnSettingToLocal, saveColumnVisibilityToLocal };
36
+ export declare function clearColumnVisibilityFromLocal(componentId?: string): void;