@pisell/core 1.0.0 → 1.0.1

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 (281) hide show
  1. package/es/app/app.d.ts +122 -0
  2. package/es/app/app.js +166 -0
  3. package/es/app/const.d.ts +4 -0
  4. package/es/app/const.js +6 -0
  5. package/es/app/index.d.ts +14 -0
  6. package/es/app/index.js +54 -0
  7. package/es/applicationManager/application.d.ts +50 -0
  8. package/es/applicationManager/application.js +226 -0
  9. package/es/applicationManager/index.d.ts +13 -0
  10. package/es/applicationManager/index.js +190 -0
  11. package/es/config.d.ts +3 -3
  12. package/es/cookie/index.d.ts +13 -0
  13. package/es/cookie/index.js +47 -0
  14. package/es/css/global.less +73 -0
  15. package/es/css/index.less +31 -0
  16. package/es/css/variables.css +84 -0
  17. package/es/data/index.d.ts +29 -0
  18. package/es/data/index.js +8 -0
  19. package/es/history/config.d.ts +24 -0
  20. package/es/history/config.js +43 -0
  21. package/es/history/index.d.ts +20 -0
  22. package/es/history/index.js +41 -0
  23. package/es/history/type.d.ts +2 -0
  24. package/es/hooks/index.d.ts +12 -0
  25. package/es/hooks/index.js +13 -0
  26. package/es/hooks/useDelayedValue/index.d.ts +2 -0
  27. package/es/hooks/useDelayedValue/index.js +26 -0
  28. package/es/hooks/useDispatch/index.d.ts +2 -0
  29. package/es/hooks/useDispatch/index.js +2 -0
  30. package/es/hooks/useLowCode/index.d.ts +13 -0
  31. package/es/hooks/useLowCode/index.js +74 -0
  32. package/es/hooks/useStore/index.d.ts +6 -0
  33. package/es/hooks/useStore/index.js +11 -0
  34. package/es/index.d.ts +7 -1
  35. package/es/index.js +8 -2
  36. package/es/indexDB/index.d.ts +176 -0
  37. package/es/indexDB/index.js +536 -0
  38. package/es/locales/config.js +10 -8
  39. package/es/locales/en.d.ts +2 -1
  40. package/es/locales/en.js +5 -1
  41. package/es/locales/index.d.ts +44 -1
  42. package/es/locales/index.js +192 -8
  43. package/es/locales/original.d.ts +3 -0
  44. package/es/locales/original.js +7 -0
  45. package/es/locales/type.d.ts +15 -5
  46. package/es/locales/zh-CN.d.ts +2 -1
  47. package/es/locales/zh-CN.js +5 -1
  48. package/es/locales/zh-HK.d.ts +2 -1
  49. package/es/locales/zh-HK.js +5 -1
  50. package/es/logger/feishu.d.ts +11 -0
  51. package/es/logger/feishu.js +50 -0
  52. package/es/logger/index.d.ts +122 -0
  53. package/es/logger/index.js +531 -0
  54. package/es/menuManager/hooks.d.ts +8 -0
  55. package/es/menuManager/hooks.js +138 -0
  56. package/es/menuManager/index.d.ts +28 -0
  57. package/es/menuManager/index.js +142 -0
  58. package/es/models/global.d.ts +32 -0
  59. package/es/models/global.js +65 -0
  60. package/es/models/index.d.ts +45 -0
  61. package/es/models/index.js +66 -0
  62. package/es/models/tasks.d.ts +31 -0
  63. package/es/models/tasks.js +331 -0
  64. package/es/models/tasksUtils.d.ts +65 -0
  65. package/es/models/tasksUtils.js +179 -0
  66. package/es/models/type.d.ts +2 -0
  67. package/es/models/type.js +1 -0
  68. package/es/plugin/index.d.ts +0 -0
  69. package/es/plugin/index.js +0 -0
  70. package/es/pubsub/example.d.ts +5 -0
  71. package/es/pubsub/example.js +92 -0
  72. package/es/pubsub/index.d.ts +63 -0
  73. package/es/pubsub/index.js +144 -0
  74. package/es/request/cache.d.ts +46 -0
  75. package/es/request/cache.js +310 -0
  76. package/es/request/cancelToken.d.ts +38 -0
  77. package/es/request/cancelToken.js +59 -0
  78. package/es/request/config.d.ts +3 -0
  79. package/es/request/config.js +58 -0
  80. package/es/request/constants.d.ts +2 -0
  81. package/es/request/constants.js +6 -0
  82. package/es/request/index.d.ts +24 -0
  83. package/es/request/index.js +175 -0
  84. package/es/request/pisell2Request.d.ts +6 -0
  85. package/es/request/pisell2Request.js +62 -0
  86. package/es/request/type.d.ts +40 -0
  87. package/es/request/type.js +1 -0
  88. package/es/request/utils.d.ts +46 -0
  89. package/es/request/utils.js +145 -0
  90. package/es/routes/config.d.ts +7 -0
  91. package/es/routes/config.js +17 -0
  92. package/es/routes/index.d.ts +28 -0
  93. package/es/routes/index.js +154 -0
  94. package/es/socket/components/SocketMonitorPage.d.ts +6 -0
  95. package/es/socket/components/SocketMonitorPage.js +692 -0
  96. package/es/socket/components/index.d.ts +2 -0
  97. package/es/socket/components/index.js +2 -0
  98. package/es/socket/constants.d.ts +33 -0
  99. package/es/socket/constants.js +39 -0
  100. package/es/socket/events.d.ts +31 -0
  101. package/es/socket/events.js +19 -0
  102. package/es/socket/heartbeat.d.ts +66 -0
  103. package/es/socket/heartbeat.js +185 -0
  104. package/es/socket/index.d.ts +61 -0
  105. package/es/socket/index.js +246 -0
  106. package/es/socket/monitor.d.ts +169 -0
  107. package/es/socket/monitor.js +438 -0
  108. package/es/socket/reconnect.d.ts +61 -0
  109. package/es/socket/reconnect.js +199 -0
  110. package/es/socket/socket.d.ts +129 -0
  111. package/es/socket/socket.js +597 -0
  112. package/es/socket/types.d.ts +84 -0
  113. package/es/socket/types.js +19 -0
  114. package/es/storage/config.d.ts +3 -0
  115. package/es/{date → storage}/config.js +1 -6
  116. package/es/storage/index.d.ts +42 -0
  117. package/es/storage/index.js +62 -0
  118. package/es/storage/type.d.ts +5 -0
  119. package/es/storage/type.js +1 -0
  120. package/es/tasks/index.d.ts +77 -0
  121. package/es/tasks/index.js +719 -0
  122. package/es/tasks/type.d.ts +62 -0
  123. package/es/tasks/type.js +1 -0
  124. package/es/tasks/useTasks.d.ts +4 -0
  125. package/es/tasks/useTasks.js +25 -0
  126. package/es/type.d.ts +1 -1
  127. package/es/variables/VariablesProvider.d.ts +7 -0
  128. package/es/variables/VariablesProvider.js +14 -0
  129. package/es/variables/config.d.ts +3 -0
  130. package/es/{date/index.js → variables/config.js} +8 -14
  131. package/es/variables/index.d.ts +6 -0
  132. package/es/variables/index.js +5 -0
  133. package/es/variables/type.d.ts +2 -0
  134. package/es/variables/type.js +1 -0
  135. package/es/website/index.d.ts +6 -0
  136. package/es/website/index.js +65 -0
  137. package/lib/app/app.d.ts +122 -0
  138. package/lib/app/app.js +128 -0
  139. package/lib/app/const.d.ts +4 -0
  140. package/lib/app/const.js +33 -0
  141. package/lib/app/index.d.ts +14 -0
  142. package/lib/app/index.js +76 -0
  143. package/lib/applicationManager/application.d.ts +50 -0
  144. package/lib/applicationManager/application.js +110 -0
  145. package/lib/applicationManager/index.d.ts +13 -0
  146. package/lib/applicationManager/index.js +76 -0
  147. package/lib/config.d.ts +3 -3
  148. package/lib/cookie/index.d.ts +13 -0
  149. package/lib/cookie/index.js +64 -0
  150. package/lib/css/global.less +73 -0
  151. package/lib/css/index.less +31 -0
  152. package/lib/css/variables.css +84 -0
  153. package/lib/data/index.d.ts +29 -0
  154. package/lib/{date → data}/index.js +19 -20
  155. package/lib/history/config.d.ts +24 -0
  156. package/lib/history/config.js +41 -0
  157. package/lib/history/index.d.ts +20 -0
  158. package/lib/history/index.js +58 -0
  159. package/lib/history/type.d.ts +2 -0
  160. package/lib/history/type.js +17 -0
  161. package/lib/hooks/index.d.ts +12 -0
  162. package/lib/hooks/index.js +44 -0
  163. package/lib/hooks/useDelayedValue/index.d.ts +2 -0
  164. package/lib/hooks/useDelayedValue/index.js +36 -0
  165. package/lib/hooks/useDispatch/index.d.ts +2 -0
  166. package/lib/hooks/useDispatch/index.js +26 -0
  167. package/lib/hooks/useLowCode/index.d.ts +13 -0
  168. package/lib/hooks/useLowCode/index.js +75 -0
  169. package/lib/hooks/useStore/index.d.ts +6 -0
  170. package/lib/hooks/useStore/index.js +33 -0
  171. package/lib/index.d.ts +7 -1
  172. package/lib/index.js +23 -5
  173. package/lib/indexDB/index.d.ts +176 -0
  174. package/lib/indexDB/index.js +287 -0
  175. package/lib/locales/config.js +10 -7
  176. package/lib/locales/en.d.ts +2 -1
  177. package/lib/locales/en.js +5 -1
  178. package/lib/locales/index.d.ts +44 -1
  179. package/lib/locales/index.js +106 -4
  180. package/lib/locales/original.d.ts +3 -0
  181. package/lib/locales/original.js +31 -0
  182. package/lib/locales/type.d.ts +15 -5
  183. package/lib/locales/zh-CN.d.ts +2 -1
  184. package/lib/locales/zh-CN.js +5 -1
  185. package/lib/locales/zh-HK.d.ts +2 -1
  186. package/lib/locales/zh-HK.js +5 -1
  187. package/lib/logger/feishu.d.ts +11 -0
  188. package/lib/logger/feishu.js +52 -0
  189. package/lib/logger/index.d.ts +122 -0
  190. package/lib/logger/index.js +288 -0
  191. package/lib/menuManager/hooks.d.ts +8 -0
  192. package/lib/menuManager/hooks.js +135 -0
  193. package/lib/menuManager/index.d.ts +28 -0
  194. package/lib/menuManager/index.js +110 -0
  195. package/lib/models/global.d.ts +32 -0
  196. package/lib/models/global.js +62 -0
  197. package/lib/models/index.d.ts +45 -0
  198. package/lib/models/index.js +70 -0
  199. package/lib/models/tasks.d.ts +31 -0
  200. package/lib/models/tasks.js +199 -0
  201. package/lib/models/tasksUtils.d.ts +65 -0
  202. package/lib/models/tasksUtils.js +160 -0
  203. package/lib/models/type.d.ts +2 -0
  204. package/lib/models/type.js +17 -0
  205. package/lib/plugin/index.d.ts +0 -0
  206. package/lib/plugin/index.js +0 -0
  207. package/lib/pubsub/example.d.ts +5 -0
  208. package/lib/pubsub/example.js +61 -0
  209. package/lib/pubsub/index.d.ts +63 -0
  210. package/lib/pubsub/index.js +129 -0
  211. package/lib/request/cache.d.ts +46 -0
  212. package/lib/request/cache.js +159 -0
  213. package/lib/request/cancelToken.d.ts +38 -0
  214. package/lib/request/cancelToken.js +59 -0
  215. package/lib/request/config.d.ts +3 -0
  216. package/lib/request/config.js +74 -0
  217. package/lib/request/constants.d.ts +2 -0
  218. package/lib/request/constants.js +34 -0
  219. package/lib/request/index.d.ts +24 -0
  220. package/lib/request/index.js +143 -0
  221. package/lib/request/pisell2Request.d.ts +6 -0
  222. package/lib/request/pisell2Request.js +75 -0
  223. package/lib/request/type.d.ts +40 -0
  224. package/lib/request/type.js +17 -0
  225. package/lib/request/utils.d.ts +46 -0
  226. package/lib/request/utils.js +111 -0
  227. package/lib/routes/config.d.ts +7 -0
  228. package/lib/routes/config.js +50 -0
  229. package/lib/routes/index.d.ts +28 -0
  230. package/lib/routes/index.js +118 -0
  231. package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
  232. package/lib/socket/components/SocketMonitorPage.js +346 -0
  233. package/lib/socket/components/index.d.ts +2 -0
  234. package/lib/socket/components/index.js +39 -0
  235. package/lib/socket/constants.d.ts +33 -0
  236. package/lib/socket/constants.js +62 -0
  237. package/lib/socket/events.d.ts +31 -0
  238. package/lib/socket/events.js +44 -0
  239. package/lib/socket/heartbeat.d.ts +66 -0
  240. package/lib/socket/heartbeat.js +152 -0
  241. package/lib/socket/index.d.ts +61 -0
  242. package/lib/socket/index.js +200 -0
  243. package/lib/socket/monitor.d.ts +169 -0
  244. package/lib/socket/monitor.js +346 -0
  245. package/lib/socket/reconnect.d.ts +61 -0
  246. package/lib/socket/reconnect.js +153 -0
  247. package/lib/socket/socket.d.ts +129 -0
  248. package/lib/socket/socket.js +410 -0
  249. package/lib/socket/types.d.ts +84 -0
  250. package/lib/socket/types.js +36 -0
  251. package/lib/storage/config.d.ts +3 -0
  252. package/lib/{date → storage}/config.js +2 -7
  253. package/lib/storage/index.d.ts +42 -0
  254. package/lib/storage/index.js +66 -0
  255. package/lib/storage/type.d.ts +5 -0
  256. package/lib/storage/type.js +17 -0
  257. package/lib/tasks/index.d.ts +77 -0
  258. package/lib/tasks/index.js +438 -0
  259. package/lib/tasks/type.d.ts +62 -0
  260. package/lib/{date → tasks}/type.js +1 -1
  261. package/lib/tasks/useTasks.d.ts +4 -0
  262. package/lib/tasks/useTasks.js +37 -0
  263. package/lib/type.d.ts +1 -1
  264. package/lib/variables/VariablesProvider.d.ts +7 -0
  265. package/lib/variables/VariablesProvider.js +51 -0
  266. package/lib/variables/config.d.ts +3 -0
  267. package/lib/variables/config.js +38 -0
  268. package/lib/variables/index.d.ts +6 -0
  269. package/lib/variables/index.js +29 -0
  270. package/lib/variables/type.d.ts +2 -0
  271. package/lib/variables/type.js +17 -0
  272. package/lib/website/index.d.ts +6 -0
  273. package/lib/website/index.js +75 -0
  274. package/package.json +13 -3
  275. package/es/date/config.d.ts +0 -3
  276. package/es/date/index.d.ts +0 -7
  277. package/es/date/type.d.ts +0 -7
  278. package/lib/date/config.d.ts +0 -3
  279. package/lib/date/index.d.ts +0 -7
  280. package/lib/date/type.d.ts +0 -7
  281. /package/es/{date → history}/type.js +0 -0
