@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
@@ -1 +1,73 @@
1
1
  export declare const uniqueByKey: <T>(arr: T[], key: keyof T) => T[];
2
+ /**
3
+ * 分组键的基础类型
4
+ * @description 分组条件计算后得到的标量值
5
+ */
6
+ export declare type GroupKey = string | number | boolean;
7
+ /**
8
+ * 分组规则
9
+ * @template T - 数据项类型
10
+ * @description
11
+ * - `string`:单字段路径,支持 `'a.b.c'` 点路径
12
+ * - `string[]`:多字段组合,按顺序拼接为组合键
13
+ * - `(item, index) => GroupKey | GroupKey[]`:完全自定义分组键
14
+ */
15
+ export declare type GroupBySpec<T> = string | string[] | ((item: T, index: number) => GroupKey | GroupKey[]);
16
+ /**
17
+ * 单个分组的结果模型
18
+ * @template T - 数据项类型
19
+ */
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;
31
+ }
32
+ /**
33
+ * 分组可选项
34
+ * @template T - 数据项类型
35
+ */
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;
43
+ }
44
+ /**
45
+ * 按点路径安全取值
46
+ * @param obj - 取值对象
47
+ * @param path - 字段路径,支持 `'a.b.c'`
48
+ * @returns 路径对应的值,路径不存在时返回 undefined
49
+ * @example
50
+ * getByPath({ a: { b: 1 } }, 'a.b') // 1
51
+ * getByPath({ id: 9 }, 'id') // 9
52
+ */
53
+ export declare const getByPath: (obj: unknown, path: string) => unknown;
54
+ /**
55
+ * 将数组按指定条件分组
56
+ * @template T - 数据项类型
57
+ * @param dataSource - 待分组的数据数组
58
+ * @param spec - 分组规则,详见 {@link GroupBySpec}
59
+ * @param options - 可选项(自定义 groupId、分组/组内排序)
60
+ * @returns 分组结果数组,默认保持各分组首次出现的顺序、组内保持原始相对顺序
61
+ * @description
62
+ * 该函数为纯函数,不修改入参(排序时对内部拷贝操作)。相同分组键的数据会被归入同一分组。
63
+ * @example
64
+ * // 单字段
65
+ * groupBy(list, 'productId');
66
+ * @example
67
+ * // 商品 + 时间组合
68
+ * groupBy(list, ['productId', 'time']);
69
+ * @example
70
+ * // 自定义键
71
+ * groupBy(list, (item) => `${item.productId}_${item.time}`);
72
+ */
73
+ export declare const groupBy: <T>(dataSource: T[], spec: GroupBySpec<T>, options?: GroupByOptions<T>) => GroupResult<T>[];
package/es/arrayUtils.js CHANGED
@@ -8,11 +8,11 @@ export var uniqueByKey = function uniqueByKey(arr, key) {
8
8
  _step;
9
9
  try {
10
10
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
11
- var item = _step.value;
12
- var keyValue = item[key];
11
+ var _item = _step.value;
12
+ var keyValue = _item[key];
13
13
  if (!seen.has(keyValue)) {
14
14
  seen.add(keyValue);
15
- result.push(item);
15
+ result.push(_item);
16
16
  }
17
17
  }
18
18
  } catch (err) {
@@ -21,4 +21,143 @@ export var uniqueByKey = function uniqueByKey(arr, key) {
21
21
  _iterator.f();
22
22
  }
23
23
  return result;
24
+ };
25
+
26
+ /**
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
+
45
+ /**
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);
72
+ };
73
+
74
+ /**
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);
86
+ };
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;
24
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";
@@ -0,0 +1,18 @@
1
+ import type { DisplayState } from './types';
2
+ /**
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
+ export declare function getDisplayState(mode?: 'read' | 'edit', disabled?: boolean): DisplayState;
@@ -0,0 +1,25 @@
1
+ /**
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
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 公共类型定义
3
+ * 供所有输入组件使用
4
+ */
5
+ /**
6
+ * 显示状态类型
7
+ *
8
+ * 所有输入组件的三种状态:
9
+ * - read: 只读态,纯文本展示
10
+ * - edit: 编辑态,显示输入控件
11
+ * - disabled: 禁用态,禁用的输入控件
12
+ */
13
+ export declare type DisplayState = 'read' | 'edit' | 'disabled';
14
+ /**
15
+ * 校验结果类型
16
+ *
17
+ * 所有输入组件的校验结果统一格式
18
+ */
19
+ export interface ValidationResult {
20
+ /**
21
+ * 是否校验通过
22
+ */
23
+ isValid: boolean;
24
+ /**
25
+ * 错误信息数组
26
+ */
27
+ errors: string[];
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ /** 生成存储 key 的路径后缀:pathname 或 pathname#memory_key(来自 URL memory_key 参数) */
2
+ export declare function getStorageKeySuffix(): string;
3
+ /**
4
+ * 生成组件实例的存储 key。
5
+ * @param componentId 组件实例 id(如 __id)
6
+ * @param prefix 前缀,如 'table-setting'、'record-board-column-visibility'
7
+ */
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;
17
+ }
18
+ export declare function saveColumnSettingToLocal(params: {
19
+ componentId: string;
20
+ columnSetting: ColumnSettingStorageItem[];
21
+ }): void;
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
+ }): void;
30
+ export declare function getColumnVisibilityFromLocal(componentId?: string): Record<string, boolean> | null;
31
+ /** RecordBoard 列设置(显隐 + 顺序)从 localStorage 读取,用于列设置弹层拖拽排序与显隐持久化 */
32
+ export declare function getRecordBoardColumnSettingFromLocal(componentId?: string): {
33
+ columnVisibility: Record<string, boolean>;
34
+ columnOrder: string[] | null;
35
+ } | null;
36
+ export declare function clearColumnVisibilityFromLocal(componentId?: string): void;
@@ -0,0 +1,142 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ /**
8
+ * 组件级 localStorage 存储:列设置、列显隐等。
9
+ * 供 pisellDataSourceContainer、pisellRecordBoard 等复用,key 含 pathname 与 memory_key 以区分页面。
10
+ */
11
+ import { isJson } from "./typeUtils";
12
+
13
+ /** 生成存储 key 的路径后缀:pathname 或 pathname#memory_key(来自 URL memory_key 参数) */
14
+ export function getStorageKeySuffix() {
15
+ if (typeof window === 'undefined' || typeof window.location === 'undefined') {
16
+ return '/';
17
+ }
18
+ var _window$location = window.location,
19
+ pathname = _window$location.pathname,
20
+ search = _window$location.search;
21
+ var appendPath = pathname || '/';
22
+ var memoryKey = '';
23
+ try {
24
+ var params = new URLSearchParams(search || '');
25
+ var mk = params.get('memory_key');
26
+ if (mk && mk.trim() !== '') memoryKey = mk.trim();
27
+ } catch (_unused) {
28
+ // ignore
29
+ }
30
+ return memoryKey ? "".concat(appendPath, "#").concat(memoryKey) : appendPath;
31
+ }
32
+
33
+ /**
34
+ * 生成组件实例的存储 key。
35
+ * @param componentId 组件实例 id(如 __id)
36
+ * @param prefix 前缀,如 'table-setting'、'record-board-column-visibility'
37
+ */
38
+ export function getComponentStorageKey(componentId, prefix) {
39
+ if (typeof window === 'undefined' || typeof window.location === 'undefined') {
40
+ return "".concat(prefix, "-").concat(componentId);
41
+ }
42
+ var suffix = getStorageKeySuffix();
43
+ return "".concat(prefix, "-").concat(componentId, "-").concat(suffix);
44
+ }
45
+
46
+ // ---------- 列设置(DataSourceContainer Table 列显隐+排序等,数组格式) ----------
47
+
48
+ export function saveColumnSettingToLocal(params) {
49
+ var componentId = params.componentId,
50
+ columnSetting = params.columnSetting;
51
+ if (!componentId) return;
52
+ if (typeof window === 'undefined' || !window.localStorage) return;
53
+ var storageKey = getComponentStorageKey(componentId, 'table-setting');
54
+ var data = {
55
+ column_setting: columnSetting,
56
+ updatedAt: Date.now()
57
+ };
58
+ try {
59
+ window.localStorage.setItem(storageKey, JSON.stringify(data));
60
+ } catch (_unused2) {
61
+ // ignore
62
+ }
63
+ }
64
+ export function getColumnSettingFromLocal(componentId) {
65
+ if (!componentId) return null;
66
+ if (typeof window === 'undefined' || !window.localStorage) return null;
67
+ var storageKey = getComponentStorageKey(componentId, 'table-setting');
68
+ var raw = window.localStorage.getItem(storageKey);
69
+ if (raw && isJson(raw)) {
70
+ var data = JSON.parse(raw);
71
+ var arr = data === null || data === void 0 ? void 0 : data.column_setting;
72
+ return Array.isArray(arr) ? arr : null;
73
+ }
74
+ return null;
75
+ }
76
+ export function clearColumnSettingFromLocal(componentId) {
77
+ if (!componentId) return;
78
+ if (typeof window === 'undefined' || !window.localStorage) return;
79
+ var storageKey = getComponentStorageKey(componentId, 'table-setting');
80
+ window.localStorage.removeItem(storageKey);
81
+ }
82
+
83
+ // ---------- 列显隐(RecordBoard,Record<列 key, boolean> 格式) ----------
84
+
85
+ var RECORD_BOARD_VISIBILITY_PREFIX = 'record-board-column-visibility';
86
+ export function saveColumnVisibilityToLocal(params) {
87
+ var componentId = params.componentId,
88
+ columnVisibility = params.columnVisibility,
89
+ columnOrder = params.columnOrder;
90
+ if (!componentId) return;
91
+ if (typeof window === 'undefined' || !window.localStorage) return;
92
+ var storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
93
+ var data = _objectSpread(_objectSpread({
94
+ column_visibility: columnVisibility
95
+ }, columnOrder != null && {
96
+ column_order: columnOrder
97
+ }), {}, {
98
+ updatedAt: Date.now()
99
+ });
100
+ try {
101
+ window.localStorage.setItem(storageKey, JSON.stringify(data));
102
+ } catch (_unused3) {
103
+ // ignore
104
+ }
105
+ }
106
+ export function getColumnVisibilityFromLocal(componentId) {
107
+ if (!componentId) return null;
108
+ if (typeof window === 'undefined' || !window.localStorage) return null;
109
+ var storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
110
+ var raw = window.localStorage.getItem(storageKey);
111
+ if (raw && isJson(raw)) {
112
+ var data = JSON.parse(raw);
113
+ var vis = data === null || data === void 0 ? void 0 : data.column_visibility;
114
+ return vis && _typeof(vis) === 'object' && vis !== null ? vis : null;
115
+ }
116
+ return null;
117
+ }
118
+
119
+ /** RecordBoard 列设置(显隐 + 顺序)从 localStorage 读取,用于列设置弹层拖拽排序与显隐持久化 */
120
+ export function getRecordBoardColumnSettingFromLocal(componentId) {
121
+ if (!componentId) return null;
122
+ if (typeof window === 'undefined' || !window.localStorage) return null;
123
+ var storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
124
+ var raw = window.localStorage.getItem(storageKey);
125
+ if (raw && isJson(raw)) {
126
+ var data = JSON.parse(raw);
127
+ var vis = data === null || data === void 0 ? void 0 : data.column_visibility;
128
+ var columnVisibility = vis && _typeof(vis) === 'object' && vis !== null ? vis : {};
129
+ var columnOrder = Array.isArray(data === null || data === void 0 ? void 0 : data.column_order) ? data.column_order : null;
130
+ return {
131
+ columnVisibility: columnVisibility,
132
+ columnOrder: columnOrder
133
+ };
134
+ }
135
+ return null;
136
+ }
137
+ export function clearColumnVisibilityFromLocal(componentId) {
138
+ if (!componentId) return;
139
+ if (typeof window === 'undefined' || !window.localStorage) return;
140
+ var storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
141
+ window.localStorage.removeItem(storageKey);
142
+ }
package/es/format.d.ts CHANGED
@@ -18,6 +18,10 @@ export declare type FormatOptions = {
18
18
  useThousandsSeparator?: boolean;
19
19
  /** 整数位隐藏小数 指的是如果价格为整数,后面的".00" 将被省略以节省页面空间 */
20
20
  hideDecimalForWholeNumbers?: boolean;
21
+ /** 货币代码或虚拟币单位后缀 */
22
+ currencyCode?: string;
23
+ /** 货币展示格式,支持预置值和金额模板 */
24
+ currencyFormat?: string;
21
25
  };
