@taicode/common-web 3.7.5 → 3.7.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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +12 -13
  3. package/output/components/alert-dialog.d.ts +0 -20
  4. package/output/components/alert-dialog.d.ts.map +0 -1
  5. package/output/components/alert-dialog.js +0 -65
  6. package/output/components/alert.d.ts +0 -11
  7. package/output/components/alert.d.ts.map +0 -1
  8. package/output/components/alert.js +0 -38
  9. package/output/components/avatar.d.ts +0 -13
  10. package/output/components/avatar.d.ts.map +0 -1
  11. package/output/components/avatar.js +0 -40
  12. package/output/components/badge.d.ts +0 -11
  13. package/output/components/badge.d.ts.map +0 -1
  14. package/output/components/badge.js +0 -39
  15. package/output/components/button.d.ts +0 -12
  16. package/output/components/button.d.ts.map +0 -1
  17. package/output/components/button.js +0 -48
  18. package/output/components/calendar.d.ts +0 -13
  19. package/output/components/calendar.d.ts.map +0 -1
  20. package/output/components/calendar.js +0 -57
  21. package/output/components/card.d.ts +0 -13
  22. package/output/components/card.d.ts.map +0 -1
  23. package/output/components/card.js +0 -43
  24. package/output/components/chart.d.ts +0 -56
  25. package/output/components/chart.d.ts.map +0 -1
  26. package/output/components/chart.js +0 -127
  27. package/output/components/checkbox.d.ts +0 -5
  28. package/output/components/checkbox.d.ts.map +0 -1
  29. package/output/components/checkbox.js +0 -21
  30. package/output/components/command.d.ts +0 -20
  31. package/output/components/command.d.ts.map +0 -1
  32. package/output/components/command.js +0 -55
  33. package/output/components/dialog.d.ts +0 -20
  34. package/output/components/dialog.d.ts.map +0 -1
  35. package/output/components/dialog.js +0 -58
  36. package/output/components/direction.d.ts +0 -9
  37. package/output/components/direction.d.ts.map +0 -1
  38. package/output/components/direction.js +0 -10
  39. package/output/components/drawer.d.ts +0 -14
  40. package/output/components/drawer.d.ts.map +0 -1
  41. package/output/components/drawer.js +0 -56
  42. package/output/components/dropdown-menu.d.ts +0 -29
  43. package/output/components/dropdown-menu.d.ts.map +0 -1
  44. package/output/components/dropdown-menu.js +0 -78
  45. package/output/components/field.d.ts +0 -39
  46. package/output/components/field.d.ts.map +0 -1
  47. package/output/components/field.js +0 -102
  48. package/output/components/footer/index.d.ts +0 -27
  49. package/output/components/footer/index.d.ts.map +0 -1
  50. package/output/components/footer/index.js +0 -17
  51. package/output/components/form.d.ts +0 -26
  52. package/output/components/form.d.ts.map +0 -1
  53. package/output/components/form.js +0 -69
  54. package/output/components/index.d.ts +0 -46
  55. package/output/components/index.d.ts.map +0 -1
  56. package/output/components/index.js +0 -45
  57. package/output/components/input-group.d.ts +0 -17
  58. package/output/components/input-group.d.ts.map +0 -1
  59. package/output/components/input-group.js +0 -75
  60. package/output/components/input.d.ts +0 -4
  61. package/output/components/input.d.ts.map +0 -1
  62. package/output/components/input.js +0 -19
  63. package/output/components/item.d.ts +0 -25
  64. package/output/components/item.d.ts.map +0 -1
  65. package/output/components/item.js +0 -89
  66. package/output/components/json-view/index.d.ts +0 -11
  67. package/output/components/json-view/index.d.ts.map +0 -1
  68. package/output/components/json-view/index.js +0 -52
  69. package/output/components/json-view/lazy/index.d.ts +0 -18
  70. package/output/components/json-view/lazy/index.d.ts.map +0 -1
  71. package/output/components/json-view/lazy/index.js +0 -22
  72. package/output/components/kbd.d.ts +0 -4
  73. package/output/components/kbd.d.ts.map +0 -1
  74. package/output/components/kbd.js +0 -22
  75. package/output/components/label.d.ts +0 -5
  76. package/output/components/label.d.ts.map +0 -1
  77. package/output/components/label.js +0 -20
  78. package/output/components/list-actions/index.d.ts +0 -23
  79. package/output/components/list-actions/index.d.ts.map +0 -1
  80. package/output/components/list-actions/index.js +0 -15
  81. package/output/components/loading-button/index.d.ts +0 -44
  82. package/output/components/loading-button/index.d.ts.map +0 -1
  83. package/output/components/loading-button/index.js +0 -75
  84. package/output/components/loading-button/index.test.d.ts +0 -2
  85. package/output/components/loading-button/index.test.d.ts.map +0 -1
  86. package/output/components/loading-button/index.test.js +0 -203
  87. package/output/components/native-select.d.ts +0 -9
  88. package/output/components/native-select.d.ts.map +0 -1
  89. package/output/components/native-select.js +0 -28
  90. package/output/components/page-back-button/index.d.ts +0 -8
  91. package/output/components/page-back-button/index.d.ts.map +0 -1
  92. package/output/components/page-back-button/index.js +0 -7
  93. package/output/components/page-state.d.ts +0 -19
  94. package/output/components/page-state.d.ts.map +0 -1
  95. package/output/components/page-state.js +0 -13
  96. package/output/components/pagination/index.d.ts +0 -34
  97. package/output/components/pagination/index.d.ts.map +0 -1
  98. package/output/components/pagination/index.js +0 -75
  99. package/output/components/popover.d.ts +0 -11
  100. package/output/components/popover.d.ts.map +0 -1
  101. package/output/components/popover.js +0 -44
  102. package/output/components/progress.d.ts +0 -5
  103. package/output/components/progress.d.ts.map +0 -1
  104. package/output/components/progress.js +0 -21
  105. package/output/components/radio-group.d.ts +0 -6
  106. package/output/components/radio-group.d.ts.map +0 -1
  107. package/output/components/radio-group.js +0 -25
  108. package/output/components/route-pending-indicator/index.d.ts +0 -20
  109. package/output/components/route-pending-indicator/index.d.ts.map +0 -1
  110. package/output/components/route-pending-indicator/index.js +0 -17
  111. package/output/components/scroll-area.d.ts +0 -6
  112. package/output/components/scroll-area.d.ts.map +0 -1
  113. package/output/components/scroll-area.js +0 -24
  114. package/output/components/searchable-select/index.d.ts +0 -41
  115. package/output/components/searchable-select/index.d.ts.map +0 -1
  116. package/output/components/searchable-select/index.js +0 -46
  117. package/output/components/select.d.ts +0 -17
  118. package/output/components/select.d.ts.map +0 -1
  119. package/output/components/select.js +0 -58
  120. package/output/components/separator.d.ts +0 -5
  121. package/output/components/separator.d.ts.map +0 -1
  122. package/output/components/separator.js +0 -20
  123. package/output/components/sheet.d.ts +0 -16
  124. package/output/components/sheet.d.ts.map +0 -1
  125. package/output/components/sheet.js +0 -58
  126. package/output/components/sidebar.d.ts +0 -78
  127. package/output/components/sidebar.d.ts.map +0 -1
  128. package/output/components/sidebar.js +0 -233
  129. package/output/components/size-provider/index.d.ts +0 -2
  130. package/output/components/size-provider/index.d.ts.map +0 -1
  131. package/output/components/size-provider/index.js +0 -1
  132. package/output/components/size-provider/size-provider.d.ts +0 -9
  133. package/output/components/size-provider/size-provider.d.ts.map +0 -1
  134. package/output/components/size-provider/size-provider.js +0 -29
  135. package/output/components/skeleton.d.ts +0 -3
  136. package/output/components/skeleton.d.ts.map +0 -1
  137. package/output/components/skeleton.js +0 -18
  138. package/output/components/sonner.d.ts +0 -8
  139. package/output/components/sonner.d.ts.map +0 -1
  140. package/output/components/sonner.js +0 -34
  141. package/output/components/spinner.d.ts +0 -3
  142. package/output/components/spinner.d.ts.map +0 -1
  143. package/output/components/spinner.js +0 -19
  144. package/output/components/switch.d.ts +0 -8
  145. package/output/components/switch.d.ts.map +0 -1
  146. package/output/components/switch.js +0 -20
  147. package/output/components/table.d.ts +0 -11
  148. package/output/components/table.d.ts.map +0 -1
  149. package/output/components/table.js +0 -47
  150. package/output/components/tabs.d.ts +0 -12
  151. package/output/components/tabs.d.ts.map +0 -1
  152. package/output/components/tabs.js +0 -45
  153. package/output/components/textarea.d.ts +0 -4
  154. package/output/components/textarea.d.ts.map +0 -1
  155. package/output/components/textarea.js +0 -19
  156. package/output/components/theme-switcher.d.ts +0 -6
  157. package/output/components/theme-switcher.d.ts.map +0 -1
  158. package/output/components/theme-switcher.js +0 -19
  159. package/output/components/toaster/index.d.ts +0 -16
  160. package/output/components/toaster/index.d.ts.map +0 -1
  161. package/output/components/toaster/index.js +0 -70
  162. package/output/components/toggle-group.d.ts +0 -12
  163. package/output/components/toggle-group.d.ts.map +0 -1
  164. package/output/components/toggle-group.js +0 -38
  165. package/output/components/toggle.d.ts +0 -10
  166. package/output/components/toggle.d.ts.map +0 -1
  167. package/output/components/toggle.js +0 -38
  168. package/output/components/tooltip.d.ts +0 -8
  169. package/output/components/tooltip.d.ts.map +0 -1
  170. package/output/components/tooltip.js +0 -33
  171. package/output/features/confirm-dialog/index.d.ts +0 -41
  172. package/output/features/confirm-dialog/index.d.ts.map +0 -1
  173. package/output/features/confirm-dialog/index.js +0 -19
  174. package/output/features/input-confirm/index.d.ts +0 -26
  175. package/output/features/input-confirm/index.d.ts.map +0 -1
  176. package/output/features/input-confirm/index.js +0 -59
  177. package/output/features/signin/context.d.ts +0 -14
  178. package/output/features/signin/context.d.ts.map +0 -1
  179. package/output/features/signin/context.js +0 -13
  180. package/output/features/signin/index.d.ts +0 -58
  181. package/output/features/signin/index.d.ts.map +0 -1
  182. package/output/features/signin/index.js +0 -137
  183. package/output/features/signin/service.d.ts +0 -92
  184. package/output/features/signin/service.d.ts.map +0 -1
  185. package/output/features/signin/service.js +0 -519
  186. package/output/features/signin/service.test.d.ts +0 -2
  187. package/output/features/signin/service.test.d.ts.map +0 -1
  188. package/output/features/signin/service.test.js +0 -211
  189. package/output/features/signin/types.d.ts +0 -63
  190. package/output/features/signin/types.d.ts.map +0 -1
  191. package/output/features/signin/types.js +0 -1
  192. package/output/hooks/use-loading/index.d.ts +0 -6
  193. package/output/hooks/use-loading/index.d.ts.map +0 -1
  194. package/output/hooks/use-loading/index.js +0 -14
  195. package/output/hooks/use-loading/index.test.d.ts +0 -2
  196. package/output/hooks/use-loading/index.test.d.ts.map +0 -1
  197. package/output/hooks/use-loading/index.test.js +0 -24
  198. package/output/hooks/use-mobile/index.d.ts +0 -2
  199. package/output/hooks/use-mobile/index.d.ts.map +0 -1
  200. package/output/hooks/use-mobile/index.js +0 -16
  201. package/output/hooks/use-observer/index.d.ts +0 -2
  202. package/output/hooks/use-observer/index.d.ts.map +0 -1
  203. package/output/hooks/use-observer/index.js +0 -1
  204. package/output/hooks/use-observer/use-observer.d.ts +0 -3
  205. package/output/hooks/use-observer/use-observer.d.ts.map +0 -1
  206. package/output/hooks/use-observer/use-observer.js +0 -16
  207. package/output/hooks/use-observer/use-observer.test.d.ts +0 -2
  208. package/output/hooks/use-observer/use-observer.test.d.ts.map +0 -1
  209. package/output/hooks/use-observer/use-observer.test.js +0 -134
  210. package/output/hooks/use-offline/index.d.ts +0 -6
  211. package/output/hooks/use-offline/index.d.ts.map +0 -1
  212. package/output/hooks/use-offline/index.js +0 -19
  213. package/output/layout/app/index.d.ts +0 -34
  214. package/output/layout/app/index.d.ts.map +0 -1
  215. package/output/layout/app/index.js +0 -34
  216. package/output/layout/dashboard/index.d.ts +0 -76
  217. package/output/layout/dashboard/index.d.ts.map +0 -1
  218. package/output/layout/dashboard/index.js +0 -84
  219. package/output/layout/index.d.ts +0 -3
  220. package/output/layout/index.d.ts.map +0 -1
  221. package/output/layout/index.js +0 -2
  222. package/output/services/cache-api/cache-api.d.ts +0 -23
  223. package/output/services/cache-api/cache-api.d.ts.map +0 -1
  224. package/output/services/cache-api/cache-api.js +0 -145
  225. package/output/services/cache-api/cache-api.test.d.ts +0 -2
  226. package/output/services/cache-api/cache-api.test.d.ts.map +0 -1
  227. package/output/services/cache-api/cache-api.test.js +0 -610
  228. package/output/services/cache-api/index.d.ts +0 -2
  229. package/output/services/cache-api/index.d.ts.map +0 -1
  230. package/output/services/cache-api/index.js +0 -1
  231. package/output/services/cached-fetch/index.d.ts +0 -50
  232. package/output/services/cached-fetch/index.d.ts.map +0 -1
  233. package/output/services/cached-fetch/index.js +0 -196
  234. package/output/services/service/index.d.ts +0 -2
  235. package/output/services/service/index.d.ts.map +0 -1
  236. package/output/services/service/index.js +0 -1
  237. package/output/services/service/service.d.ts +0 -135
  238. package/output/services/service/service.d.ts.map +0 -1
  239. package/output/services/service/service.js +0 -276
  240. package/output/services/service/service.test.d.ts +0 -2
  241. package/output/services/service/service.test.d.ts.map +0 -1
  242. package/output/services/service/service.test.js +0 -1399
  243. package/output/services/side-cache/index.d.ts +0 -2
  244. package/output/services/side-cache/index.d.ts.map +0 -1
  245. package/output/services/side-cache/index.js +0 -1
  246. package/output/services/side-cache/side-cache.d.ts +0 -11
  247. package/output/services/side-cache/side-cache.d.ts.map +0 -1
  248. package/output/services/side-cache/side-cache.js +0 -161
  249. package/output/services/side-cache/side-cache.test.d.ts +0 -2
  250. package/output/services/side-cache/side-cache.test.d.ts.map +0 -1
  251. package/output/services/side-cache/side-cache.test.js +0 -271
  252. package/output/utils/avatar/index.d.ts +0 -28
  253. package/output/utils/avatar/index.d.ts.map +0 -1
  254. package/output/utils/avatar/index.js +0 -35
  255. package/output/utils/delay/index.d.ts +0 -2
  256. package/output/utils/delay/index.d.ts.map +0 -1
  257. package/output/utils/delay/index.js +0 -5
  258. package/output/utils/form/index.d.ts +0 -3
  259. package/output/utils/form/index.d.ts.map +0 -1
  260. package/output/utils/form/index.js +0 -1
  261. package/output/utils/merge-class-names/index.d.ts +0 -3
  262. package/output/utils/merge-class-names/index.d.ts.map +0 -1
  263. package/output/utils/merge-class-names/index.js +0 -5
  264. package/output/utils/merge-class-names/index.test.d.ts +0 -2
  265. package/output/utils/merge-class-names/index.test.d.ts.map +0 -1
  266. package/output/utils/merge-class-names/index.test.js +0 -7
  267. package/output/utils/performance/index.d.ts +0 -82
  268. package/output/utils/performance/index.d.ts.map +0 -1
  269. package/output/utils/performance/index.js +0 -129
  270. package/output/utils/redirect/index.d.ts +0 -6
  271. package/output/utils/redirect/index.d.ts.map +0 -1
  272. package/output/utils/redirect/index.js +0 -32