@@ -0,0 +1,287 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/indexDB/index.ts
30
+ var indexDB_exports = {};
31
+ __export(indexDB_exports, {
32
+ default: () => indexDB_default
33
+ });
34
+ module.exports = __toCommonJS(indexDB_exports);
35
+ var import_storage = __toESM(require("../storage"));
36
+ var IndexDBManager = class {
37
+ /**
38
+ * 创建 IndexDBManager 实例
39
+ * @param {DBOptions} options - 数据库配置选项
40
+ */
41
+ constructor(options) {
42
+ this.db = null;
43
+ this.dbName = options.dbName;
44
+ this.version = options.version;
45
+ this.stores = options.stores;
46
+ this.useIndexDB = IndexDBManager.isSupported();
47
+ }
48
+ /**
49
+ * 检查环境是否支持 IndexedDB
50
+ * @returns {boolean} 是否支持 IndexedDB
51
+ * @private
52
+ */
53
+ static isSupported() {
54
+ return window && "indexedDB" in window;
55
+ }
56
+ /**
57
+ * 初始化数据库连接
58
+ * 如果环境不支持 IndexedDB,将自动使用 localStorage
59
+ * @returns {Promise<boolean>} 连接是否成功
60
+ */
61
+ async connect() {
62
+ if (!this.useIndexDB) {
63
+ return true;
64
+ }
65
+ return new Promise((resolve, reject) => {
66
+ const request = indexedDB.open(this.dbName, this.version);
67
+ request.onerror = () => {
68
+ this.useIndexDB = false;
69
+ resolve(true);
70
+ };
71
+ request.onsuccess = (event) => {
72
+ this.db = event.target.result;
73
+ resolve(true);
74
+ };
75
+ request.onupgradeneeded = (event) => {
76
+ const db = event.target.result;
77
+ this.stores.forEach((store) => {
78
+ var _a;
79
+ if (!db.objectStoreNames.contains(store.name)) {
80
+ const objectStore = db.createObjectStore(store.name, { keyPath: store.keyPath });
81
+ (_a = store.indexes) == null ? void 0 : _a.forEach((index) => {
82
+ objectStore.createIndex(index.name, index.keyPath, index.options);
83
+ });
84
+ }
85
+ });
86
+ };
87
+ });
88
+ }
89
+ /**
90
+ * 生成用于 localStorage 的存储键
91
+ * @param {string} storeName - 存储对象名称
92
+ * @param {string|number} [key] - 可选的键值
93
+ * @returns {string} 格式化的存储键
94
+ * @private
95
+ */
96
+ getStorageKey(storeName, key) {
97
+ return `${this.dbName}_${storeName}${key ? `_${key}` : ""}`;
98
+ }
99
+ /**
100
+ * 添加数据到指定的存储对象
101
+ * @param {string} storeName - 存储对象名称
102
+ * @param {T} data - 要添加的数据
103
+ * @returns {Promise<T>} 添加的数据
104
+ * @template T
105
+ */
106
+ async add(storeName, data) {
107
+ var _a;
108
+ if (!this.useIndexDB) {
109
+ const key = this.getStorageKey(storeName, data[((_a = this.stores.find((s) => s.name === storeName)) == null ? void 0 : _a.keyPath) || "id"]);
110
+ import_storage.default.setStorage(key, JSON.stringify(data));
111
+ return data;
112
+ }
113
+ return new Promise((resolve, reject) => {
114
+ if (!this.db) {
115
+ reject(new Error("数据库未连接"));
116
+ return;
117
+ }
118
+ const transaction = this.db.transaction(storeName, "readwrite");
119
+ const store = transaction.objectStore(storeName);
120
+ const request = store.add(data);
121
+ request.onsuccess = () => resolve(data);
122
+ request.onerror = () => reject(new Error("添加数据失败"));
123
+ });
124
+ }
125
+ /**
126
+ * 获取指定存储对象中的数据
127
+ * @param {string} storeName - 存储对象名称
128
+ * @param {string|number} key - 数据主键
129
+ * @returns {Promise<T|null>} 获取的数据,不存在则返回 null
130
+ * @template T
131
+ */
132
+ async get(storeName, key) {
133
+ if (!this.useIndexDB) {
134
+ const storageKey = this.getStorageKey(storeName, key);
135
+ let data = import_storage.default.getStorage(storageKey);
136
+ if (data) {
137
+ data = JSON.parse(data);
138
+ }
139
+ return data;
140
+ }
141
+ return new Promise((resolve, reject) => {
142
+ if (!this.db) {
143
+ reject(new Error("数据库未连接"));
144
+ return;
145
+ }
146
+ const transaction = this.db.transaction(storeName, "readonly");
147
+ const store = transaction.objectStore(storeName);
148
+ const request = store.get(key);
149
+ request.onsuccess = () => resolve(request.result || null);
150
+ request.onerror = () => reject(new Error("获取数据失败"));
151
+ });
152
+ }
153
+ /**
154
+ * 更新指定存储对象中的数据
155
+ * @param {string} storeName - 存储对象名称
156
+ * @param {T} data - 要更新的数据
157
+ * @returns {Promise<T>} 更新后的数据
158
+ * @template T
159
+ */
160
+ async update(storeName, data) {
161
+ var _a;
162
+ if (!this.useIndexDB) {
163
+ const key = this.getStorageKey(storeName, data[((_a = this.stores.find((s) => s.name === storeName)) == null ? void 0 : _a.keyPath) || "id"]);
164
+ import_storage.default.setStorage(key, JSON.stringify(data));
165
+ return data;
166
+ }
167
+ return new Promise((resolve, reject) => {
168
+ if (!this.db) {
169
+ reject(new Error("数据库未连接"));
170
+ return;
171
+ }
172
+ const transaction = this.db.transaction(storeName, "readwrite");
173
+ const store = transaction.objectStore(storeName);
174
+ const request = store.put(data);
175
+ request.onsuccess = () => resolve(data);
176
+ request.onerror = () => reject(new Error("更新数据失败"));
177
+ });
178
+ }
179
+ /**
180
+ * 删除指定存储对象中的数据
181
+ * @param {string} storeName - 存储对象名称
182
+ * @param {string|number} key - 数据主键
183
+ * @returns {Promise<boolean>} 删除是否成功
184
+ */
185
+ async delete(storeName, key) {
186
+ if (!this.useIndexDB) {
187
+ const storageKey = this.getStorageKey(storeName, key);
188
+ import_storage.default.removeStorage(storageKey);
189
+ return true;
190
+ }
191
+ return new Promise((resolve, reject) => {
192
+ if (!this.db) {
193
+ reject(new Error("数据库未连接"));
194
+ return;
195
+ }
196
+ const transaction = this.db.transaction(storeName, "readwrite");
197
+ const store = transaction.objectStore(storeName);
198
+ const request = store.delete(key);
199
+ request.onsuccess = () => resolve(true);
200
+ request.onerror = () => reject(new Error("删除数据失败"));
201
+ });
202
+ }
203
+ /**
204
+ * 获取指定存储对象中的所有数据
205
+ * @param {string} storeName - 存储对象名称
206
+ * @returns {Promise<T[]>} 数据数组
207
+ * @template T
208
+ */
209
+ async getAll(storeName) {
210
+ if (!this.useIndexDB) {
211
+ const prefix = this.getStorageKey(storeName);
212
+ const results = [];
213
+ for (let i = 0; i < localStorage.length; i++) {
214
+ const key = localStorage.key(i);
215
+ if (key == null ? void 0 : key.startsWith(prefix)) {
216
+ let value = import_storage.default.getStorage(key);
217
+ if (value) {
218
+ value = JSON.parse(value);
219
+ }
220
+ if (value) {
221
+ results.push(value);
222
+ }
223
+ }
224
+ }
225
+ return results;
226
+ }
227
+ return new Promise((resolve, reject) => {
228
+ if (!this.db) {
229
+ reject(new Error("数据库未连接"));
230
+ return;
231
+ }
232
+ const transaction = this.db.transaction(storeName, "readonly");
233
+ const store = transaction.objectStore(storeName);
234
+ const request = store.getAll();
235
+ request.onsuccess = () => resolve(request.result);
236
+ request.onerror = () => reject(new Error("获取所有数据失败"));
237
+ });
238
+ }
239
+ /**
240
+ * 清空指定存储对象中的所有数据
241
+ * @param {string} storeName - 存储对象名称
242
+ * @returns {Promise<boolean>} 清空是否成功
243
+ */
244
+ async clear(storeName) {
245
+ if (!this.useIndexDB) {
246
+ const prefix = this.getStorageKey(storeName);
247
+ const keysToRemove = [];
248
+ for (let i = 0; i < localStorage.length; i++) {
249
+ const key = localStorage.key(i);
250
+ if (key == null ? void 0 : key.startsWith(prefix)) {
251
+ keysToRemove.push(key);
252
+ }
253
+ }
254
+ keysToRemove.forEach((key) => localStorage.removeItem(key));
255
+ return true;
256
+ }
257
+ return new Promise((resolve, reject) => {
258
+ if (!this.db) {
259
+ reject(new Error("数据库未连接"));
260
+ return;
261
+ }
262
+ const transaction = this.db.transaction(storeName, "readwrite");
263
+ const store = transaction.objectStore(storeName);
264
+ const request = store.clear();
265
+ request.onsuccess = () => resolve(true);
266
+ request.onerror = () => reject(new Error("清空数据失败"));
267
+ });
268
+ }
269
+ /**
270
+ * 关闭数据库连接
271
+ * 在不再需要使用数据库时调用,释放资源
272
+ */
273
+ close() {
274
+ if (this.db) {
275
+ this.db.close();
276
+ this.db = null;
277
+ }
278
+ }
279
+ /**
280
+ * 获取当前使用的存储方式
281
+ * @returns {'indexDB'|'localStorage'} 当前使用的存储方式
282
+ */
283
+ getCurrentStorage() {
284
+ return this.useIndexDB ? "indexDB" : "localStorage";
285
+ }
286
+ };
287
+ var indexDB_default = IndexDBManager;
@@ -37,21 +37,24 @@ module.exports = __toCommonJS(config_exports);
37
37
  var import_en = __toESM(require("./en"));