22
26
  /**
23
27
  * 根据配置格式化金额
@@ -25,4 +29,4 @@ export declare type FormatOptions = {
25
29
  * @param symbol
26
30
  * @param options
27
31
  */
28
- export declare const formatAmountWithOptions: (amount: string | number | undefined, symbol: string | undefined, options: FormatOptions) => string | number;
32
+ export declare const formatAmountWithOptions: (amount?: number | string, symbol?: string, options?: FormatOptions) => string | number;
package/es/format.js CHANGED
@@ -53,6 +53,24 @@ export var formatAmount = function formatAmount() {
53
53
  return amount;
54
54
  }
55
55
  };
56
+ var applyCurrencyFormat = function applyCurrencyFormat(params) {
57
+ var amount = params.amount,
58
+ symbol = params.symbol,
59
+ currencyCode = params.currencyCode,
60
+ currencyFormat = params.currencyFormat;
61
+ var format = currencyFormat.trim();
62
+ if (format.includes('{{amount}}') || format.includes('{amount}')) {
63
+ return format.split('{{amount}}').join(amount).split('{{sym}}').join(symbol).split('{{unit}}').join(currencyCode).split('{{symbol}}').join(symbol).split('{{unit_label}}').join(currencyCode).split('{{currency_code}}').join(currencyCode).split('{amount}').join(amount).split('{sym}').join(symbol).split('{unit}').join(currencyCode).split('{symbol}').join(symbol).split('{unit_label}').join(currencyCode).split('{currency_code}').join(currencyCode).trim();
64
+ }
65
+ if (format === 'symbol_last') {
66
+ if (symbol) return "".concat(amount).concat(symbol);
67
+ if (currencyCode) return "".concat(amount, " ").concat(currencyCode);
68
+ return amount;
69
+ }
70
+ if (symbol) return "".concat(symbol).concat(amount);
71
+ return currencyCode ? "".concat(amount, " ").concat(currencyCode) : amount;
72
+ };
73
+
56
74
  /**
57
75
  * 根据配置格式化金额
58
76
  * @param amount
@@ -62,7 +80,7 @@ export var formatAmount = function formatAmount() {
62
80
  export var formatAmountWithOptions = function formatAmountWithOptions() {
63
81
  var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
64
82
  var symbol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
65
- var options = arguments.length > 2 ? arguments[2] : undefined;
83
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
66
84
  var _options$precision = options.precision,
67
85
  precision = _options$precision === void 0 ? 2 : _options$precision,
68
86
  _options$useThousands = options.useThousandsSeparator,
@@ -70,7 +88,11 @@ export var formatAmountWithOptions = function formatAmountWithOptions() {
70
88
  _options$showCurrency = options.showCurrencySymbol,
71
89
  showCurrencySymbol = _options$showCurrency === void 0 ? true : _options$showCurrency,
72
90
  _options$hideDecimalF = options.hideDecimalForWholeNumbers,
73
- hideDecimalForWholeNumbers = _options$hideDecimalF === void 0 ? true : _options$hideDecimalF;
91
+ hideDecimalForWholeNumbers = _options$hideDecimalF === void 0 ? true : _options$hideDecimalF,
92
+ _options$currencyCode = options.currencyCode,
93
+ currencyCode = _options$currencyCode === void 0 ? '' : _options$currencyCode,
94
+ _options$currencyForm = options.currencyFormat,
95
+ currencyFormat = _options$currencyForm === void 0 ? '' : _options$currencyForm;
74
96
  // 校验格式
75
97
  if (!isString(amount) && !isNumber(amount)) {
76
98
  console.error('amount is not a number');
@@ -86,22 +108,45 @@ export var formatAmountWithOptions = function formatAmountWithOptions() {
86
108
  // 截取小数部分并补零
87
109
  var decimalPart = (absoluteAmount - integerPart).toFixed(precision).substring(2);
88
110
 
111
+ // 新配置缺省时完整保留历史逻辑,避免影响现有调用方。
112
+ if (!currencyCode && !currencyFormat) {
113
+ var legacyFormattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
114
+ legacyFormattedAmount = showCurrencySymbol ? symbol + legacyFormattedAmount : legacyFormattedAmount;
115
+ if (precision > 0) {
116
+ legacyFormattedAmount += '.' + decimalPart;
117
+ if (hideDecimalForWholeNumbers && legacyFormattedAmount.indexOf('.00') !== -1) {
118
+ legacyFormattedAmount = legacyFormattedAmount.substring(0, legacyFormattedAmount.length - 3);
119
+ }
120
+ }
121
+ if (roundedAmount < 0) {
122
+ legacyFormattedAmount = '-' + legacyFormattedAmount;
123
+ }
124
+ return legacyFormattedAmount;
125
+ }
126
+
89
127
  // 增加千分位分隔符
90
128
  var formattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
91
129
 
92
- // 拼接货币符号
93
- formattedAmount = showCurrencySymbol ? symbol + formattedAmount : formattedAmount;
94
-
95
130
  // 添加小数点
96
131
  if (precision > 0) {
97
132
  formattedAmount += '.' + decimalPart;
98
133
 
99
- // 如果小数位是 .00的话 抹去
100
- if (hideDecimalForWholeNumbers && formattedAmount.indexOf('.00') !== -1) {
101
- formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
134
+ // 整数按配置隐藏全部小数位
135
+ if (hideDecimalForWholeNumbers && Number(decimalPart) === 0) {
136
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - precision - 1);
102
137
  }
103
138
  }
104
139
 
140
+ // 数值精度与币种排版分开处理,便于共享法币和虚拟币规则
141
+ if (showCurrencySymbol) {
142
+ formattedAmount = applyCurrencyFormat({
143
+ amount: formattedAmount,
144
+ symbol: symbol,
145
+ currencyCode: currencyCode,
146
+ currencyFormat: currencyFormat
147
+ });
148
+ }
149
+
105
150
  // 添加负号
106
151
  if (roundedAmount < 0) {
107
152
  formattedAmount = '-' + formattedAmount;
package/es/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './otherUtils';
2
2
  export * from './typeUtils';
3
+ export * from './componentStorage';
3
4
  export * from './document';
4
5
  export * from './date';
5
6
  export * from './platform';
@@ -12,6 +13,11 @@ export * from './image';
12
13
  export * from './locales';
13
14
  export * from './arrayUtils';
14
15
  export * from './walletValidity';
16
+ export * from './weighing';
17
+ export * from './common';
18
+ export * from './text-input';
19
+ export * from './number-input';
20
+ export * from './select';
15
21
  export declare const setPisellUtilsConfig: (config: {
16
22
  [key: string]: any;
17
23
  }) => void;
package/es/index.js CHANGED
@@ -6,6 +6,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  export * from "./otherUtils";
8
8
  export * from "./typeUtils";
9
+ export * from "./componentStorage";
9
10
  export * from "./document";
10
11
  export * from "./date";
11
12
  export * from "./platform";
@@ -18,6 +19,11 @@ export * from "./image";
18
19
  export * from "./locales";
19
20
  export * from "./arrayUtils";
20
21
  export * from "./walletValidity";
22
+ export * from "./weighing";
23
+ export * from "./common";
24
+ export * from "./text-input";
25
+ export * from "./number-input";
26
+ export * from "./select";
21
27
  // export { default as firebase } from './firebase';
22
28
 
23
29
  export var setPisellUtilsConfig = function setPisellUtilsConfig(config) {