@@ -1,2 +0,0 @@
1
- export { SideCache } from './side-cache.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/services/side-cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA"}
@@ -1 +0,0 @@
1
- export { SideCache } from './side-cache.js';
@@ -1,11 +0,0 @@
1
- export declare class SideCache<T> {
2
- private accessor emptyFlag;
3
- private accessor currentKey;
4
- private accessor cache;
5
- get value(): T | undefined;
6
- get empty(): boolean;
7
- handle<F extends ((...args: unknown[]) => T)>(key: unknown, func: F): T;
8
- handle<F extends ((...args: unknown[]) => Promise<T> | T)>(key: unknown, func: F): Promise<T> | T;
9
- clear(key?: unknown): void;
10
- }
11
- //# sourceMappingURL=side-cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"side-cache.d.ts","sourceRoot":"","sources":["../../../source/services/side-cache/side-cache.ts"],"names":[],"mappings":"AAWA,qBAAa,SAAS,CAAC,CAAC;IAEtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAG1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAG/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAE1D,IACW,KAAK,IAAI,CAAC,GAAG,SAAS,CAIhC;IAED,IACW,KAAK,IAAI,OAAO,CAE1B;IAED,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;IACvE,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAyC1F,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI;CAoBlC"}
@@ -1,161 +0,0 @@
1
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
- var useValue = arguments.length > 2;
3
- for (var i = 0; i < initializers.length; i++) {
4
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
- }
6
- return useValue ? value : void 0;
7
- };
8
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
- var _, done = false;
14
- for (var i = decorators.length - 1; i >= 0; i--) {
15
- var context = {};
16
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
- if (kind === "accessor") {
21
- if (result === void 0) continue;
22
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
- if (_ = accept(result.get)) descriptor.get = _;
24
- if (_ = accept(result.set)) descriptor.set = _;
25
- if (_ = accept(result.init)) initializers.unshift(_);
26
- }
27
- else if (_ = accept(result)) {
28
- if (kind === "field") initializers.unshift(_);
29
- else descriptor[key] = _;
30
- }
31
- }
32
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
- done = true;
34
- };
35
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
38
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
- };
40
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
- if (kind === "m") throw new TypeError("Private method is not writable");
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
- };
46
- import { action, computed, observable, runInAction } from 'mobx';
47
- function isPromiseLike(value) {
48
- return value != null && typeof value.then === 'function';
49
- }
50
- let SideCache = (() => {
51
- var _a, _SideCache_emptyFlag_accessor_storage, _SideCache_currentKey_accessor_storage, _SideCache_cache_accessor_storage;
52
- var _b, _c, _d;
53
- let _instanceExtraInitializers = [];
54
- let _emptyFlag_decorators;
55
- let _emptyFlag_initializers = [];
56
- let _emptyFlag_extraInitializers = [];
57
- let _currentKey_decorators;
58
- let _currentKey_initializers = [];
59
- let _currentKey_extraInitializers = [];
60
- let _cache_decorators;
61
- let _cache_initializers = [];
62
- let _cache_extraInitializers = [];
63
- let _get_value_decorators;
64
- let _get_empty_decorators;
65
- let _handle_decorators;
66
- let _clear_decorators;
67
- return _a = class SideCache {
68
- get emptyFlag() { return __classPrivateFieldGet(this, _SideCache_emptyFlag_accessor_storage, "f"); }
69
- set emptyFlag(value) { __classPrivateFieldSet(this, _SideCache_emptyFlag_accessor_storage, value, "f"); }
70
- get currentKey() { return __classPrivateFieldGet(this, _SideCache_currentKey_accessor_storage, "f"); }
71
- set currentKey(value) { __classPrivateFieldSet(this, _SideCache_currentKey_accessor_storage, value, "f"); }
72
- get cache() { return __classPrivateFieldGet(this, _SideCache_cache_accessor_storage, "f"); }
73
- set cache(value) { __classPrivateFieldSet(this, _SideCache_cache_accessor_storage, value, "f"); }
74
- get value() {
75
- if (this.currentKey == null)
76
- return undefined;
77
- const cacheItem = this.cache[this.currentKey];
78
- return cacheItem ? cacheItem.data : undefined;
79
- }
80
- get empty() {
81
- return this.emptyFlag;
82
- }
83
- handle(key, func) {
84
- var _b;
85
- // 不需要跨设备、软件一致,所以直接用 JSON.stringify
86
- // 但需要处理 JSON.stringify(undefined) 返回 undefined 的情况
87
- const keyStringify = (_b = JSON.stringify(key)) !== null && _b !== void 0 ? _b : 'undefined';
88
- // 这会让外面立马可以拿到之前缓存的值,如果存在的话
89
- runInAction(() => this.currentKey = keyStringify);
90
- const funcReturn = func();
91
- if (isPromiseLike(funcReturn)) {
92
- return funcReturn.then(result => runInAction(() => {
93
- this.emptyFlag = false;
94
- this.cache = Object.assign(Object.assign({}, this.cache), { [keyStringify]: {
95
- data: result,
96
- createTime: new Date().toISOString()
97
- } });
98
- return result;
99
- }));
100
- }
101
- runInAction(() => {
102
- this.emptyFlag = false;
103
- this.cache = Object.assign(Object.assign({}, this.cache), { [keyStringify]: {
104
- data: funcReturn,
105
- createTime: new Date().toISOString()
106
- } });
107
- });
108
- return funcReturn;
109
- }
110
- clear(key) {
111
- var _b;
112
- if (key === undefined) {
113
- // 清除所有缓存
114
- this.cache = {};
115
- this.emptyFlag = true;
116
- this.currentKey = undefined;
117
- }
118
- else {
119
- // 清除指定 key 的缓存
120
- const keyStringify = (_b = JSON.stringify(key)) !== null && _b !== void 0 ? _b : 'undefined';
121
- const newCache = Object.assign({}, this.cache);
122
- delete newCache[keyStringify];
123
- this.cache = newCache;
124
- // 如果清除的是当前 key,需要重置状态
125
- if (this.currentKey === keyStringify) {
126
- this.emptyFlag = Object.keys(this.cache).length === 0;
127
- this.currentKey = undefined;
128
- }
129
- }
130
- }
131
- constructor() {
132
- _SideCache_emptyFlag_accessor_storage.set(this, (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _emptyFlag_initializers, true)));
133
- _SideCache_currentKey_accessor_storage.set(this, (__runInitializers(this, _emptyFlag_extraInitializers), __runInitializers(this, _currentKey_initializers, void 0)));
134
- _SideCache_cache_accessor_storage.set(this, (__runInitializers(this, _currentKey_extraInitializers), __runInitializers(this, _cache_initializers, {})));
135
- __runInitializers(this, _cache_extraInitializers);
136
- }
137
- },
138
- _SideCache_emptyFlag_accessor_storage = new WeakMap(),
139
- _SideCache_currentKey_accessor_storage = new WeakMap(),
140
- _SideCache_cache_accessor_storage = new WeakMap(),
141
- (() => {
142
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
143
- _emptyFlag_decorators = [observable];
144
- _currentKey_decorators = [observable];
145
- _cache_decorators = [(_b = observable).ref.bind(_b)];
146
- _get_value_decorators = [computed];
147
- _get_empty_decorators = [computed];
148
- _handle_decorators = [(_c = action).bound.bind(_c)];
149
- _clear_decorators = [(_d = action).bound.bind(_d)];
150
- __esDecorate(_a, null, _emptyFlag_decorators, { kind: "accessor", name: "emptyFlag", static: false, private: false, access: { has: obj => "emptyFlag" in obj, get: obj => obj.emptyFlag, set: (obj, value) => { obj.emptyFlag = value; } }, metadata: _metadata }, _emptyFlag_initializers, _emptyFlag_extraInitializers);
151
- __esDecorate(_a, null, _currentKey_decorators, { kind: "accessor", name: "currentKey", static: false, private: false, access: { has: obj => "currentKey" in obj, get: obj => obj.currentKey, set: (obj, value) => { obj.currentKey = value; } }, metadata: _metadata }, _currentKey_initializers, _currentKey_extraInitializers);
152
- __esDecorate(_a, null, _cache_decorators, { kind: "accessor", name: "cache", static: false, private: false, access: { has: obj => "cache" in obj, get: obj => obj.cache, set: (obj, value) => { obj.cache = value; } }, metadata: _metadata }, _cache_initializers, _cache_extraInitializers);
153
- __esDecorate(_a, null, _get_value_decorators, { kind: "getter", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value }, metadata: _metadata }, null, _instanceExtraInitializers);
154
- __esDecorate(_a, null, _get_empty_decorators, { kind: "getter", name: "empty", static: false, private: false, access: { has: obj => "empty" in obj, get: obj => obj.empty }, metadata: _metadata }, null, _instanceExtraInitializers);
155
- __esDecorate(_a, null, _handle_decorators, { kind: "method", name: "handle", static: false, private: false, access: { has: obj => "handle" in obj, get: obj => obj.handle }, metadata: _metadata }, null, _instanceExtraInitializers);
156
- __esDecorate(_a, null, _clear_decorators, { kind: "method", name: "clear", static: false, private: false, access: { has: obj => "clear" in obj, get: obj => obj.clear }, metadata: _metadata }, null, _instanceExtraInitializers);
157
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
158
- })(),
159
- _a;
160
- })();
161
- export { SideCache };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=side-cache.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"side-cache.test.d.ts","sourceRoot":"","sources":["../../../source/services/side-cache/side-cache.test.ts"],"names":[],"mappings":""}
@@ -1,271 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { runInAction } from 'mobx';
3
- import { SideCache } from './side-cache.js';
4
- describe('SideCache', () => {
5
- let cache;
6
- beforeEach(() => {
7
- cache = new SideCache();
8
- });
9
- describe('初始状态', () => {
10
- it('应该初始化为空状态', () => {
11
- expect(cache.empty).toBe(true);
12
- expect(cache.value).toBe(undefined);
13
- });
14
- });
15
- describe('同步缓存', () => {
16
- it('应该能够缓存同步函数的结果', () => {
17
- const mockFunc = vi.fn(() => 'test-result');
18
- const key = 'test-key';
19
- const result = cache.handle(key, mockFunc);
20
- expect(result).toBe('test-result');
21
- expect(mockFunc).toHaveBeenCalledTimes(1);
22
- expect(cache.empty).toBe(false);
23
- expect(cache.value).toBe('test-result');
24
- });
25
- it('应该对相同 key 返回缓存的结果', () => {
26
- const mockFunc = vi.fn(() => 'cached-result');
27
- const key = 'same-key';
28
- // 第一次调用
29
- const result1 = cache.handle(key, mockFunc);
30
- expect(result1).toBe('cached-result');
31
- expect(mockFunc).toHaveBeenCalledTimes(1);
32
- // 第二次调用相同 key,应该直接返回缓存
33
- const result2 = cache.handle(key, mockFunc);
34
- expect(result2).toBe('cached-result');
35
- expect(mockFunc).toHaveBeenCalledTimes(2); // 函数仍会被调用,但会更新缓存
36
- expect(cache.value).toBe('cached-result');
37
- });
38
- it('应该对不同 key 分别缓存', () => {
39
- const mockFunc1 = vi.fn(() => 'result1');
40
- const mockFunc2 = vi.fn(() => 'result2');
41
- cache.handle('key1', mockFunc1);
42
- expect(cache.value).toBe('result1');
43
- cache.handle('key2', mockFunc2);
44
- expect(cache.value).toBe('result2');
45
- // 切换回 key1
46
- cache.handle('key1', mockFunc1);
47
- expect(cache.value).toBe('result1');
48
- });
49
- });
50
- describe('异步缓存', () => {
51
- it('应该能够缓存异步函数的结果', async () => {
52
- const mockAsyncFunc = vi.fn(async () => 'async-result');
53
- const key = 'async-key';
54
- const promise = cache.handle(key, mockAsyncFunc);
55
- expect(promise).toBeInstanceOf(Promise);
56
- const result = await promise;
57
- expect(result).toBe('async-result');
58
- expect(mockAsyncFunc).toHaveBeenCalledTimes(1);
59
- expect(cache.empty).toBe(false);
60
- expect(cache.value).toBe('async-result');
61
- });
62
- it('应该在异步函数执行期间立即设置 currentKey', async () => {
63
- const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
64
- const mockAsyncFunc = vi.fn(async () => {
65
- await delay(10);
66
- return 'delayed-result';
67
- });
68
- const key = 'delayed-key';
69
- // 在异步函数开始执行时,currentKey 应该已经设置
70
- const promise = cache.handle(key, mockAsyncFunc);
71
- // 此时异步函数还在执行,但 currentKey 已设置
72
- // 如果之前有缓存,value 应该能立即获取到
73
- const result = await promise;
74
- expect(result).toBe('delayed-result');
75
- expect(cache.value).toBe('delayed-result');
76
- });
77
- it('应该处理异步函数的错误', async () => {
78
- const error = new Error('Async error');
79
- const mockAsyncFunc = vi.fn(async () => {
80
- throw error;
81
- });
82
- const key = 'error-key';
83
- await expect(cache.handle(key, mockAsyncFunc)).rejects.toThrow('Async error');
84
- expect(mockAsyncFunc).toHaveBeenCalledTimes(1);
85
- });
86
- });
87
- describe('key 序列化', () => {
88
- it('应该正确处理不同类型的 key', () => {
89
- const mockFunc = vi.fn(() => 'result');
90
- // 字符串 key
91
- cache.handle('string-key', mockFunc);
92
- expect(cache.value).toBe('result');
93
- // 数字 key
94
- cache.handle(123, mockFunc);
95
- expect(cache.value).toBe('result');
96
- // 对象 key
97
- cache.handle({ id: 1, name: 'test' }, mockFunc);
98
- expect(cache.value).toBe('result');
99
- // 数组 key
100
- cache.handle([1, 2, 3], mockFunc);
101
- expect(cache.value).toBe('result');
102
- });
103
- it('相同内容的对象 key 应该被视为相同', () => {
104
- const mockFunc = vi.fn(() => 'object-result');
105
- const key1 = { id: 1, name: 'test' };
106
- const key2 = { id: 1, name: 'test' };
107
- cache.handle(key1, mockFunc);
108
- const result1 = cache.value;
109
- cache.handle(key2, mockFunc);
110
- const result2 = cache.value;
111
- expect(result1).toBe(result2);
112
- expect(result1).toBe('object-result');
113
- });
114
- });
115
- describe('缓存时间戳', () => {
116
- it('应该为缓存项添加创建时间', () => {
117
- const mockFunc = vi.fn(() => 'timestamped-result');
118
- const key = 'timestamp-key';
119
- const beforeTime = new Date().toISOString();
120
- cache.handle(key, mockFunc);
121
- const afterTime = new Date().toISOString();
122
- // 访问私有属性进行测试(仅用于测试目的)
123
- const cacheData = cache.cache;
124
- const cachedItem = cacheData[JSON.stringify(key)];
125
- expect(cachedItem).toBeDefined();
126
- expect(cachedItem.data).toBe('timestamped-result');
127
- expect(cachedItem.createTime).toBeDefined();
128
- expect(typeof cachedItem.createTime).toBe('string');
129
- // 验证时间戳在合理范围内
130
- expect(cachedItem.createTime >= beforeTime).toBe(true);
131
- expect(cachedItem.createTime <= afterTime).toBe(true);
132
- });
133
- });
134
- describe('边界情况', () => {
135
- it('应该处理 null 和 undefined key', () => {
136
- const mockFunc1 = vi.fn(() => 'null-key-result');
137
- const mockFunc2 = vi.fn(() => 'undefined-key-result');
138
- cache.handle(null, mockFunc1);
139
- expect(cache.value).toBe('null-key-result');
140
- cache.handle(undefined, mockFunc2);
141
- expect(cache.value).toBe('undefined-key-result');
142
- });
143
- it('应该处理返回 null 或 undefined 的函数', () => {
144
- const nullFunc = vi.fn(() => null);
145
- const undefinedFunc = vi.fn(() => undefined);
146
- cache.handle('null-key', nullFunc);
147
- expect(cache.value).toBe(null);
148
- expect(cache.empty).toBe(false);
149
- cache.handle('undefined-key', undefinedFunc);
150
- expect(cache.value).toBe(undefined);
151
- expect(cache.empty).toBe(false);
152
- });
153
- it('应该处理返回 Promise.resolve(null) 的异步函数', async () => {
154
- const nullAsyncFunc = vi.fn(async () => null);
155
- const result = await cache.handle('async-null', nullAsyncFunc);
156
- expect(result).toBe(null);
157
- expect(cache.value).toBe(null);
158
- expect(cache.empty).toBe(false);
159
- });
160
- });
161
- describe('类型检查', () => {
162
- it('应该正确识别 Promise-like 对象', async () => {
163
- let thenCallback;
164
- const promiseLike = {
165
- then: vi.fn((callback) => {
166
- thenCallback = callback;
167
- return promiseLike;
168
- })
169
- };
170
- const mockFunc = vi.fn(() => promiseLike);
171
- const result = cache.handle('promise-like', mockFunc);
172
- expect(result).toBe(promiseLike);
173
- expect(promiseLike.then).toHaveBeenCalled();
174
- // 模拟 Promise 完成
175
- if (thenCallback) {
176
- thenCallback('resolved-value');
177
- }
178
- });
179
- });
180
- describe('clear 方法', () => {
181
- it('应该能够清除指定 key 的缓存', () => {
182
- const mockFunc = vi.fn(() => 'test-result');
183
- const key = 'test-key';
184
- // 先添加缓存
185
- cache.handle(key, mockFunc);
186
- expect(cache.empty).toBe(false);
187
- expect(cache.value).toBe('test-result');
188
- // 清除指定 key 的缓存
189
- cache.clear(key);
190
- expect(cache.empty).toBe(true);
191
- expect(cache.value).toBe(undefined);
192
- });
193
- it('应该能够清除当前激活的缓存', () => {
194
- const mockFunc = vi.fn(() => 'active-result');
195
- const key = 'active-key';
196
- cache.handle(key, mockFunc);
197
- expect(cache.value).toBe('active-result');
198
- // 清除当前激活的 key
199
- cache.clear(key);
200
- expect(cache.value).toBe(undefined);
201
- expect(cache.empty).toBe(true);
202
- });
203
- it('应该能够清除所有缓存', () => {
204
- const mockFunc1 = vi.fn(() => 'result1');
205
- const mockFunc2 = vi.fn(() => 'result2');
206
- // 添加多个缓存
207
- cache.handle('key1', mockFunc1);
208
- cache.handle('key2', mockFunc2);
209
- expect(cache.value).toBe('result2');
210
- expect(cache.empty).toBe(false);
211
- // 清除所有缓存
212
- cache.clear();
213
- expect(cache.value).toBe(undefined);
214
- expect(cache.empty).toBe(true);
215
- });
216
- it('应该能够清除非当前激活的缓存而不影响当前状态', () => {
217
- const mockFunc1 = vi.fn(() => 'result1');
218
- const mockFunc2 = vi.fn(() => 'result2');
219
- // 添加两个缓存
220
- cache.handle('key1', mockFunc1);
221
- cache.handle('key2', mockFunc2);
222
- expect(cache.value).toBe('result2'); // 当前激活的是 key2
223
- // 清除非当前激活的 key1
224
- cache.clear('key1');
225
- expect(cache.value).toBe('result2'); // 当前值不变
226
- expect(cache.empty).toBe(false); // 仍有缓存存在
227
- });
228
- it('应该正确处理清除不存在的 key', () => {
229
- const mockFunc = vi.fn(() => 'test-result');
230
- cache.handle('existing-key', mockFunc);
231
- // 清除不存在的 key 不应该影响现有缓存
232
- cache.clear('non-existing-key');
233
- expect(cache.value).toBe('test-result');
234
- expect(cache.empty).toBe(false);
235
- });
236
- it('应该正确处理复杂对象作为 key', () => {
237
- const complexKey = { id: 1, data: { nested: 'value' } };
238
- const mockFunc = vi.fn(() => 'complex-result');
239
- // 使用复杂对象作为 key
240
- cache.handle(complexKey, mockFunc);
241
- expect(cache.value).toBe('complex-result');
242
- // 清除复杂对象 key
243
- cache.clear(complexKey);
244
- expect(cache.value).toBe(undefined);
245
- expect(cache.empty).toBe(true);
246
- });
247
- it('应该正确处理 undefined 作为 key', () => {
248
- const mockFunc = vi.fn(() => 'undefined-key-result');
249
- // 使用 undefined 作为 key
250
- cache.handle(undefined, mockFunc);
251
- expect(cache.value).toBe('undefined-key-result');
252
- // 清除 undefined key
253
- cache.clear(undefined);
254
- expect(cache.value).toBe(undefined);
255
- expect(cache.empty).toBe(true);
256
- });
257
- it('应该在 MobX action 中正确更新状态', () => {
258
- const mockFunc = vi.fn(() => 'action-result');
259
- const key = 'action-key';
260
- runInAction(() => {
261
- cache.handle(key, mockFunc);
262
- });
263
- expect(cache.value).toBe('action-result');
264
- runInAction(() => {
265
- cache.clear(key);
266
- });
267
- expect(cache.value).toBe(undefined);
268
- expect(cache.empty).toBe(true);
269
- });
270
- });
271
- });
@@ -1,28 +0,0 @@
1
- /**
2
- * Avatar 工具函数
3
- * 用于生成用户头像 URL
4
- */
5
- /**
6
- * 使用原生 Web Crypto API 生成 SHA-256 哈希
7
- * @param input 输入字符串
8
- * @returns SHA-256 哈希值(十六进制字符串)
9
- */
10
- export type GetUserAvatarUrlParams = {
11
- username: string;
12
- avatar?: string | null;
13
- };
14
- /**
15
- * 生成 Gravatar 头像 URL
16
- * @param email 用户邮箱
17
- * @param size 头像大小(像素)
18
- * @returns Gravatar URL
19
- */
20
- export declare function getGravatarUrl(email: string, size?: number): Promise<string>;
21
- /**
22
- * 生成用户头像 URL
23
- * @param user 用户对象
24
- * @param size 头像大小(像素)
25
- * @returns 头像 URL(如果有自定义头像返回自定义,否则返回 Gravatar)
26
- */
27
- export declare function getUserAvatarUrl(user: GetUserAvatarUrlParams, size?: number): Promise<string>;
28
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/avatar/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAWjF;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9E;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,EAAE,IAAI,SAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAK/F"}
@@ -1,35 +0,0 @@
1
- /**
2
- * Avatar 工具函数
3
- * 用于生成用户头像 URL
4
- */
5
- async function sha256(input) {
6
- const encoder = new TextEncoder();
7
- const data = encoder.encode(input);
8
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
9
- const hashArray = Array.from(new Uint8Array(hashBuffer));
10
- return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
11
- }
12
- /**
13
- * 生成 Gravatar 头像 URL
14
- * @param email 用户邮箱
15
- * @param size 头像大小(像素)
16
- * @returns Gravatar URL
17
- */
18
- export async function getGravatarUrl(email, size = 80) {
19
- const trimmedEmail = email.trim();
20
- const lowerEmail = trimmedEmail.toLowerCase();
21
- const hash = await sha256(lowerEmail);
22
- return `https://www.gravatar.com/avatar/${hash}?d=mp&s=${size}`;
23
- }
24
- /**
25
- * 生成用户头像 URL
26
- * @param user 用户对象
27
- * @param size 头像大小(像素)
28
- * @returns 头像 URL(如果有自定义头像返回自定义,否则返回 Gravatar)
29
- */
30
- export async function getUserAvatarUrl(user, size = 80) {
31
- if (user.avatar) {
32
- return user.avatar;
33
- }
34
- return getGravatarUrl(user.username, size);
35
- }
@@ -1,2 +0,0 @@
1
- export declare function delay(ms: number): Promise<unknown>;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/delay/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAI/B"}
@@ -1,5 +0,0 @@
1
- export function delay(ms) {
2
- return new Promise(resolve => {
3
- setTimeout(resolve, ms);
4
- });
5
- }
@@ -1,3 +0,0 @@
1
- export type FormValidateResult<E extends string> = E | undefined | Promise<E | undefined>;
2
- export type FormValidate<T extends object, K extends keyof T, E extends string> = (field: T[K], form: T) => FormValidateResult<E>;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/form/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;AACzF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { type ClassValue } from 'clsx';
2
- export declare function mergeClassNames(...inputs: ClassValue[]): string;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/merge-class-names/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAA;AAG5C,wBAAgB,eAAe,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEtD"}
@@ -1,5 +0,0 @@
1
- import { clsx } from 'clsx';
2
- import { twMerge } from 'tailwind-merge';
3
- export function mergeClassNames(...inputs) {
4
- return twMerge(clsx(inputs));
5
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../source/utils/merge-class-names/index.test.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { mergeClassNames } from './index.js';
3
- describe('mergeClassNames', () => {
4
- it('merges conditional and conflicting Tailwind classes', () => {
5
- expect(mergeClassNames('px-2', false && 'text-muted-foreground', 'px-4')).toBe('px-4');
6
- });
7
- });