38
38
  var import_zh_CN = __toESM(require("./zh-CN"));
39
39
  var import_zh_HK = __toESM(require("./zh-HK"));
40
+ var import_original = __toESM(require("./original"));
41
+ var import_storage = __toESM(require("../storage"));
42
+ var storageLocale = import_storage.default.getStorage("locale");
40
43
  var defaultConfig = {
41
- // 当前语言
42
- locale: "en",
44
+ // 当前语言 本地语言 > 英文语言包
45
+ locale: storageLocale || import_en.default.locale,
43
46
  // 语言包
44
- texts: {
45
- "en": import_en.default,
46
- "zh-CN": import_zh_CN.default,
47
- "zh-HK": import_zh_HK.default
48
- }
47
+ library: [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
48
+ pre[cur.locale] = cur;
49
+ return pre;
50
+ }, {})
49
51
  };
50
52
  var config = {
51
53
  ...defaultConfig
52
54
  };
53
55
  var setConfig = (newConfig) => {
54
56
  config = { ...config, ...newConfig };
57
+ import_storage.default.setStorage("locale", config.locale);
55
58
  return config;
56
59
  };
57
60
  var getConfig = () => config;
@@ -1,2 +1,3 @@
1
- declare const _default: {};
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
2
3
  export default _default;
