@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
package/lib/arrayUtils.js CHANGED
@@ -19,6 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/arrayUtils.ts
20
20
  var arrayUtils_exports = {};
21
21
  __export(arrayUtils_exports, {
22
+ getByPath: () => getByPath,
23
+ groupBy: () => groupBy,
22
24
  uniqueByKey: () => uniqueByKey
23
25
  });
24
26
  module.exports = __toCommonJS(arrayUtils_exports);
@@ -34,7 +36,80 @@ var uniqueByKey = (arr, key) => {
34
36
  }
35
37
  return result;
36
38
  };
39
+ var getByPath = (obj, path) => {
40
+ if (obj === null || obj === void 0) {
41
+ return void 0;
42
+ }
43
+ if (path.indexOf(".") === -1) {
44
+ return obj[path];
45
+ }
46
+ return path.split(".").reduce((acc, key) => {
47
+ if (acc === null || acc === void 0) {
48
+ return void 0;
49
+ }
50
+ return acc[key];
51
+ }, obj);
52
+ };
53
+ var normalizeGroupKey = (value) => {
54
+ if (value === null || value === void 0) {
55
+ return "";
56
+ }
57
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
58
+ return value;
59
+ }
60
+ return String(value);
61
+ };
62
+ var groupBy = (dataSource, spec, options = {}) => {
63
+ const { getGroupId, sortGroups, sortItems } = options;
64
+ const fieldNames = Array.isArray(spec) ? spec : typeof spec === "string" ? [spec] : [];
65
+ const groupMap = /* @__PURE__ */ new Map();
66
+ const order = [];
67
+ (dataSource || []).forEach((item, index) => {
68
+ let keys;
69
+ if (typeof spec === "function") {
70
+ const result = spec(item, index);
71
+ keys = (Array.isArray(result) ? result : [result]).map(normalizeGroupKey);
72
+ } else if (Array.isArray(spec)) {
73
+ keys = spec.map((field) => normalizeGroupKey(getByPath(item, field)));
74
+ } else {
75
+ keys = [normalizeGroupKey(getByPath(item, spec))];
76
+ }
77
+ const groupId = getGroupId ? getGroupId(keys) : keys.join("|");
78
+ let group = groupMap.get(groupId);
79
+ if (!group) {
80
+ const keyMap = {};
81
+ fieldNames.forEach((field, i) => {
82
+ keyMap[field] = keys[i];
83
+ });
84
+ group = {
85
+ groupId,
86
+ keys,
87
+ keyMap,
88
+ items: [],
89
+ index: order.length
90
+ };
91
+ groupMap.set(groupId, group);
92
+ order.push(groupId);
93
+ }
94
+ group.items.push(item);
95
+ });
96
+ let groups = order.map((id) => groupMap.get(id));
97
+ if (sortItems) {
98
+ groups.forEach((group) => {
99
+ group.items.sort(sortItems);
100
+ });
101
+ }
102
+ if (sortGroups) {
103
+ groups = groups.slice().sort(sortGroups);
104
+ groups.forEach((group, i) => {
105
+ group.index = i;
106
+ });
107
+ }
108
+ return groups;
109
+ };
37
110
  // Annotate the CommonJS export names for ESM import in node:
38
111
  0 && (module.exports = {
112
+ getByPath,
113
+ groupBy,
39
114
  uniqueByKey
40
115
  });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 公共工具和类型导出
