@taicode/common-web 3.0.1 → 3.2.0

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 (406) hide show
  1. package/output/components/alert-dialog.d.ts +20 -0
  2. package/output/components/alert-dialog.d.ts.map +1 -0
  3. package/output/components/alert-dialog.js +65 -0
  4. package/output/components/alert.d.ts +11 -0
  5. package/output/components/alert.d.ts.map +1 -0
  6. package/output/components/alert.js +38 -0
  7. package/output/components/avatar.d.ts +13 -0
  8. package/output/components/avatar.d.ts.map +1 -0
  9. package/output/components/avatar.js +40 -0
  10. package/output/components/badge.d.ts +10 -0
  11. package/output/components/badge.d.ts.map +1 -0
  12. package/output/components/badge.js +31 -0
  13. package/output/components/button.d.ts +12 -0
  14. package/output/components/button.d.ts.map +1 -0
  15. package/output/components/button.js +44 -0
  16. package/output/components/card.d.ts +8 -0
  17. package/output/components/card.d.ts.map +1 -0
  18. package/output/components/card.js +38 -0
  19. package/output/components/checkbox.d.ts +5 -0
  20. package/output/components/checkbox.d.ts.map +1 -0
  21. package/output/components/checkbox.js +21 -0
  22. package/output/components/command.d.ts +20 -0
  23. package/output/components/command.d.ts.map +1 -0
  24. package/output/components/command.js +55 -0
  25. package/output/components/dialog.d.ts +20 -0
  26. package/output/components/dialog.d.ts.map +1 -0
  27. package/output/components/dialog.js +58 -0
  28. package/output/components/direction.d.ts +9 -0
  29. package/output/components/direction.d.ts.map +1 -0
  30. package/output/components/direction.js +10 -0
  31. package/output/components/dropdown-menu.d.ts +29 -0
  32. package/output/components/dropdown-menu.d.ts.map +1 -0
  33. package/output/components/dropdown-menu.js +78 -0
  34. package/output/components/field.d.ts +39 -0
  35. package/output/components/field.d.ts.map +1 -0
  36. package/output/components/field.js +102 -0
  37. package/output/components/index.d.ts +36 -0
  38. package/output/components/index.d.ts.map +1 -0
  39. package/output/components/index.js +35 -0
  40. package/output/components/input-group.d.ts +17 -0
  41. package/output/components/input-group.d.ts.map +1 -0
  42. package/output/components/input-group.js +75 -0
  43. package/output/components/input.d.ts +3 -0
  44. package/output/components/input.d.ts.map +1 -0
  45. package/output/components/input.js +19 -0
  46. package/output/components/item.d.ts +25 -0
  47. package/output/components/item.d.ts.map +1 -0
  48. package/output/components/item.js +89 -0
  49. package/output/components/json-view/index.d.ts +11 -0
  50. package/output/components/json-view/index.d.ts.map +1 -0
  51. package/output/components/json-view/index.js +52 -0
  52. package/output/components/kbd.d.ts +4 -0
  53. package/output/components/kbd.d.ts.map +1 -0
  54. package/output/components/kbd.js +22 -0
  55. package/output/components/label.d.ts +5 -0
  56. package/output/components/label.d.ts.map +1 -0
  57. package/output/components/label.js +20 -0
  58. package/output/{loading-button → components/loading-button}/index.d.ts +1 -1
  59. package/output/components/loading-button/index.d.ts.map +1 -0
  60. package/output/{loading-button → components/loading-button}/index.js +3 -7
  61. package/output/components/loading-button/index.test.d.ts.map +1 -0
  62. package/output/{loading-button → components/loading-button}/index.test.js +4 -4
  63. package/output/components/native-select.d.ts +9 -0
  64. package/output/components/native-select.d.ts.map +1 -0
  65. package/output/components/native-select.js +28 -0
  66. package/output/components/page-state.d.ts +19 -0
  67. package/output/components/page-state.d.ts.map +1 -0
  68. package/output/components/page-state.js +13 -0
  69. package/output/components/popover.d.ts +11 -0
  70. package/output/components/popover.d.ts.map +1 -0
  71. package/output/components/popover.js +44 -0
  72. package/output/components/progress.d.ts +5 -0
  73. package/output/components/progress.d.ts.map +1 -0
  74. package/output/components/progress.js +21 -0
  75. package/output/components/radio-group.d.ts +6 -0
  76. package/output/components/radio-group.d.ts.map +1 -0
  77. package/output/components/radio-group.js +25 -0
  78. package/output/components/scroll-area.d.ts +6 -0
  79. package/output/components/scroll-area.d.ts.map +1 -0
  80. package/output/components/scroll-area.js +24 -0
  81. package/output/components/select.d.ts +17 -0
  82. package/output/components/select.d.ts.map +1 -0
  83. package/output/components/select.js +58 -0
  84. package/output/components/separator.d.ts +6 -0
  85. package/output/components/separator.d.ts.map +1 -0
  86. package/output/components/separator.js +19 -0
  87. package/output/components/sheet.d.ts +16 -0
  88. package/output/components/sheet.d.ts.map +1 -0
  89. package/output/components/sheet.js +58 -0
  90. package/output/components/size-provider/index.d.ts +2 -0
  91. package/output/components/size-provider/index.d.ts.map +1 -0
  92. package/output/components/size-provider/index.js +1 -0
  93. package/output/{size-provider → components/size-provider}/size-provider.d.ts +1 -1
  94. package/output/components/size-provider/size-provider.d.ts.map +1 -0
  95. package/output/{size-provider → components/size-provider}/size-provider.js +1 -1
  96. package/output/components/skeleton.d.ts +3 -0
  97. package/output/components/skeleton.d.ts.map +1 -0
  98. package/output/{catalyst/divider.js → components/skeleton.js} +4 -4
  99. package/output/components/sonner.d.ts +8 -0
  100. package/output/components/sonner.d.ts.map +1 -0
  101. package/output/components/sonner.js +34 -0
  102. package/output/components/spinner.d.ts +3 -0
  103. package/output/components/spinner.d.ts.map +1 -0
  104. package/output/{catalyst/divider.jsx → components/spinner.js} +7 -4
  105. package/output/components/switch.d.ts +8 -0
  106. package/output/components/switch.d.ts.map +1 -0
  107. package/output/components/switch.js +20 -0
  108. package/output/components/table.d.ts +11 -0
  109. package/output/components/table.d.ts.map +1 -0
  110. package/output/components/table.js +47 -0
  111. package/output/components/tabs.d.ts +12 -0
  112. package/output/components/tabs.d.ts.map +1 -0
  113. package/output/components/tabs.js +45 -0
  114. package/output/components/textarea.d.ts +4 -0
  115. package/output/components/textarea.d.ts.map +1 -0
  116. package/output/components/textarea.js +19 -0
  117. package/output/components/theme-switcher.d.ts +6 -0
  118. package/output/components/theme-switcher.d.ts.map +1 -0
  119. package/output/components/theme-switcher.js +19 -0
  120. package/output/{toaster → components/toaster}/index.d.ts +1 -1
  121. package/output/components/toaster/index.d.ts.map +1 -0
  122. package/output/{toaster → components/toaster}/index.js +1 -1
  123. package/output/components/tooltip.d.ts +8 -0
  124. package/output/components/tooltip.d.ts.map +1 -0
  125. package/output/components/tooltip.js +33 -0
  126. package/output/features/confirm-dialog/index.d.ts +39 -0
  127. package/output/features/confirm-dialog/index.d.ts.map +1 -0
  128. package/output/features/confirm-dialog/index.js +19 -0
  129. package/output/features/input-confirm/index.d.ts +26 -0
  130. package/output/features/input-confirm/index.d.ts.map +1 -0
  131. package/output/features/input-confirm/index.js +59 -0
  132. package/output/{signin → features/signin}/context.d.ts +1 -2
  133. package/output/features/signin/context.d.ts.map +1 -0
  134. package/output/{signin → features/signin}/context.js +3 -3
  135. package/output/{signin → features/signin}/index.d.ts +4 -4
  136. package/output/features/signin/index.d.ts.map +1 -0
  137. package/output/{signin → features/signin}/index.js +9 -9
  138. package/output/{signin → features/signin}/service.d.ts +1 -1
  139. package/output/features/signin/service.d.ts.map +1 -0
  140. package/output/{signin → features/signin}/service.js +1 -4
  141. package/output/features/signin/service.test.d.ts.map +1 -0
  142. package/output/{signin → features/signin}/service.test.js +1 -1
  143. package/output/features/signin/types.d.ts.map +1 -0
  144. package/output/hooks/use-loading/index.d.ts +6 -0
  145. package/output/hooks/use-loading/index.d.ts.map +1 -0
  146. package/output/hooks/use-loading/index.js +14 -0
  147. package/output/hooks/use-loading/index.test.d.ts +2 -0
  148. package/output/hooks/use-loading/index.test.d.ts.map +1 -0
  149. package/output/hooks/use-loading/index.test.js +24 -0
  150. package/output/hooks/use-mobile/index.d.ts +2 -0
  151. package/output/hooks/use-mobile/index.d.ts.map +1 -0
  152. package/output/hooks/use-mobile/index.js +16 -0
  153. package/output/hooks/use-observer/index.d.ts +2 -0
  154. package/output/hooks/use-observer/index.d.ts.map +1 -0
  155. package/output/hooks/use-observer/index.js +1 -0
  156. package/output/hooks/use-observer/use-observer.d.ts.map +1 -0
  157. package/output/{helpers → hooks}/use-observer/use-observer.js +2 -2
  158. package/output/hooks/use-observer/use-observer.test.d.ts.map +1 -0
  159. package/output/{use-observer → hooks/use-observer}/use-observer.test.js +2 -2
  160. package/output/hooks/use-offline/index.d.ts +6 -0
  161. package/output/hooks/use-offline/index.d.ts.map +1 -0
  162. package/output/hooks/use-offline/index.js +19 -0
  163. package/output/layout/app/index.d.ts +34 -0
  164. package/output/layout/app/index.d.ts.map +1 -0
  165. package/output/layout/app/index.js +34 -0
  166. package/output/layout/dashboard/index.d.ts +58 -0
  167. package/output/layout/dashboard/index.d.ts.map +1 -0
  168. package/output/layout/dashboard/index.js +71 -0
  169. package/output/layout/index.d.ts +3 -0
  170. package/output/layout/index.d.ts.map +1 -0
  171. package/output/layout/index.js +2 -0
  172. package/output/services/cache-api/cache-api.d.ts.map +1 -0
  173. package/output/{cache-api → services/cache-api}/cache-api.js +1 -1
  174. package/output/services/cache-api/cache-api.test.d.ts.map +1 -0
  175. package/output/{cache-api → services/cache-api}/cache-api.test.js +1 -1
  176. package/output/services/cache-api/index.d.ts +2 -0
  177. package/output/services/cache-api/index.d.ts.map +1 -0
  178. package/output/services/cache-api/index.js +1 -0
  179. package/output/{service → services/service}/index.d.ts +1 -1
  180. package/output/services/service/index.d.ts.map +1 -0
  181. package/output/{service → services/service}/index.js +1 -1
  182. package/output/services/service/service.d.ts +135 -0
  183. package/output/services/service/service.d.ts.map +1 -0
  184. package/output/services/service/service.js +276 -0
  185. package/output/services/service/service.test.d.ts.map +1 -0
  186. package/output/{service → services/service}/service.test.js +1 -1
  187. package/output/services/side-cache/index.d.ts +2 -0
  188. package/output/services/side-cache/index.d.ts.map +1 -0
  189. package/output/services/side-cache/index.js +1 -0
  190. package/output/services/side-cache/side-cache.d.ts.map +1 -0
  191. package/output/services/side-cache/side-cache.test.d.ts.map +1 -0
  192. package/output/{side-cache → services/side-cache}/side-cache.test.js +1 -1
  193. package/output/utils/avatar/index.d.ts +28 -0
  194. package/output/utils/avatar/index.d.ts.map +1 -0
  195. package/output/utils/avatar/index.js +35 -0
  196. package/output/utils/cn/index.d.ts +3 -0
  197. package/output/utils/cn/index.d.ts.map +1 -0
  198. package/output/utils/cn/index.js +5 -0
  199. package/output/utils/cn/index.test.d.ts +2 -0
  200. package/output/utils/cn/index.test.d.ts.map +1 -0
  201. package/output/utils/cn/index.test.js +7 -0
  202. package/output/utils/delay/index.d.ts +2 -0
  203. package/output/utils/delay/index.d.ts.map +1 -0
  204. package/output/utils/delay/index.js +5 -0
  205. package/output/utils/form/index.d.ts +3 -0
  206. package/output/utils/form/index.d.ts.map +1 -0
  207. package/output/utils/form/index.js +1 -0
  208. package/output/utils/performance/index.d.ts +82 -0
  209. package/output/utils/performance/index.d.ts.map +1 -0
  210. package/output/utils/performance/index.js +129 -0
  211. package/output/utils/redirect/index.d.ts +6 -0
  212. package/output/utils/redirect/index.d.ts.map +1 -0
  213. package/output/utils/redirect/index.js +32 -0
  214. package/package.json +117 -28
  215. package/styles.css +123 -0
  216. package/output/cache-api/cache-api.d.ts.map +0 -1
  217. package/output/cache-api/cache-api.test.d.ts.map +0 -1
  218. package/output/cache-api/index.d.ts +0 -2
  219. package/output/cache-api/index.d.ts.map +0 -1
  220. package/output/cache-api/index.js +0 -1
  221. package/output/catalyst/alert.d.ts +0 -29
  222. package/output/catalyst/alert.d.ts.map +0 -1
  223. package/output/catalyst/alert.js +0 -46
  224. package/output/catalyst/alert.jsx +0 -55
  225. package/output/catalyst/auth-layout.d.ts +0 -5
  226. package/output/catalyst/auth-layout.d.ts.map +0 -1
  227. package/output/catalyst/auth-layout.js +0 -4
  228. package/output/catalyst/auth-layout.jsx +0 -7
  229. package/output/catalyst/avatar.d.ts +0 -16
  230. package/output/catalyst/avatar.d.ts.map +0 -1
  231. package/output/catalyst/avatar.js +0 -30
  232. package/output/catalyst/avatar.jsx +0 -45
  233. package/output/catalyst/badge.d.ts +0 -35
  234. package/output/catalyst/badge.d.ts.map +0 -1
  235. package/output/catalyst/badge.js +0 -46
  236. package/output/catalyst/badge.jsx +0 -53
  237. package/output/catalyst/button.d.ts +0 -59
  238. package/output/catalyst/button.d.ts.map +0 -1
  239. package/output/catalyst/button.js +0 -181
  240. package/output/catalyst/button.jsx +0 -187
  241. package/output/catalyst/checkbox.d.ts +0 -37
  242. package/output/catalyst/checkbox.d.ts.map +0 -1
  243. package/output/catalyst/checkbox.js +0 -97
  244. package/output/catalyst/checkbox.jsx +0 -105
  245. package/output/catalyst/combobox.d.ts +0 -20
  246. package/output/catalyst/combobox.d.ts.map +0 -1
  247. package/output/catalyst/combobox.js +0 -101
  248. package/output/catalyst/combobox.jsx +0 -120
  249. package/output/catalyst/description-list.d.ts +0 -4
  250. package/output/catalyst/description-list.d.ts.map +0 -1
  251. package/output/catalyst/description-list.js +0 -25
  252. package/output/catalyst/description-list.jsx +0 -24
  253. package/output/catalyst/dialog.d.ts +0 -29
  254. package/output/catalyst/dialog.d.ts.map +0 -1
  255. package/output/catalyst/dialog.js +0 -46
  256. package/output/catalyst/dialog.jsx +0 -55
  257. package/output/catalyst/divider.d.ts +0 -4
  258. package/output/catalyst/divider.d.ts.map +0 -1
  259. package/output/catalyst/dropdown.d.ts +0 -33
  260. package/output/catalyst/dropdown.d.ts.map +0 -1
  261. package/output/catalyst/dropdown.js +0 -99
  262. package/output/catalyst/dropdown.jsx +0 -102
  263. package/output/catalyst/fieldset.d.ts +0 -22
  264. package/output/catalyst/fieldset.d.ts.map +0 -1
  265. package/output/catalyst/fieldset.js +0 -42
  266. package/output/catalyst/fieldset.jsx +0 -41
  267. package/output/catalyst/heading.d.ts +0 -7
  268. package/output/catalyst/heading.d.ts.map +0 -1
  269. package/output/catalyst/heading.js +0 -23
  270. package/output/catalyst/heading.jsx +0 -22
  271. package/output/catalyst/input.d.ts +0 -11
  272. package/output/catalyst/input.d.ts.map +0 -1
  273. package/output/catalyst/input.js +0 -70
  274. package/output/catalyst/input.jsx +0 -73
  275. package/output/catalyst/link.d.ts +0 -13
  276. package/output/catalyst/link.d.ts.map +0 -1
  277. package/output/catalyst/link.js +0 -37
  278. package/output/catalyst/link.jsx +0 -14
  279. package/output/catalyst/listbox.d.ts +0 -16
  280. package/output/catalyst/listbox.d.ts.map +0 -1
  281. package/output/catalyst/listbox.js +0 -99
  282. package/output/catalyst/listbox.jsx +0 -120
  283. package/output/catalyst/navbar.d.ts +0 -16
  284. package/output/catalyst/navbar.d.ts.map +0 -1
  285. package/output/catalyst/navbar.js +0 -59
  286. package/output/catalyst/navbar.jsx +0 -67
  287. package/output/catalyst/pagination.d.ts +0 -18
  288. package/output/catalyst/pagination.d.ts.map +0 -1
  289. package/output/catalyst/pagination.js +0 -35
  290. package/output/catalyst/pagination.jsx +0 -52
  291. package/output/catalyst/radio.d.ts +0 -38
  292. package/output/catalyst/radio.d.ts.map +0 -1
  293. package/output/catalyst/radio.js +0 -100
  294. package/output/catalyst/radio.jsx +0 -103
  295. package/output/catalyst/select.d.ts +0 -6
  296. package/output/catalyst/select.d.ts.map +0 -1
  297. package/output/catalyst/select.js +0 -52
  298. package/output/catalyst/select.jsx +0 -59
  299. package/output/catalyst/sidebar-layout.d.ts +0 -6
  300. package/output/catalyst/sidebar-layout.d.ts.map +0 -1
  301. package/output/catalyst/sidebar-layout.js +0 -18
  302. package/output/catalyst/sidebar-layout.jsx +0 -58
  303. package/output/catalyst/sidebar.d.ts +0 -20
  304. package/output/catalyst/sidebar.d.ts.map +0 -1
  305. package/output/catalyst/sidebar.js +0 -77
  306. package/output/catalyst/sidebar.jsx +0 -85
  307. package/output/catalyst/stacked-layout.d.ts +0 -6
  308. package/output/catalyst/stacked-layout.d.ts.map +0 -1
  309. package/output/catalyst/stacked-layout.js +0 -18
  310. package/output/catalyst/stacked-layout.jsx +0 -55
  311. package/output/catalyst/switch.d.ts +0 -37
  312. package/output/catalyst/switch.d.ts.map +0 -1
  313. package/output/catalyst/switch.js +0 -160
  314. package/output/catalyst/switch.jsx +0 -161
  315. package/output/catalyst/table.d.ts +0 -17
  316. package/output/catalyst/table.d.ts.map +0 -1
  317. package/output/catalyst/table.js +0 -56
  318. package/output/catalyst/table.jsx +0 -68
  319. package/output/catalyst/text.d.ts +0 -6
  320. package/output/catalyst/text.d.ts.map +0 -1
  321. package/output/catalyst/text.js +0 -30
  322. package/output/catalyst/text.jsx +0 -29
  323. package/output/catalyst/textarea.d.ts +0 -7
  324. package/output/catalyst/textarea.d.ts.map +0 -1
  325. package/output/catalyst/textarea.js +0 -48
  326. package/output/catalyst/textarea.jsx +0 -49
  327. package/output/catalyst-config/catalyst-config.d.ts +0 -14
  328. package/output/catalyst-config/catalyst-config.d.ts.map +0 -1
  329. package/output/catalyst-config/catalyst-config.js +0 -14
  330. package/output/catalyst-config/index.d.ts +0 -3
  331. package/output/catalyst-config/index.d.ts.map +0 -1
  332. package/output/catalyst-config/index.js +0 -1
  333. package/output/helpers/cache-api/cache-api.d.ts +0 -13
  334. package/output/helpers/cache-api/cache-api.d.ts.map +0 -1
  335. package/output/helpers/cache-api/cache-api.js +0 -114
  336. package/output/helpers/cache-api/cache-api.test.d.ts +0 -2
  337. package/output/helpers/cache-api/cache-api.test.d.ts.map +0 -1
  338. package/output/helpers/cache-api/cache-api.test.js +0 -348
  339. package/output/helpers/cache-api/index.d.ts +0 -2
  340. package/output/helpers/cache-api/index.d.ts.map +0 -1
  341. package/output/helpers/cache-api/index.js +0 -1
  342. package/output/helpers/service/index.d.ts +0 -1
  343. package/output/helpers/service/index.d.ts.map +0 -1
  344. package/output/helpers/service/index.js +0 -1
  345. package/output/helpers/service/service.d.ts +0 -5
  346. package/output/helpers/service/service.d.ts.map +0 -1
  347. package/output/helpers/service/service.js +0 -2
  348. package/output/helpers/side-cache/index.d.ts +0 -2
  349. package/output/helpers/side-cache/index.d.ts.map +0 -1
  350. package/output/helpers/side-cache/index.js +0 -1
  351. package/output/helpers/side-cache/side-cache.d.ts +0 -10
  352. package/output/helpers/side-cache/side-cache.d.ts.map +0 -1
  353. package/output/helpers/side-cache/side-cache.js +0 -137
  354. package/output/helpers/side-cache/side-cache.test.d.ts.map +0 -1
  355. package/output/helpers/side-cache/side-cache.test.js +0 -179
  356. package/output/helpers/use-observer/index.d.ts +0 -2
  357. package/output/helpers/use-observer/index.d.ts.map +0 -1
  358. package/output/helpers/use-observer/index.js +0 -1
  359. package/output/helpers/use-observer/use-observer.d.ts.map +0 -1
  360. package/output/helpers/use-observer/use-observer.test.d.ts.map +0 -1
  361. package/output/helpers/use-observer/use-observer.test.jsx +0 -134
  362. package/output/loading-button/index.d.ts.map +0 -1
  363. package/output/loading-button/index.test.d.ts.map +0 -1
  364. package/output/service/index.d.ts.map +0 -1
  365. package/output/service/service.d.ts +0 -286
  366. package/output/service/service.d.ts.map +0 -1
  367. package/output/service/service.js +0 -351
  368. package/output/service/service.test.d.ts.map +0 -1
  369. package/output/service/service.test.jsx +0 -367
  370. package/output/side-cache/index.d.ts +0 -2
  371. package/output/side-cache/index.d.ts.map +0 -1
  372. package/output/side-cache/index.js +0 -1
  373. package/output/side-cache/side-cache.d.ts.map +0 -1
  374. package/output/side-cache/side-cache.test.d.ts +0 -2
  375. package/output/side-cache/side-cache.test.d.ts.map +0 -1
  376. package/output/signin/context.d.ts.map +0 -1
  377. package/output/signin/index.d.ts.map +0 -1
  378. package/output/signin/service.d.ts.map +0 -1
  379. package/output/signin/service.test.d.ts.map +0 -1
  380. package/output/signin/types.d.ts.map +0 -1
  381. package/output/size-provider/index.d.ts +0 -2
  382. package/output/size-provider/index.d.ts.map +0 -1
  383. package/output/size-provider/index.js +0 -1
  384. package/output/size-provider/size-provider.d.ts.map +0 -1
  385. package/output/toaster/index.d.ts.map +0 -1
  386. package/output/use-observer/index.d.ts +0 -2
  387. package/output/use-observer/index.d.ts.map +0 -1
  388. package/output/use-observer/index.js +0 -1
  389. package/output/use-observer/use-observer.d.ts +0 -3
  390. package/output/use-observer/use-observer.d.ts.map +0 -1
  391. package/output/use-observer/use-observer.js +0 -16
  392. package/output/use-observer/use-observer.test.d.ts +0 -2
  393. package/output/use-observer/use-observer.test.d.ts.map +0 -1
  394. package/output/use-observer/use-observer.test.jsx +0 -134
  395. /package/output/{loading-button → components/loading-button}/index.test.d.ts +0 -0
  396. /package/output/{service → features/signin}/service.test.d.ts +0 -0
  397. /package/output/{signin → features/signin}/types.d.ts +0 -0
  398. /package/output/{signin → features/signin}/types.js +0 -0
  399. /package/output/{helpers → hooks}/use-observer/use-observer.d.ts +0 -0
  400. /package/output/{helpers → hooks}/use-observer/use-observer.test.d.ts +0 -0
  401. /package/output/{cache-api → services/cache-api}/cache-api.d.ts +0 -0
  402. /package/output/{cache-api → services/cache-api}/cache-api.test.d.ts +0 -0
  403. /package/output/{signin → services/service}/service.test.d.ts +0 -0
  404. /package/output/{side-cache → services/side-cache}/side-cache.d.ts +0 -0
  405. /package/output/{side-cache → services/side-cache}/side-cache.js +0 -0
  406. /package/output/{helpers → services}/side-cache/side-cache.test.d.ts +0 -0