package/lib/locales/en.js CHANGED
@@ -22,4 +22,8 @@ __export(en_exports, {
22
22
  default: () => en_default
23
23
  });
24
24
  module.exports = __toCommonJS(en_exports);
25
- var en_default = {};
25
+ var en_default = {
26
+ "locale": "en",
27
+ "name": "english",
28
+ "translations": {}
29
+ };
@@ -1,4 +1,4 @@
1
- import { Locale } from './type';
1
+ import { Locale, LibraryItem, LoadLibraryByUrlParams } from "./type";
2
2
  /**
3
3
  * @title: 获取当前语言
4
4
  * @description:
@@ -41,6 +41,36 @@ export declare const getText: (id: string, locale?: Locale) => string;
41
41
  * @Author: zhiwei.Wang
42
42
  */
43
43
  export declare const isCN: () => boolean;
44
+ /**
45
+ * @title: 加载远端语言包
46
+ * @description:
47
+ * @param {string | Promise} urls 支持字符串、异步函数和LibraryItem对象
48
+ * @return {*}
49
+ * @Author: zhiwei.Wang
50
+ */
51
+ export declare const loadLibraryByUrl: (urls: LoadLibraryByUrlParams) => Promise<{
52
+ [x: string]: LibraryItem;
53
+ }>;
54
+ export declare const loadLibraryByItems: (libraryList: LibraryItem[]) => void;
55
+ export declare const loadLibrary: (urls: (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[]) => Promise<{
56
+ [x: string]: LibraryItem;
57
+ }>;
58
+ /**
59
+ * @title: 解析original多语言对象
60
+ * @description: 优先级 店铺语言 > original > en > zh-CN > zh-HK
61
+ * @return: *
62
+ * @Author: shengjie.zuo
63
+ * @Date: 2024-10-26 16:25:36
64
+ */
65
+ export declare const translation: (text: string | {
66
+ [key: string]: string;
67
+ }, locale?: Locale) => string | number;
68
+ export declare const getLibraryByData: (data: LibraryItem[]) => {};
69
+ export declare const createTextsByLibrary: (id: string, library?: {
70
+ [x: string]: LibraryItem;
71
+ } | undefined) => {
72
+ [x: string]: string;
73
+ };
44
74
  declare const _default: {
45
75
  getLocale: () => string;
46
76
  getCurrentTexts: (locale?: string | undefined) => {
@@ -51,5 +81,18 @@ declare const _default: {
51
81
  isCN: () => boolean;
52
82
  getConfig: () => import("./type").LocaleConfig;
53
83
  setConfig: (newConfig: Partial<import("./type").LocaleConfig>) => import("./type").LocaleConfig;
84
+ loadLibraryByUrl: (urls: LoadLibraryByUrlParams) => Promise<{
85
+ [x: string]: LibraryItem;
86
+ }>;
87
+ translation: (text: string | {
88
+ [key: string]: string;
89
+ }, locale?: string | undefined) => string | number;
90
+ loadLibraryByItems: (libraryList: LibraryItem[]) => void;
91
+ getLibraryByData: (data: LibraryItem[]) => {};
92
+ createTextsByLibrary: (id: string, library?: {
93
+ [x: string]: LibraryItem;
94
+ } | undefined) => {
95
+ [x: string]: string;
96
+ };
54
97
  };
55
98
  export default _default;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,26 +16,42 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/locales/index.ts
20
30
  var locales_exports = {};
21
31
  __export(locales_exports, {
32
+ createTextsByLibrary: () => createTextsByLibrary,
22
33
  default: () => locales_default,
23
34
  getCurrentTexts: () => getCurrentTexts,
35
+ getLibraryByData: () => getLibraryByData,
24
36
  getLocale: () => getLocale,
25
37
  getText: () => getText,
26
38
  isCN: () => isCN,
27
- setLocale: () => setLocale
39
+ loadLibrary: () => loadLibrary,
40
+ loadLibraryByItems: () => loadLibraryByItems,
41
+ loadLibraryByUrl: () => loadLibraryByUrl,
42
+ setLocale: () => setLocale,
43
+ translation: () => translation
28
44
  });
29
45
  module.exports = __toCommonJS(locales_exports);
30
46
  var import_config = require("./config");
47
+ var import_lodash = __toESM(require("lodash"));
48
+ var import_utils = require("@pisell/utils");
31
49
  var getLocale = () => {
32
50
  return (0, import_config.getConfig)().locale;
33
51
  };
34
52
  var getCurrentTexts = (locale) => {
35
53
  let config = (0, import_config.getConfig)();
36
- return config.texts[locale || config.locale];
54
+ return config.library[locale || config.locale].translations;
37
55
  };
38
56
  var setLocale = (locale, reload = false) => {
39
57
  (0, import_config.setConfig)({ locale });
@@ -50,6 +68,79 @@ var isCN = () => {
50
68
  let locale = getLocale();
51
69
  return locale === "zh-CN" || locale === "zh-HK";
52
70
  };
71
+ var loadLibraryByUrl = async (urls) => {
72
+ try {
73
+ let fetchList = urls.map((item) => {
74
+ if (typeof item === "string") {
75
+ return fetch(item);
76
+ }
77
+ if (typeof item === "function") {
78
+ return item();
79
+ }
80
+ if (typeof item === "object" && item !== null && "locale" in item) {
81
+ return Promise.resolve(item);
82
+ }
83
+ return item;
84
+ });
85
+ let res = await Promise.all(fetchList);
86
+ let library = { ...(0, import_config.getConfig)().library };
87
+ for (const item of res) {
88
+ const _item = item instanceof Response ? await item.json() : item;
89
+ library = {
90
+ ...library,
91
+ [_item.locale]: import_lodash.default.mergeWith(library[_item.locale] || {}, _item)
92
+ };
93
+ }
94
+ (0, import_config.setConfig)({ library });
95
+ return library;
96
+ } catch (err) {
97
+ console.log(err);
98
+ throw err;
99
+ }
100
+ };
101
+ var loadLibraryByItems = (libraryList) => {
102
+ let library = { ...(0, import_config.getConfig)().library };
103
+ libraryList.forEach((item) => {
104
+ library = {
105
+ ...library,
106
+ [item.locale]: import_lodash.default.mergeWith(library[item.locale] || {}, item)
107
+ };
108
+ });
109
+ (0, import_config.setConfig)({ library });
110
+ };
111
+ var loadLibrary = async (urls) => {
112
+ return loadLibraryByUrl(urls);
113
+ };
114
+ var translation = (text, locale) => {
115
+ if (!text) {
116
+ return "";
117
+ }
118
+ if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
119
+ return text;
120
+ }
121
+ let primary = locale || getLocale();
122
+ return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
123
+ };
124
+ var getLibraryByData = (data) => {
125
+ return data.reduce((pre, next) => {
126
+ return {
127
+ ...pre,
128
+ [next.locale]: next
129
+ };
130
+ }, {});
131
+ };
132
+ var createTextsByLibrary = (id, library) => {
133
+ const _library = library || (0, import_config.getConfig)().library;
134
+ return Object.keys(_library).reduce((pre, next) => {
135
+ var _a;
136
+ let _pre = { ...pre };
137
+ let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
138
+ if (cur) {
139
+ _pre[_library[next].locale] = cur;
140
+ }
141
+ return _pre;
142
+ }, {});
143
+ };
53
144
  var locales_default = {
54
145
  getLocale,
55
146
  getCurrentTexts,
@@ -57,13 +148,24 @@ var locales_default = {
57
148
  getText,
58
149
  isCN,
59
150
  getConfig: import_config.getConfig,
60
- setConfig: import_config.setConfig
151
+ setConfig: import_config.setConfig,
152
+ loadLibraryByUrl,
153
+ translation,
154
+ loadLibraryByItems,
155
+ getLibraryByData,
156
+ createTextsByLibrary
61
157
  };
62
158
  // Annotate the CommonJS export names for ESM import in node:
63
159
  0 && (module.exports = {
160
+ createTextsByLibrary,
64
161
  getCurrentTexts,
162
+ getLibraryByData,
65
163
  getLocale,
66
164
  getText,
67
165
  isCN,
68
- setLocale
166
+ loadLibrary,
167
+ loadLibraryByItems,
168
+ loadLibraryByUrl,
169
+ setLocale,
170
+ translation
69
171
  });
@@ -0,0 +1,3 @@
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
3
+ export default _default;
@@ -0,0 +1,31 @@
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/locales/original.ts
20
+ var original_exports = {};
21
+ __export(original_exports, {
22
+ default: () => original_default
23
+ });
24
+ module.exports = __toCommonJS(original_exports);
25
+ var original_default = {
26
+ "locale": "original",
27
+ "name": "original",
28
+ "translations": {
29
+ "original": "Original"
30
+ }
31
+ };
@@ -1,9 +1,19 @@
1
- export declare type Locale = 'en' | 'zh-CN' | 'zh-HK' | string;
1
+ export declare type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
+ export declare type MultiLanguage = {
3
+ [key in Locale]: string;
4
+ };
5
+ export interface LibraryItem {
6
+ locale: Locale;
7
+ name: string;
8
+ translations: {
9
+ [key: string]: string;
10
+ };
11
+ [key: string]: any;
12
+ }
2
13
  export interface LocaleConfig {
3
14
  locale: Locale;
4
- texts: {
5
- [key in Locale]: {
6
- [key: string]: string;
7
- };
15
+ library: {
16
+ [key in Locale]: LibraryItem;
8
17
  };
9
18
  }
19
+ export declare type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
@@ -1,2 +1,3 @@
1
- declare const _default: {};
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
2
3
  export default _default;
@@ -22,4 +22,8 @@ __export(zh_CN_exports, {
22
22
  default: () => zh_CN_default
23
23
  });
24
24
  module.exports = __toCommonJS(zh_CN_exports);
25
- var zh_CN_default = {};
25
+ var zh_CN_default = {
26
+ "locale": "zh-CN",
27
+ "name": "simplifiedChinese",
28
+ "translations": {}
29
+ };
@@ -1,2 +1,3 @@
1
- declare const _default: {};
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
2
3
  export default _default;
@@ -22,4 +22,8 @@ __export(zh_HK_exports, {
22
22
  default: () => zh_HK_default
23
23
  });
24
24
  module.exports = __toCommonJS(zh_HK_exports);
25
- var zh_HK_default = {};
25
+ var zh_HK_default = {
26
+ "locale": "zh-HK",
27
+ "name": "chineseTraditional",
28
+ "translations": {}
29
+ };
@@ -0,0 +1,11 @@
1
+ interface contentItem {
2
+ key: string;
3
+ value: string;
4
+ }
5
+ interface sendWebhookProps {
6
+ title: string;
7
+ content: contentItem[];
8
+ webhook: string;
9
+ }
10
+ export declare const sendWarningLog: ({ title, content, webhook }: sendWebhookProps) => Promise<any>;
11
+ export {};