3
+ */
4
+ export type { DisplayState, ValidationResult } from './types';
5
+ export { getDisplayState } from './stateHelper';
@@ -0,0 +1,29 @@
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/common/index.ts
20
+ var common_exports = {};
21
+ __export(common_exports, {
22
+ getDisplayState: () => import_stateHelper.getDisplayState
23
+ });
24
+ module.exports = __toCommonJS(common_exports);
25
+ var import_stateHelper = require("./stateHelper");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ getDisplayState
29
+ });
@@ -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,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/common/stateHelper.ts
20
+ var stateHelper_exports = {};
21
+ __export(stateHelper_exports, {
22
+ getDisplayState: () => getDisplayState
23
+ });
24
+ module.exports = __toCommonJS(stateHelper_exports);
25
+ function getDisplayState(mode, disabled) {
26
+ if (disabled) {
27
+ return "disabled";
28
+ }
29
+ return mode || "edit";
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ getDisplayState
34
+ });
@@ -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,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/common/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -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,144 @@
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/componentStorage.ts
20
+ var componentStorage_exports = {};
21
+ __export(componentStorage_exports, {
22
+ clearColumnSettingFromLocal: () => clearColumnSettingFromLocal,
23
+ clearColumnVisibilityFromLocal: () => clearColumnVisibilityFromLocal,
24
+ getColumnSettingFromLocal: () => getColumnSettingFromLocal,
25
+ getColumnVisibilityFromLocal: () => getColumnVisibilityFromLocal,
26
+ getComponentStorageKey: () => getComponentStorageKey,
27
+ getRecordBoardColumnSettingFromLocal: () => getRecordBoardColumnSettingFromLocal,
28
+ getStorageKeySuffix: () => getStorageKeySuffix,
29
+ saveColumnSettingToLocal: () => saveColumnSettingToLocal,
30
+ saveColumnVisibilityToLocal: () => saveColumnVisibilityToLocal
31
+ });
32
+ module.exports = __toCommonJS(componentStorage_exports);
33
+ var import_typeUtils = require("./typeUtils");
34
+ function getStorageKeySuffix() {
35
+ if (typeof window === "undefined" || typeof window.location === "undefined") {
36
+ return "/";
37
+ }
38
+ const { pathname, search } = window.location;
39
+ const appendPath = pathname || "/";
40
+ let memoryKey = "";
41
+ try {
42
+ const params = new URLSearchParams(search || "");
43
+ const mk = params.get("memory_key");
44
+ if (mk && mk.trim() !== "") memoryKey = mk.trim();
45
+ } catch {
46
+ }
47
+ return memoryKey ? `${appendPath}#${memoryKey}` : appendPath;
48
+ }
49
+ function getComponentStorageKey(componentId, prefix) {
50
+ if (typeof window === "undefined" || typeof window.location === "undefined") {
51
+ return `${prefix}-${componentId}`;
52
+ }
53
+ const suffix = getStorageKeySuffix();
54
+ return `${prefix}-${componentId}-${suffix}`;
55
+ }
56
+ function saveColumnSettingToLocal(params) {
57
+ const { componentId, columnSetting } = params;
58
+ if (!componentId) return;
59
+ if (typeof window === "undefined" || !window.localStorage) return;
60
+ const storageKey = getComponentStorageKey(componentId, "table-setting");
61
+ const data = { column_setting: columnSetting, updatedAt: Date.now() };
62
+ try {
63
+ window.localStorage.setItem(storageKey, JSON.stringify(data));
64
+ } catch {
65
+ }
66
+ }
67
+ function getColumnSettingFromLocal(componentId) {
68
+ if (!componentId) return null;
69
+ if (typeof window === "undefined" || !window.localStorage) return null;
70
+ const storageKey = getComponentStorageKey(componentId, "table-setting");
71
+ const raw = window.localStorage.getItem(storageKey);
72
+ if (raw && (0, import_typeUtils.isJson)(raw)) {
73
+ const data = JSON.parse(raw);
74
+ const arr = data == null ? void 0 : data.column_setting;
75
+ return Array.isArray(arr) ? arr : null;
76
+ }
77
+ return null;
78
+ }
79
+ function clearColumnSettingFromLocal(componentId) {
80
+ if (!componentId) return;
81
+ if (typeof window === "undefined" || !window.localStorage) return;
82
+ const storageKey = getComponentStorageKey(componentId, "table-setting");
83
+ window.localStorage.removeItem(storageKey);
84
+ }
85
+ var RECORD_BOARD_VISIBILITY_PREFIX = "record-board-column-visibility";
86
+ function saveColumnVisibilityToLocal(params) {
87
+ const { componentId, columnVisibility, columnOrder } = params;
88
+ if (!componentId) return;
89
+ if (typeof window === "undefined" || !window.localStorage) return;
90
+ const storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
91
+ const data = {
92
+ column_visibility: columnVisibility,
93
+ ...columnOrder != null && { column_order: columnOrder },
94
+ updatedAt: Date.now()
95
+ };
96
+ try {
97
+ window.localStorage.setItem(storageKey, JSON.stringify(data));
98
+ } catch {
99
+ }
100
+ }
101
+ function getColumnVisibilityFromLocal(componentId) {
102
+ if (!componentId) return null;
103
+ if (typeof window === "undefined" || !window.localStorage) return null;
104
+ const storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
105
+ const raw = window.localStorage.getItem(storageKey);
106
+ if (raw && (0, import_typeUtils.isJson)(raw)) {
107
+ const data = JSON.parse(raw);
108
+ const vis = data == null ? void 0 : data.column_visibility;
109
+ return vis && typeof vis === "object" && vis !== null ? vis : null;
110
+ }
111
+ return null;
112
+ }
113
+ function getRecordBoardColumnSettingFromLocal(componentId) {
114
+ if (!componentId) return null;
115
+ if (typeof window === "undefined" || !window.localStorage) return null;
116
+ const storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
117
+ const raw = window.localStorage.getItem(storageKey);
118
+ if (raw && (0, import_typeUtils.isJson)(raw)) {
119
+ const data = JSON.parse(raw);
120
+ const vis = data == null ? void 0 : data.column_visibility;
121
+ const columnVisibility = vis && typeof vis === "object" && vis !== null ? vis : {};
122
+ const columnOrder = Array.isArray(data == null ? void 0 : data.column_order) ? data.column_order : null;
123
+ return { columnVisibility, columnOrder };
124
+ }
125
+ return null;
126
+ }
127
+ function clearColumnVisibilityFromLocal(componentId) {
128
+ if (!componentId) return;
129
+ if (typeof window === "undefined" || !window.localStorage) return;
130
+ const storageKey = getComponentStorageKey(componentId, RECORD_BOARD_VISIBILITY_PREFIX);
131
+ window.localStorage.removeItem(storageKey);
132
+ }
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ clearColumnSettingFromLocal,
136
+ clearColumnVisibilityFromLocal,
137
+ getColumnSettingFromLocal,
138
+ getColumnVisibilityFromLocal,
139
+ getComponentStorageKey,
140
+ getRecordBoardColumnSettingFromLocal,
141
+ getStorageKeySuffix,
142
+ saveColumnSettingToLocal,
143
+ saveColumnVisibilityToLocal
144
+ });
package/lib/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/lib/format.js CHANGED
@@ -53,12 +53,28 @@ var formatAmount = (amount = 0, precision = 2, symbol = "") => {
53
53
  return amount;
54
54
  }