@@ -1,286 +0,0 @@
1
- /**
2
- * React 服务层集成工具
3
- *
4
- * 本模块提供了在 React 应用中集成依赖注入(DI)和状态管理(Mobx)的工具函数和组件。
5
- * 主要功能包括:
6
- * - 通过 useService Hook 使用全局注册的服务,并自动响应状态变化
7
- * - 通过 useLocalService Hook 创建局部服务实例,避免全局状态污染
8
- * - 通过 ServiceProvider 组件提供服务容器上下文
9
- * - 自动初始化服务实例
10
- *
11
- * @example
12
- * ```tsx
13
- * // 1. 定义服务
14
- * class UserService extends Service {
15
- * @observable users: User[] = []
16
- * async init() { return true }
17
- * }
18
- *
19
- * // 2. 在根组件提供服务
20
- * function App() {
21
- * return (
22
- * <ServiceProvider services={[UserService]}>
23
- * <UserList />
24
- * </ServiceProvider>
25
- * )
26
- * }
27
- *
28
- * // 3. 在组件中使用服务
29
- * function UserList() {
30
- * const users = useService(UserService, s => s.users)
31
- * return <div>{users.map(user => <div key={user.id}>{user.name}</div>)}</div>
32
- * }
33
- * ```
34
- */
35
- import { Token, Container, Provider } from '@needle-di/core';
36
- import React from 'react';
37
- /**
38
- * 使用服务 Hook
39
- *
40
- * 该 Hook 从 DI 容器中获取指定的服务实例,支持可选的 selector 函数来选择需要的数据。
41
- * 当选择的数据发生变化时,组件会自动重新渲染。
42
- *
43
- * 该 Hook 可以获取三种类型的服务:
44
- * 1. 全局服务:通过 ServiceProvider 类注入的服务
45
- * 2. 值注入服务:通过 ServiceProvider 值注入({ provide, useValue })的服务实例
46
- * 3. 父级容器中的任何服务:支持多层嵌套的 ServiceProvider
47
- *
48
- * 特性:
49
- * - 从容器获取服务实例
50
- * - 支持 Mobx 响应式更新
51
- * - 支持可选 selector,不传时监听整个服务的所有变化
52
- * - 智能检测 selector 返回值,优化响应式监听策略
53
- *
54
- * @template T 服务类型
55
- * @template U 选择器返回的数据类型
56
- * @param target 服务的 Token,用于从容器中获取服务实例
57
- * @param selector 可选的选择器函数。如果不传入,返回服务实例并监听所有 observable 属性变化
58
- * @returns 如果传入了 selector,返回选择器的结果;否则返回服务实例
59
- *
60
- * @throws {Error} 当组件不在 ServiceProvider 内部时抛出错误
61
- *
62
- * @example
63
- * ```tsx
64
- * // 场景 1: 使用全局服务(类注入)
65
- * // App.tsx
66
- * <ServiceProvider services={[UserService]}>
67
- * <UserList />
68
- * </ServiceProvider>
69
- *
70
- * // UserList.tsx
71
- * const users = useService(UserService, service => service.users)
72
- * const userService = useService(UserService) // 监听整个服务的所有变化
73
- *
74
- * // 场景 2: 使用值注入的共享服务实例
75
- * // UserPage.tsx
76
- * function UserPage() {
77
- * const localService = useMemo(() => {
78
- * const service = new LocalUserService()
79
- * service.init()
80
- * return service
81
- * }, [])
82
- *
83
- * return (
84
- * <ServiceProvider services={[
85
- * { provide: LocalUserService, useValue: localService }
86
- * ]}>
87
- * <UserList />
88
- * <UserDetail />
89
- * </ServiceProvider>
90
- * )
91
- * }
92
- *
93
- * // UserList.tsx 和 UserDetail.tsx 共享同一个 localService 实例
94
- * function UserList() {
95
- * const users = useService(LocalUserService, s => s.users)
96
- * return <div>{users.length} users</div>
97
- * }
98
- *
99
- * function UserDetail() {
100
- * const service = useService(LocalUserService)
101
- * return <div>{service.currentUser?.name}</div>
102
- * }
103
- *
104
- * // 场景 3: 其他 selector 使用方式
105
- * const service = useService(UserService, s => s) // 智能检测,自动优化响应式监听
106
- * const currentUser = useService(UserService, service => service.currentUser)
107
- * const userCount = useService(UserService, service => service.users.length)
108
- * ```
109
- */
110
- export declare function useService<T>(target: Token<T>): T;
111
- export declare function useService<T, U>(target: Token<T>, selector: (service: T) => U): U;
112
- /**
113
- * 使用局部服务实例 Hook
114
- *
115
- * 该 Hook 创建指定服务的局部实例,既能注入全局依赖,又不会污染全局上下文。
116
- * 局部实例在 Hook 的整个生命周期内保持引用稳定,支持自动初始化和响应式更新。
117
- *
118
- * 特性:
119
- * - 创建局部服务实例,避免全局状态污染
120
- * - 继承全局容器的所有依赖,支持依赖注入
121
- * - 在组件重渲染时保持实例引用稳定
122
- * - 自动初始化实现了 Service 接口的服务
123
- * - 支持 Mobx 响应式更新
124
- * - 支持可选 selector,不传时监听整个服务的所有变化
125
- *
126
- * @template T 服务类型
127
- * @template U 选择器返回的数据类型
128
- * @param ServiceClass 服务构造函数/类
129
- * @param selector 可选的选择器函数。如果不传入,返回服务实例并监听所有 observable 属性变化
130
- * @returns 如果传入了 selector,返回选择器的结果;否则返回服务实例
131
- *
132
- * @throws {Error} 当组件不在 ServiceProvider 内部时抛出错误
133
- *
134
- * @example
135
- * ```tsx
136
- * // 使用选择器,只监听特定属性
137
- * const localUsers = useLocalService(LocalUserService, service => service.users)
138
- *
139
- * // 不使用选择器,监听整个服务的所有变化
140
- * const service = useLocalService(LocalUserService)
141
- *
142
- * // 局部服务可以注入全局服务
143
- * class LocalUserService extends Service {
144
- * constructor(
145
- * @inject(ApiService) private apiService: ApiService,
146
- * @inject(ConfigService) private configService: ConfigService
147
- * ) {
148
- * super()
149
- * }
150
- *
151
- * @observable users: User[] = []
152
- *
153
- * async init() {
154
- * this.users = await this.apiService.getUsers()
155
- * return true
156
- * }
157
- * }
158
- *
159
- * // 使用局部服务
160
- * function UserComponent() {
161
- * const users = useLocalService(LocalUserService, s => s.users)
162
- * const userCount = useLocalService(LocalUserService, s => s.users.length)
163
- *
164
- * return (
165
- * <div>
166
- * <p>用户数量: {userCount}</p>
167
- * {users.map(user => <div key={user.id}>{user.name}</div>)}
168
- * </div>
169
- * )
170
- * }
171
- *
172
- * // 不使用选择器的例子
173
- * function SimpleUserComponent() {
174
- * const service = useLocalService(LocalUserService)
175
- *
176
- * return (
177
- * <div>
178
- * <p>用户数量: {service.users.length}</p>
179
- * {service.users.map(user => <div key={user.id}>{user.name}</div>)}
180
- * </div>
181
- * )
182
- * }
183
- * ```
184
- */
185
- export declare function useLocalService<T>(ServiceClass: new (...args: any[]) => T): T;
186
- export declare function useLocalService<T, U>(ServiceClass: new (...args: any[]) => T, selector: (service: T) => U): U;
187
- /**
188
- * ServiceProvider 组件的属性接口
189
- */
190
- interface ServiceProviderProps {
191
- /**
192
- * 要注册到容器中的服务提供者数组
193
- * 支持两种注入方式:
194
- * 1. 类注入:直接传入服务类,ServiceProvider 会自动实例化并初始化
195
- * 2. 值注入:传入 { provide: Token, useValue: instance },直接注入已有实例
196
- */
197
- services: Provider<unknown>[];
198
- /** 子组件 */
199
- children: React.ReactNode;
200
- }
201
- /**
202
- * 服务提供者组件
203
- *
204
- * 该组件为其子组件树提供依赖注入容器上下文。
205
- * 它会自动复用父级容器(如果存在),并创建子容器来管理新的服务实例。
206
- *
207
- * 特性:
208
- * - 自动复用父级容器,避免重复创建
209
- * - 支持容器层级结构,子容器可以覆盖父容器的服务
210
- * - 支持两种注入方式:类注入和值注入
211
- * - 自动初始化实现了 Service 接口的服务(仅限类注入)
212
- *
213
- * @param props 组件属性
214
- *
215
- * @example
216
- * ```tsx
217
- * // 方式 1: 类注入 - 自动实例化和初始化
218
- * function App() {
219
- * return (
220
- * <ServiceProvider services={[UserService, ProductService]}>
221
- * <Router>
222
- * <Routes>
223
- * <Route path="/users" element={<UserPage />} />
224
- * <Route path="/products" element={<ProductPage />} />
225
- * </Routes>
226
- * </Router>
227
- * </ServiceProvider>
228
- * )
229
- * }
230
- *
231
- * // 方式 2: 值注入 - 在多个组件间共享局部服务实例
232
- * function UserPage() {
233
- * // 创建局部服务实例
234
- * const localUserService = useMemo(() => {
235
- * const service = new LocalUserService()
236
- * service.init() // 手动初始化
237
- * return service
238
- * }, [])
239
- *
240
- * return (
241
- * <ServiceProvider
242
- * services={[
243
- * { provide: LocalUserService, useValue: localUserService }
244
- * ]}
245
- * >
246
- * <UserList />
247
- * <UserDetail />
248
- * </ServiceProvider>
249
- * )
250
- * }
251
- *
252
- * // UserList 和 UserDetail 共享同一个 localUserService 实例
253
- * function UserList() {
254
- * const users = useService(LocalUserService, s => s.users)
255
- * return <div>{users.length} users</div>
256
- * }
257
- *
258
- * function UserDetail() {
259
- * const service = useService(LocalUserService)
260
- * return <div>{service.currentUser?.name}</div>
261
- * }
262
- *
263
- * // 方式 3: 混合使用类注入和值注入
264
- * function App() {
265
- * const configService = useMemo(() => {
266
- * const config = new ConfigService()
267
- * config.loadConfig() // 预配置
268
- * return config
269
- * }, [])
270
- *
271
- * return (
272
- * <ServiceProvider services={[
273
- * UserService, // 类注入 - 自动实例化和初始化
274
- * ApiService, // 类注入
275
- * { provide: ConfigService, useValue: configService } // 值注入 - 使用预配置的实例
276
- * ]}>
277
- * <Router />
278
- * </ServiceProvider>
279
- * )
280
- * }
281
- * ```
282
- */
283
- /** 自动复用 Container,除非没有,否则不会重新创建 Container */
284
- export declare function ServiceProvider(props: ServiceProviderProps): React.FunctionComponentElement<React.ProviderProps<Container | undefined>>;
285
- export {};
286
- //# sourceMappingURL=service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../source/service/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,KAA2D,MAAM,OAAO,CAAA;AA+D/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AAEH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAClD,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAgDlF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;AAC9E,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAyF9G;;GAEG;AACH,UAAU,oBAAoB;IAC5B;;;;;OAKG;IACH,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAA;IAC7B,UAAU;IACV,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AACH,6CAA6C;AAE7C,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,8EA2B1D"}
@@ -1,351 +0,0 @@
1
- /**
2
- * React 服务层集成工具
3
- *
4
- * 本模块提供了在 React 应用中集成依赖注入(DI)和状态管理(Mobx)的工具函数和组件。
5
- * 主要功能包括:
6
- * - 通过 useService Hook 使用全局注册的服务,并自动响应状态变化
7
- * - 通过 useLocalService Hook 创建局部服务实例,避免全局状态污染
8
- * - 通过 ServiceProvider 组件提供服务容器上下文
9
- * - 自动初始化服务实例
10
- *
11
- * @example
12
- * ```tsx
13
- * // 1. 定义服务
14
- * class UserService extends Service {
15
- * @observable users: User[] = []
16
- * async init() { return true }
17
- * }
18
- *
19
- * // 2. 在根组件提供服务
20
- * function App() {
21
- * return (
22
- * <ServiceProvider services={[UserService]}>
23
- * <UserList />
24
- * </ServiceProvider>
25
- * )
26
- * }
27
- *
28
- * // 3. 在组件中使用服务
29
- * function UserList() {
30
- * const users = useService(UserService, s => s.users)
31
- * return <div>{users.map(user => <div key={user.id}>{user.name}</div>)}</div>
32
- * }
33
- * ```
34
- */
35
- import { reaction, runInAction } from 'mobx';
36
- import { Container } from '@needle-di/core';
37
- import React, { useContext, useEffect, useMemo, useState, useRef } from 'react';
38
- /**
39
- * React Context 用于传递 DI 容器实例
40
- * 通过上下文在组件树中共享依赖注入容器
41
- */
42
- const ctx = React.createContext(undefined);
43
- const INIT_RETURN_ERROR_MESSAGE = 'Service init must return a boolean value.';
44
- class InvalidInitReturnError extends Error {
45
- constructor() {
46
- super(INIT_RETURN_ERROR_MESSAGE);
47
- this.name = 'InvalidInitReturnError';
48
- }
49
- }
50
- function setServiceInited(target, value) {
51
- runInAction(() => {
52
- if (target != null && typeof target === 'object') {
53
- target.inited = value;
54
- }
55
- });
56
- }
57
- function applyInitResult(target, result) {
58
- if (typeof result === 'boolean') {
59
- setServiceInited(target, result);
60
- return;
61
- }
62
- setServiceInited(target, false);
63
- throw new InvalidInitReturnError();
64
- }
65
- async function initializeServiceInstance(target) {
66
- if (target == null ||
67
- typeof target !== 'object' ||
68
- !('init' in target) ||
69
- typeof target.init !== 'function') {
70
- return;
71
- }
72
- const service = target;
73
- if (service.inited === true) {
74
- return;
75
- }
76
- try {
77
- const result = await service.init();
78
- applyInitResult(service, result);
79
- }
80
- catch (error) {
81
- if (error instanceof InvalidInitReturnError) {
82
- throw error;
83
- }
84
- setServiceInited(service, false);
85
- }
86
- }
87
- export function useService(target, selector) {
88
- const container = useContext(ctx);
89
- // 使用 useState 强制组件重新渲染
90
- const [, refresh] = useState({});
91
- React.useEffect(() => {
92
- if (container == null)
93
- return;
94
- // 从容器中获取服务实例
95
- const service = container.get(target);
96
- // 设置 Mobx reaction,当 selector 返回的数据变化时触发重新渲染
97
- const dispose = reaction(() => {
98
- // 如果没有提供 selector,使用默认策略监听整个服务的变化
99
- if (!selector) {
100
- // 直接访问服务实例,让 Mobx 自动收集依赖
101
- return service;
102
- }
103
- // 执行 selector 获取结果
104
- const result = selector(service);
105
- // 智能检测:如果 selector 返回的就是服务实例本身,
106
- // 则切换到监听所有属性变化的模式
107
- if (result === service) {
108
- // 通过访问服务实例让 Mobx 收集所有 observable 属性的依赖
109
- return service;
110
- }
111
- return result;
112
- }, () => refresh({}) // 触发组件重新渲染
113
- );
114
- return dispose;
115
- }, [container, selector, target]);
116
- if (container == null) {
117
- throw new Error('Must be a child of ServiceProvider.');
118
- }
119
- // 返回选择器结果或服务实例
120
- const service = container.get(target);
121
- return selector ? selector(service) : service;
122
- }
123
- export function useLocalService(ServiceClass, selector) {
124
- const parentContainer = useContext(ctx);
125
- // 使用 useRef 保持局部容器和服务实例的引用稳定
126
- const localContainerRef = useRef(null);
127
- const serviceInstanceRef = useRef(null);
128
- // 使用 useState 强制组件重新渲染,完全模仿 useService
129
- const [, refresh] = useState({});
130
- const [initError, setInitError] = useState(null);
131
- if (parentContainer == null) {
132
- throw new Error('Must be a child of ServiceProvider.');
133
- }
134
- // 确保服务实例已创建
135
- if (serviceInstanceRef.current == null) {
136
- // 创建继承父容器的子容器
137
- localContainerRef.current = new Container(parentContainer);
138
- // 将服务类绑定到局部容器
139
- localContainerRef.current.bindAll(ServiceClass);
140
- // 获取服务实例
141
- serviceInstanceRef.current = localContainerRef.current.get(ServiceClass);
142
- }
143
- // 模仿 useService 的结构:在 useEffect 中设置 reaction 和初始化
144
- React.useEffect(() => {
145
- if (parentContainer == null)
146
- return;
147
- const service = serviceInstanceRef.current;
148
- // 设置 Mobx reaction,当 selector 返回的数据变化时触发重新渲染
149
- const dispose = reaction(() => {
150
- // 如果没有提供 selector,使用默认策略监听整个服务的变化
151
- if (!selector) {
152
- // 直接访问服务实例,让 Mobx 自动收集依赖
153
- return service;
154
- }
155
- // 执行 selector 获取结果
156
- const result = selector(service);
157
- // 智能检测:如果 selector 返回的就是服务实例本身,
158
- // 则切换到监听所有属性变化的模式
159
- if (result === service) {
160
- // 通过访问服务实例让 Mobx 收集所有 observable 属性的依赖
161
- return service;
162
- }
163
- return result;
164
- }, () => refresh({}) // 触发组件重新渲染
165
- );
166
- return dispose;
167
- }, [parentContainer, selector, ServiceClass]);
168
- // 单独的 useEffect 处理服务初始化,避免与 selector 变化的冲突
169
- React.useEffect(() => {
170
- if (parentContainer == null)
171
- return;
172
- let disposed = false;
173
- setInitError(prev => (prev === null ? prev : null));
174
- const service = serviceInstanceRef.current;
175
- initializeServiceInstance(service).catch((error) => {
176
- if (error instanceof InvalidInitReturnError && !disposed) {
177
- setInitError(error);
178
- }
179
- });
180
- return () => {
181
- disposed = true;
182
- };
183
- }, [parentContainer, ServiceClass]); // 注意:这里不依赖 selector
184
- if (initError) {
185
- throw initError;
186
- }
187
- // 返回选择器结果或服务实例
188
- return selector ? selector(serviceInstanceRef.current) : serviceInstanceRef.current;
189
- }
190
- /**
191
- * 服务提供者组件
192
- *
193
- * 该组件为其子组件树提供依赖注入容器上下文。
194
- * 它会自动复用父级容器(如果存在),并创建子容器来管理新的服务实例。
195
- *
196
- * 特性:
197
- * - 自动复用父级容器,避免重复创建
198
- * - 支持容器层级结构,子容器可以覆盖父容器的服务
199
- * - 支持两种注入方式:类注入和值注入
200
- * - 自动初始化实现了 Service 接口的服务(仅限类注入)
201
- *
202
- * @param props 组件属性
203
- *
204
- * @example
205
- * ```tsx
206
- * // 方式 1: 类注入 - 自动实例化和初始化
207
- * function App() {
208
- * return (
209
- * <ServiceProvider services={[UserService, ProductService]}>
210
- * <Router>
211
- * <Routes>
212
- * <Route path="/users" element={<UserPage />} />
213
- * <Route path="/products" element={<ProductPage />} />
214
- * </Routes>
215
- * </Router>
216
- * </ServiceProvider>
217
- * )
218
- * }
219
- *
220
- * // 方式 2: 值注入 - 在多个组件间共享局部服务实例
221
- * function UserPage() {
222
- * // 创建局部服务实例
223
- * const localUserService = useMemo(() => {
224
- * const service = new LocalUserService()
225
- * service.init() // 手动初始化
226
- * return service
227
- * }, [])
228
- *
229
- * return (
230
- * <ServiceProvider
231
- * services={[
232
- * { provide: LocalUserService, useValue: localUserService }
233
- * ]}
234
- * >
235
- * <UserList />
236
- * <UserDetail />
237
- * </ServiceProvider>
238
- * )
239
- * }
240
- *
241
- * // UserList 和 UserDetail 共享同一个 localUserService 实例
242
- * function UserList() {
243
- * const users = useService(LocalUserService, s => s.users)
244
- * return <div>{users.length} users</div>
245
- * }
246
- *
247
- * function UserDetail() {
248
- * const service = useService(LocalUserService)
249
- * return <div>{service.currentUser?.name}</div>
250
- * }
251
- *
252
- * // 方式 3: 混合使用类注入和值注入
253
- * function App() {
254
- * const configService = useMemo(() => {
255
- * const config = new ConfigService()
256
- * config.loadConfig() // 预配置
257
- * return config
258
- * }, [])
259
- *
260
- * return (
261
- * <ServiceProvider services={[
262
- * UserService, // 类注入 - 自动实例化和初始化
263
- * ApiService, // 类注入
264
- * { provide: ConfigService, useValue: configService } // 值注入 - 使用预配置的实例
265
- * ]}>
266
- * <Router />
267
- * </ServiceProvider>
268
- * )
269
- * }
270
- * ```
271
- */
272
- /** 自动复用 Container,除非没有,否则不会重新创建 Container */
273
- // di 实现也有限制 https://needle-di.io/advanced/child-containers.html
274
- export function ServiceProvider(props) {
275
- const parentContainer = useContext(ctx);
276
- const { children, services } = props;
277
- // 创建子容器,复用父容器的服务配置
278
- const container = useMemo(() => {
279
- const currentContainer = new Container(parentContainer);
280
- // 直接绑定所有服务(包括类注入和值注入)
281
- // needle-di 的 bind 方法可以处理所有类型的 Provider
282
- services.forEach(service => {
283
- currentContainer.bind(service);
284
- });
285
- return currentContainer;
286
- }, [parentContainer, services]);
287
- // 使用 React.createElement 避免将文件改为 .tsx
288
- const init = React.createElement(InitService, { services, children });
289
- return React.createElement(ctx.Provider, { value: container, children: container ? init : null });
290
- }
291
- /**
292
- * 服务初始化组件
293
- *
294
- * 该组件负责自动初始化实现了 Service 接口的服务实例。
295
- * 它会在组件挂载时检查每个服务是否需要初始化,并调用其 init 方法。
296
- *
297
- * 初始化流程:
298
- * 1. 跳过值注入的服务(它们应该在传入前已经初始化)
299
- * 2. 从容器中获取服务实例(仅类注入的服务)
300
- * 3. 检查服务是否实现了 Service 接口(有 init 方法)
301
- * 4. 检查服务是否已经初始化(inited 属性)
302
- * 5. 如果未初始化,则调用 init 方法并更新状态
303
- *
304
- * 注意:
305
- * - 值注入的服务需要在传入前手动初始化
306
- * - 只有类注入的服务会自动调用 init 方法
307
- *
308
- * @param props 组件属性,与 ServiceProviderProps 相同
309
- */
310
- function InitService(props) {
311
- const { services, children } = props;
312
- const container = useContext(ctx);
313
- const [initError, setInitError] = React.useState(null);
314
- useEffect(() => {
315
- if (container == null)
316
- return;
317
- if (services.length == 0)
318
- return;
319
- let disposed = false;
320
- setInitError(prev => (prev === null ? prev : null));
321
- // 异步初始化所有服务
322
- const initPromises = services.map(async (service) => {
323
- // 跳过值注入的服务(它们应该在传入前已经初始化)
324
- if (service != null && typeof service === 'object' && 'provide' in service && 'useValue' in service) {
325
- return;
326
- }
327
- // 尝试从容器中获取服务实例(可选的,避免未注册时报错)
328
- const instance = container.get(service, { optional: true });
329
- if (instance != null && typeof instance === 'object') {
330
- // 检查实例是否实现了 Service 接口
331
- if ('init' in instance && typeof instance.init === 'function') {
332
- if (instance.inited !== true) {
333
- await initializeServiceInstance(instance).catch((error) => {
334
- if (error instanceof InvalidInitReturnError && !disposed) {
335
- setInitError(error);
336
- }
337
- });
338
- }
339
- }
340
- }
341
- });
342
- void Promise.all(initPromises);
343
- return () => {
344
- disposed = true;
345
- };
346
- }, [container, services]);
347
- if (initError) {
348
- throw initError;
349
- }
350
- return children;
351
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.test.d.ts","sourceRoot":"","sources":["../../source/service/service.test.tsx"],"names":[],"mappings":""}