55
55
  };
56
- var formatAmountWithOptions = (amount = 0, symbol = "", options) => {
56
+ var applyCurrencyFormat = (params) => {
57
+ const { amount, symbol, currencyCode, currencyFormat } = params;
58
+ const format = currencyFormat.trim();
59
+ if (format.includes("{{amount}}") || format.includes("{amount}")) {
60
+ 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();
61
+ }
62
+ if (format === "symbol_last") {
63
+ if (symbol) return `${amount}${symbol}`;
64
+ if (currencyCode) return `${amount} ${currencyCode}`;
65
+ return amount;
66
+ }
67
+ if (symbol) return `${symbol}${amount}`;
68
+ return currencyCode ? `${amount} ${currencyCode}` : amount;
69
+ };
70
+ var formatAmountWithOptions = (amount = 0, symbol = "", options = {}) => {
57
71
  const {
58
72
  precision = 2,
59
73
  useThousandsSeparator = false,
60
74
  showCurrencySymbol = true,
61
- hideDecimalForWholeNumbers = true
75
+ hideDecimalForWholeNumbers = true,
76
+ currencyCode = "",
77
+ currencyFormat = ""
62
78
  } = options;
63
79
  if (!(0, import_typeUtils.isString)(amount) && !(0, import_typeUtils.isNumber)(amount)) {
64
80
  console.error("amount is not a number");
@@ -69,17 +85,41 @@ var formatAmountWithOptions = (amount = 0, symbol = "", options) => {
69
85
  const absoluteAmount = Math.abs(roundedAmount);
70
86
  const integerPart = Math.floor(absoluteAmount);
71
87
  const decimalPart = (absoluteAmount - integerPart).toFixed(precision).substring(2);
88
+ if (!currencyCode && !currencyFormat) {
89
+ let legacyFormattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
90
+ legacyFormattedAmount = showCurrencySymbol ? symbol + legacyFormattedAmount : legacyFormattedAmount;
91
+ if (precision > 0) {
92
+ legacyFormattedAmount += "." + decimalPart;
93
+ if (hideDecimalForWholeNumbers && legacyFormattedAmount.indexOf(".00") !== -1) {
94
+ legacyFormattedAmount = legacyFormattedAmount.substring(
95
+ 0,
96
+ legacyFormattedAmount.length - 3
97
+ );
98
+ }
99
+ }
100
+ if (roundedAmount < 0) {
101
+ legacyFormattedAmount = "-" + legacyFormattedAmount;
102
+ }
103
+ return legacyFormattedAmount;
104
+ }
72
105
  let formattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
73
- formattedAmount = showCurrencySymbol ? symbol + formattedAmount : formattedAmount;
74
106
  if (precision > 0) {
75
107
  formattedAmount += "." + decimalPart;
76
- if (hideDecimalForWholeNumbers && formattedAmount.indexOf(".00") !== -1) {
108
+ if (hideDecimalForWholeNumbers && Number(decimalPart) === 0) {
77
109
  formattedAmount = formattedAmount.substring(
78
110
  0,
79
- formattedAmount.length - 3
111
+ formattedAmount.length - precision - 1
80
112
  );
81
113
  }
82
114
  }
115
+ if (showCurrencySymbol) {
116
+ formattedAmount = applyCurrencyFormat({
117
+ amount: formattedAmount,
118
+ symbol,
119
+ currencyCode,
120
+ currencyFormat
121
+ });
122
+ }
83
123
  if (roundedAmount < 0) {
84
124
  formattedAmount = "-" + formattedAmount;
85
125
  }
package/lib/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/lib/index.js CHANGED
@@ -26,6 +26,7 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
  __reExport(src_exports, require("./otherUtils"), module.exports);
28
28
  __reExport(src_exports, require("./typeUtils"), module.exports);
29
+ __reExport(src_exports, require("./componentStorage"), module.exports);
29
30
  __reExport(src_exports, require("./document"), module.exports);
30
31
  __reExport(src_exports, require("./date"), module.exports);
31
32
  __reExport(src_exports, require("./platform"), module.exports);
@@ -38,6 +39,11 @@ __reExport(src_exports, require("./image"), module.exports);
38
39
  __reExport(src_exports, require("./locales"), module.exports);
39
40
  __reExport(src_exports, require("./arrayUtils"), module.exports);
40
41
  __reExport(src_exports, require("./walletValidity"), module.exports);
42
+ __reExport(src_exports, require("./weighing"), module.exports);
43
+ __reExport(src_exports, require("./common"), module.exports);
44
+ __reExport(src_exports, require("./text-input"), module.exports);
45
+ __reExport(src_exports, require("./number-input"), module.exports);
46
+ __reExport(src_exports, require("./select"), module.exports);
41
47
  var setPisellUtilsConfig = (config) => {
42
48
  globalThis.pisellUtilsConfig = {
43
49
  ...globalThis.pisellUtilsConfig || {},
@@ -55,6 +61,7 @@ var getPisellUtilsConfig = () => {
55
61
  setPisellUtilsConfig,
56
62
  ...require("./otherUtils"),
57
63
  ...require("./typeUtils"),
64
+ ...require("./componentStorage"),
58
65
  ...require("./document"),
59
66
  ...require("./date"),
60
67
  ...require("./platform"),
@@ -66,5 +73,10 @@ var getPisellUtilsConfig = () => {
66
73
  ...require("./image"),
67
74
  ...require("./locales"),
68
75
  ...require("./arrayUtils"),
69
- ...require("./walletValidity")
76
+ ...require("./walletValidity"),
77
+ ...require("./weighing"),
78
+ ...require("./common"),
79
+ ...require("./text-input"),
80
+ ...require("./number-input"),
81
+ ...require("./select")
70
82
  });