@_tc/template-core 0.0.1-bate.35 → 0.0.1-bate.37

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 (418) hide show
  1. package/cjs/app/controller/base.js +3 -3
  2. package/cjs/app/controller/project.js +1 -1
  3. package/cjs/app/controller/view.js +16 -7
  4. package/cjs/app/middleware/api-params-verify.js +10 -1
  5. package/cjs/app/middleware/error-handle.js +9 -3
  6. package/cjs/app/middleware/project-handler.js +1 -1
  7. package/cjs/app/router/view.js +3 -1
  8. package/cjs/app/router-schema/project.js +1 -1
  9. package/cjs/app/service/project.js +5 -0
  10. package/cjs/bundler/defaultAlias.js +5 -0
  11. package/cjs/bundler/dev.js +4 -3
  12. package/cjs/bundler/index.js +2 -1
  13. package/cjs/bundler/prod.js +4 -3
  14. package/cjs/bundler/utils.js +53 -24
  15. package/cjs/packages/common/LRUCache.js +4 -0
  16. package/cjs/packages/common/array/index.js +43 -0
  17. package/cjs/packages/common/cache/LRUCache.js +45 -0
  18. package/cjs/packages/common/cache/index.js +4 -0
  19. package/cjs/packages/common/guards/index.js +34 -0
  20. package/cjs/packages/common/i18n/default.js +95 -0
  21. package/cjs/packages/common/i18n/en-US.js +95 -0
  22. package/cjs/packages/common/i18n/index.js +178 -0
  23. package/cjs/packages/common/i18n/locales.js +17 -0
  24. package/cjs/packages/common/i18n/types.js +1 -0
  25. package/cjs/packages/common/index.js +65 -0
  26. package/cjs/packages/common/log/index.js +160 -0
  27. package/cjs/packages/common/number/index.js +14 -0
  28. package/cjs/packages/common/object/filterEmpty.js +32 -0
  29. package/cjs/packages/common/object/filtereEmpty.js +5 -0
  30. package/cjs/packages/common/object/index.js +26 -0
  31. package/cjs/packages/common/string/index.js +17 -0
  32. package/cjs/packages/common/types/index.js +1 -0
  33. package/cjs/packages/core/index.js +17 -12
  34. package/cjs/packages/core/loader/model.js +3 -3
  35. package/cjs/packages/core/loader/router.js +14 -5
  36. package/esm/app/controller/base.js +3 -3
  37. package/esm/app/controller/project.js +3 -3
  38. package/esm/app/controller/view.js +16 -7
  39. package/esm/app/middleware/api-params-verify.js +10 -1
  40. package/esm/app/middleware/error-handle.js +9 -3
  41. package/esm/app/middleware/project-handler.js +1 -1
  42. package/esm/app/router/view.js +3 -1
  43. package/esm/app/router-schema/project.js +1 -1
  44. package/esm/app/service/project.js +5 -0
  45. package/esm/bundler/defaultAlias.js +4 -0
  46. package/esm/bundler/dev.js +4 -3
  47. package/esm/bundler/index.js +2 -1
  48. package/esm/bundler/prod.js +4 -3
  49. package/esm/bundler/utils.js +53 -24
  50. package/esm/index.js +2 -2
  51. package/esm/packages/common/LRUCache.js +2 -0
  52. package/esm/packages/common/array/index.js +37 -0
  53. package/esm/packages/common/cache/LRUCache.js +43 -0
  54. package/esm/packages/common/cache/index.js +2 -0
  55. package/esm/packages/common/guards/index.js +26 -0
  56. package/esm/packages/common/i18n/default.js +93 -0
  57. package/esm/packages/common/i18n/en-US.js +93 -0
  58. package/esm/packages/common/i18n/index.js +162 -0
  59. package/esm/packages/common/i18n/locales.js +11 -0
  60. package/esm/packages/common/i18n/types.js +0 -0
  61. package/esm/packages/common/index.js +13 -0
  62. package/esm/packages/common/log/index.js +146 -0
  63. package/esm/packages/common/number/index.js +11 -0
  64. package/esm/packages/common/object/filterEmpty.js +29 -0
  65. package/esm/packages/common/object/filtereEmpty.js +2 -0
  66. package/esm/packages/common/object/index.js +20 -0
  67. package/esm/packages/common/string/index.js +13 -0
  68. package/esm/packages/common/types/index.js +0 -0
  69. package/esm/packages/core/index.js +17 -12
  70. package/esm/packages/core/loader/model.js +3 -3
  71. package/esm/packages/core/loader/router.js +14 -5
  72. package/fe/frontend/dash/Dashboard.d.ts +7 -0
  73. package/fe/frontend/dash/Dashboard.js +63 -0
  74. package/fe/frontend/dash/dash.entry.d.ts +2 -0
  75. package/fe/frontend/dash/dash.entry.js +62 -0
  76. package/fe/frontend/index.d.ts +3 -0
  77. package/fe/frontend/index.js +1 -0
  78. package/fe/frontend/main.css +5 -1
  79. package/fe/frontend/main.d.ts +10 -3
  80. package/fe/frontend/main.js +13 -4
  81. package/fe/frontend/testPage/testPage.entry.js +1 -2
  82. package/fe/frontend/typing/window.d.ts +7 -0
  83. package/fe/frontend/typing/window.js +1 -0
  84. package/fe/frontend/widgets/api/baseInfo.d.ts +31 -0
  85. package/fe/frontend/widgets/api/baseInfo.js +15 -0
  86. package/fe/frontend/widgets/common/CRUD/CRUD.d.ts +70 -0
  87. package/fe/frontend/widgets/common/CRUD/CRUD.js +207 -0
  88. package/fe/frontend/widgets/common/CRUD/index.d.ts +2 -0
  89. package/fe/frontend/widgets/common/CRUD/index.js +1 -0
  90. package/fe/frontend/widgets/common/auth/index.d.ts +7 -0
  91. package/fe/frontend/widgets/common/auth/index.js +20 -0
  92. package/fe/frontend/widgets/common/generateMenuData.d.ts +4 -0
  93. package/fe/frontend/widgets/common/generateMenuData.js +14 -0
  94. package/fe/frontend/widgets/common/importComponent.d.ts +5 -0
  95. package/fe/frontend/widgets/common/importComponent.js +7 -0
  96. package/fe/frontend/widgets/common/language.d.ts +2 -0
  97. package/fe/frontend/widgets/common/language.js +8 -0
  98. package/fe/frontend/widgets/common/logFn/index.d.ts +4 -0
  99. package/fe/frontend/widgets/common/logFn/index.js +8 -0
  100. package/fe/frontend/widgets/common/menu.d.ts +22 -0
  101. package/fe/frontend/widgets/common/menu.js +80 -0
  102. package/fe/frontend/widgets/common/request.d.ts +33 -0
  103. package/fe/frontend/widgets/common/request.js +127 -0
  104. package/fe/frontend/widgets/components/BasePage/HeaderView.d.ts +9 -0
  105. package/fe/frontend/widgets/components/BasePage/HeaderView.js +14 -0
  106. package/fe/frontend/widgets/components/Router/index.d.ts +9 -0
  107. package/fe/frontend/widgets/components/Router/index.js +11 -0
  108. package/fe/frontend/widgets/components/Router/type.d.ts +2 -0
  109. package/fe/frontend/widgets/components/Router/type.js +1 -0
  110. package/fe/frontend/widgets/defaultPages/Iframe/index.d.ts +3 -0
  111. package/fe/frontend/widgets/defaultPages/Iframe/index.js +14 -0
  112. package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/DetailPanel.d.ts +7 -0
  113. package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/DetailPanel.js +94 -0
  114. package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/PopFrom.d.ts +13 -0
  115. package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/PopFrom.js +109 -0
  116. package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/data.d.ts +3 -0
  117. package/fe/frontend/widgets/defaultPages/Schema/components/CallCom/data.js +6 -0
  118. package/fe/frontend/widgets/defaultPages/Schema/components/SchemaSearch/index.d.ts +3 -0
  119. package/fe/frontend/widgets/defaultPages/Schema/components/SchemaSearch/index.js +58 -0
  120. package/fe/frontend/widgets/defaultPages/Schema/components/SchemaTable/index.d.ts +11 -0
  121. package/fe/frontend/widgets/defaultPages/Schema/components/SchemaTable/index.js +176 -0
  122. package/fe/frontend/widgets/defaultPages/Schema/data/eventInfo.d.ts +8 -0
  123. package/fe/frontend/widgets/defaultPages/Schema/data/eventInfo.js +6 -0
  124. package/fe/frontend/widgets/defaultPages/Schema/data/index.d.ts +3 -0
  125. package/fe/frontend/widgets/defaultPages/Schema/data/index.js +1 -0
  126. package/fe/frontend/widgets/defaultPages/Schema/hooks/useComConfig.d.ts +10 -0
  127. package/fe/frontend/widgets/defaultPages/Schema/hooks/useComConfig.js +14 -0
  128. package/fe/frontend/widgets/defaultPages/Schema/index.d.ts +3 -0
  129. package/fe/frontend/widgets/defaultPages/Schema/index.js +67 -0
  130. package/fe/frontend/widgets/defaultPages/Schema/schemaType.d.ts +41 -0
  131. package/fe/frontend/widgets/defaultPages/Schema/schemaType.js +4 -0
  132. package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.d.ts +23 -0
  133. package/fe/frontend/widgets/defaultPages/Schema/stores/schemaEventBus.js +66 -0
  134. package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.d.ts +33 -0
  135. package/fe/frontend/widgets/defaultPages/Schema/stores/schemaStore.js +24 -0
  136. package/fe/frontend/widgets/defaultPages/Schema/utils/fetchErrorShow.d.ts +3 -0
  137. package/fe/frontend/widgets/defaultPages/Schema/utils/fetchErrorShow.js +8 -0
  138. package/fe/frontend/widgets/defaultPages/Schema/utils/permissions.d.ts +3 -0
  139. package/fe/frontend/widgets/defaultPages/Schema/utils/permissions.js +3 -0
  140. package/fe/frontend/widgets/defaultPages/Schema/utils/schemaConversion.d.ts +3 -0
  141. package/fe/frontend/widgets/defaultPages/Schema/utils/schemaConversion.js +72 -0
  142. package/fe/frontend/widgets/defaultPages/Schema/utils/validator.d.ts +4 -0
  143. package/fe/frontend/widgets/defaultPages/Schema/utils/validator.js +31 -0
  144. package/fe/frontend/widgets/defaultPages/SidebarSlotPage/SidebarSlotContainer.d.ts +10 -0
  145. package/fe/frontend/widgets/defaultPages/SidebarSlotPage/SidebarSlotContainer.js +31 -0
  146. package/fe/frontend/widgets/defaultPages/SidebarSlotPage/index.d.ts +3 -0
  147. package/fe/frontend/widgets/defaultPages/SidebarSlotPage/index.js +15 -0
  148. package/fe/frontend/widgets/defaultPages/SidebarSlotPageTmp.d.ts +3 -0
  149. package/fe/frontend/widgets/defaultPages/SidebarSlotPageTmp.js +17 -0
  150. package/fe/frontend/widgets/defaultPages/SlotPage/index.d.ts +3 -0
  151. package/fe/frontend/widgets/defaultPages/SlotPage/index.js +24 -0
  152. package/fe/frontend/widgets/defaultPages/Todo.d.ts +3 -0
  153. package/fe/frontend/widgets/defaultPages/Todo.js +5 -0
  154. package/fe/frontend/widgets/hooks/useCurrentMenuData.d.ts +11 -0
  155. package/fe/frontend/widgets/hooks/useCurrentMenuData.js +20 -0
  156. package/fe/frontend/widgets/hooks/useRouterParams.d.ts +5 -0
  157. package/fe/frontend/widgets/hooks/useRouterParams.js +11 -0
  158. package/fe/frontend/widgets/store/mode.d.ts +16 -0
  159. package/fe/frontend/widgets/store/mode.js +36 -0
  160. package/fe/model/types/data/button.d.ts +23 -0
  161. package/fe/model/types/data/button.js +1 -0
  162. package/fe/model/types/data/component.d.ts +37 -0
  163. package/fe/model/types/data/component.js +1 -0
  164. package/fe/model/types/data/fetchInfo.d.ts +8 -0
  165. package/fe/model/types/data/fetchInfo.js +1 -0
  166. package/fe/model/types/data/schema.d.ts +47 -0
  167. package/fe/model/types/data/schema.js +1 -0
  168. package/fe/model/types/data/search.d.ts +7 -0
  169. package/fe/model/types/data/search.js +1 -0
  170. package/fe/model/types/menuType.d.ts +44 -0
  171. package/fe/model/types/menuType.js +1 -0
  172. package/fe/model/types/model.d.ts +20 -0
  173. package/fe/model/types/model.js +1 -0
  174. package/fe/packages/common/array/index.d.ts +7 -0
  175. package/fe/packages/common/array/index.js +40 -0
  176. package/fe/packages/common/cache/LRUCache.d.ts +13 -0
  177. package/fe/packages/common/cache/LRUCache.js +47 -0
  178. package/fe/packages/common/cache/index.d.ts +2 -0
  179. package/fe/packages/common/cache/index.js +1 -0
  180. package/fe/packages/common/guards/index.d.ts +9 -0
  181. package/fe/packages/common/guards/index.js +24 -0
  182. package/fe/packages/common/i18n/default.d.ts +87 -0
  183. package/fe/packages/common/i18n/default.js +85 -0
  184. package/fe/packages/common/i18n/en-US.d.ts +87 -0
  185. package/fe/packages/common/i18n/en-US.js +85 -0
  186. package/fe/packages/common/i18n/index.d.ts +19 -0
  187. package/fe/packages/common/i18n/index.js +142 -0
  188. package/fe/packages/common/i18n/locales.d.ts +8 -0
  189. package/fe/packages/common/i18n/locales.js +10 -0
  190. package/fe/packages/common/i18n/types.d.ts +47 -0
  191. package/fe/packages/common/i18n/types.js +1 -0
  192. package/fe/packages/common/index.d.ts +10 -0
  193. package/fe/packages/common/index.js +9 -0
  194. package/fe/packages/common/log/index.d.ts +33 -0
  195. package/fe/packages/common/log/index.js +176 -0
  196. package/fe/packages/common/number/index.d.ts +3 -0
  197. package/fe/packages/common/number/index.js +10 -0
  198. package/fe/packages/common/object/filterEmpty.d.ts +3 -0
  199. package/fe/packages/common/object/filterEmpty.js +33 -0
  200. package/fe/packages/common/object/index.d.ts +5 -0
  201. package/fe/packages/common/object/index.js +25 -0
  202. package/fe/packages/common/string/index.d.ts +4 -0
  203. package/fe/packages/common/string/index.js +17 -0
  204. package/fe/packages/common/types/index.d.ts +4 -0
  205. package/fe/packages/common/types/index.js +1 -0
  206. package/fe/packages/ui/react/components/Button/Button.d.ts +16 -30
  207. package/fe/packages/ui/react/components/Button/Button.js +53 -26
  208. package/fe/packages/ui/react/components/Button/SumbitButton.d.ts +2 -6
  209. package/fe/packages/ui/react/components/Button/SumbitButton.js +3 -14
  210. package/fe/packages/ui/react/components/Button/index.d.ts +1 -1
  211. package/fe/packages/ui/react/components/Checkbox/Checkbox.d.ts +1 -1
  212. package/fe/packages/ui/react/components/Checkbox/Checkbox.js +5 -3
  213. package/fe/packages/ui/react/components/{ConfirmDialog.d.ts → ConfirmDialog/ConfirmDialog.d.ts} +0 -8
  214. package/fe/packages/ui/react/components/ConfirmDialog/ConfirmDialog.js +11 -0
  215. package/fe/packages/ui/react/components/ConfirmDialog/index.d.ts +2 -0
  216. package/fe/packages/ui/react/components/ConfirmDialog/index.js +1 -0
  217. package/fe/packages/ui/react/components/DataTable/ActionBtn.d.ts +3 -1
  218. package/fe/packages/ui/react/components/DataTable/ActionBtn.js +85 -4
  219. package/fe/packages/ui/react/components/DataTable/{data-table.d.ts → index.d.ts} +10 -23
  220. package/fe/packages/ui/react/components/DataTable/{data-table.js → index.js} +57 -47
  221. package/fe/packages/ui/react/components/Date/Calendar.d.ts +0 -13
  222. package/fe/packages/ui/react/components/Date/Calendar.js +5 -13
  223. package/fe/packages/ui/react/components/Date/Date.d.ts +4 -13
  224. package/fe/packages/ui/react/components/Date/Date.js +70 -66
  225. package/fe/packages/ui/react/components/Date/LocaleContext.d.ts +0 -4
  226. package/fe/packages/ui/react/components/Date/LocaleContext.js +0 -4
  227. package/fe/packages/ui/react/components/Date/LocaleProvider.d.ts +0 -11
  228. package/fe/packages/ui/react/components/Date/LocaleProvider.js +0 -11
  229. package/fe/packages/ui/react/components/Date/TimePicker.js +3 -2
  230. package/fe/packages/ui/react/components/Date/dateLocaleStore.d.ts +0 -6
  231. package/fe/packages/ui/react/components/Date/dropdownPositioning.d.ts +3 -0
  232. package/fe/packages/ui/react/components/Date/dropdownPositioning.js +12 -0
  233. package/fe/packages/ui/react/components/Date/locales.d.ts +1 -19
  234. package/fe/packages/ui/react/components/Date/locales.js +7 -47
  235. package/fe/packages/ui/react/components/Drawer/Drawer.d.ts +23 -0
  236. package/fe/packages/ui/react/components/Drawer/Drawer.js +100 -0
  237. package/fe/packages/ui/react/components/Drawer/index.d.ts +3 -0
  238. package/fe/packages/ui/react/components/Drawer/index.js +1 -0
  239. package/fe/packages/ui/react/components/Dropdown/Dropdown.d.ts +24 -0
  240. package/fe/packages/ui/react/components/Dropdown/Dropdown.js +28 -0
  241. package/fe/packages/ui/react/components/Dropdown/index.d.ts +2 -0
  242. package/fe/packages/ui/react/components/Dropdown/index.js +1 -0
  243. package/fe/packages/ui/react/components/Form/Form.d.ts +0 -6
  244. package/fe/packages/ui/react/components/Form/Form.js +1 -1
  245. package/fe/packages/ui/react/components/Form/FormItem.d.ts +0 -21
  246. package/fe/packages/ui/react/components/Form/FormItem.js +2 -9
  247. package/fe/packages/ui/react/components/Form/SchemaForm/data.d.ts +45 -0
  248. package/fe/packages/ui/react/components/Form/{SchemeForm → SchemaForm}/data.js +8 -1
  249. package/fe/packages/ui/react/components/Form/SchemaForm/index.d.ts +60 -0
  250. package/fe/packages/ui/react/components/Form/SchemaForm/index.js +75 -0
  251. package/fe/packages/ui/react/components/Form/index.d.ts +1 -1
  252. package/fe/packages/ui/react/components/Form/index.js +1 -1
  253. package/fe/packages/ui/react/components/ImagePreview/ImagePreview.js +15 -20
  254. package/fe/packages/ui/react/components/ImagePreview/PreviewImage.d.ts +0 -3
  255. package/fe/packages/ui/react/components/ImagePreview/PreviewImage.js +5 -2
  256. package/fe/packages/ui/react/components/Input/Input.d.ts +3 -21
  257. package/fe/packages/ui/react/components/Input/Input.js +5 -7
  258. package/fe/packages/ui/react/components/InputNumber/InputNumber.d.ts +26 -0
  259. package/fe/packages/ui/react/components/InputNumber/InputNumber.js +144 -0
  260. package/fe/packages/ui/react/components/InputNumber/index.d.ts +2 -0
  261. package/fe/packages/ui/react/components/InputNumber/index.js +1 -0
  262. package/fe/packages/ui/react/components/InputNumber/inputNumberUtils.d.ts +30 -0
  263. package/fe/packages/ui/react/components/InputNumber/inputNumberUtils.js +63 -0
  264. package/fe/packages/ui/react/components/InputNumber/inputNumberUtils.test.d.ts +2 -0
  265. package/fe/packages/ui/react/components/InputNumber/inputNumberUtils.test.js +27 -0
  266. package/fe/packages/ui/react/components/Label/Label.d.ts +0 -29
  267. package/fe/packages/ui/react/components/Label/Label.js +2 -4
  268. package/fe/packages/ui/react/components/Menu/Menu.d.ts +18 -0
  269. package/fe/packages/ui/react/components/Menu/Menu.js +98 -0
  270. package/fe/packages/ui/react/components/Menu/MenuContext.d.ts +39 -0
  271. package/fe/packages/ui/react/components/Menu/MenuContext.js +97 -0
  272. package/fe/packages/ui/react/components/Menu/MenuItem.d.ts +3 -0
  273. package/fe/packages/ui/react/components/Menu/MenuItem.js +33 -0
  274. package/fe/packages/ui/react/components/Menu/SubMenu.d.ts +3 -0
  275. package/fe/packages/ui/react/components/Menu/SubMenu.js +124 -0
  276. package/fe/packages/ui/react/components/Menu/index.d.ts +9 -0
  277. package/fe/packages/ui/react/components/Menu/index.js +5 -0
  278. package/fe/packages/ui/react/components/Menu/menuTypes.d.ts +58 -0
  279. package/fe/packages/ui/react/components/Menu/menuTypes.js +1 -0
  280. package/fe/packages/ui/react/components/Menu/utils.d.ts +2 -0
  281. package/fe/packages/ui/react/components/Menu/utils.js +7 -0
  282. package/fe/packages/ui/react/components/Message/Message.d.ts +0 -7
  283. package/fe/packages/ui/react/components/Message/Message.js +4 -4
  284. package/fe/packages/ui/react/components/Message/MessageManager.js +0 -8
  285. package/fe/packages/ui/react/components/Modal/Modal.d.ts +3 -7
  286. package/fe/packages/ui/react/components/Modal/Modal.js +6 -44
  287. package/fe/packages/ui/react/components/Modal/ModalManager.d.ts +0 -12
  288. package/fe/packages/ui/react/components/Modal/ModalManager.js +5 -7
  289. package/fe/packages/ui/react/components/Overlay/Overlay.d.ts +20 -0
  290. package/fe/packages/ui/react/components/Overlay/Overlay.js +53 -0
  291. package/fe/packages/ui/react/components/Overlay/index.d.ts +3 -0
  292. package/fe/packages/ui/react/components/Overlay/index.js +1 -0
  293. package/fe/packages/ui/react/components/{Pagination.d.ts → Pagination/Pagination.d.ts} +0 -7
  294. package/fe/packages/ui/react/components/{Pagination.js → Pagination/Pagination.js} +5 -12
  295. package/fe/packages/ui/react/components/Pagination/index.d.ts +2 -0
  296. package/fe/packages/ui/react/components/Pagination/index.js +1 -0
  297. package/fe/packages/ui/react/components/Popup/Popup.d.ts +26 -0
  298. package/fe/packages/ui/react/components/Popup/Popup.js +69 -0
  299. package/fe/packages/ui/react/components/Popup/index.d.ts +2 -0
  300. package/fe/packages/ui/react/components/Popup/index.js +1 -0
  301. package/fe/packages/ui/react/components/Search/Search.d.ts +2 -5
  302. package/fe/packages/ui/react/components/Search/Search.js +3 -3
  303. package/fe/packages/ui/react/components/Select/Select.d.ts +2 -2
  304. package/fe/packages/ui/react/components/Select/Select.js +52 -113
  305. package/fe/packages/ui/react/components/Select/dropdownPositioning.d.ts +3 -0
  306. package/fe/packages/ui/react/components/Select/dropdownPositioning.js +13 -0
  307. package/fe/packages/ui/react/components/Skeleton/Skeleton.d.ts +0 -15
  308. package/fe/packages/ui/react/components/Skeleton/Skeleton.js +3 -3
  309. package/fe/packages/ui/react/components/Switch/Switch.js +3 -1
  310. package/fe/packages/ui/react/components/TableSearch/TableSearch.d.ts +5 -41
  311. package/fe/packages/ui/react/components/TableSearch/TableSearch.js +21 -22
  312. package/fe/packages/ui/react/components/TableSearch/lang.js +5 -14
  313. package/fe/packages/ui/react/components/Textarea/Textarea.d.ts +21 -0
  314. package/fe/packages/ui/react/components/Textarea/Textarea.js +36 -0
  315. package/fe/packages/ui/react/components/Textarea/index.d.ts +2 -0
  316. package/fe/packages/ui/react/components/Textarea/index.js +1 -0
  317. package/fe/packages/ui/react/components/Tooltip/Tooltip.d.ts +9 -0
  318. package/fe/packages/ui/react/components/Tooltip/Tooltip.js +71 -0
  319. package/fe/packages/ui/react/components/Tooltip/index.d.ts +2 -0
  320. package/fe/packages/ui/react/components/Tooltip/index.js +1 -0
  321. package/fe/packages/ui/react/components/{TreeSelect.d.ts → TreeSelect/TreeSelect.d.ts} +0 -6
  322. package/fe/packages/ui/react/components/{TreeSelect.js → TreeSelect/TreeSelect.js} +9 -17
  323. package/fe/packages/ui/react/components/TreeSelect/index.d.ts +2 -0
  324. package/fe/packages/ui/react/components/TreeSelect/index.js +1 -0
  325. package/fe/packages/ui/react/components/Upload/ImageUpload.js +18 -6
  326. package/fe/packages/ui/react/components/Upload/Upload.d.ts +0 -27
  327. package/fe/packages/ui/react/components/Upload/Upload.js +2 -1
  328. package/fe/packages/ui/react/components/{breadcrumb.js → breadcrumb/breadcrumb.js} +15 -21
  329. package/fe/packages/ui/react/components/breadcrumb/index.d.ts +2 -0
  330. package/fe/packages/ui/react/components/breadcrumb/index.js +1 -0
  331. package/fe/packages/ui/react/components/hooks/useDropdownPositioning.d.ts +43 -0
  332. package/fe/packages/ui/react/components/hooks/useDropdownPositioning.js +123 -0
  333. package/fe/packages/ui/react/components/hooks/useInputController.d.ts +0 -3
  334. package/fe/packages/ui/react/components/hooks/useInputController.js +0 -7
  335. package/fe/packages/ui/react/components/index.d.ts +7 -1
  336. package/fe/packages/ui/react/components/index.js +7 -1
  337. package/fe/packages/ui/react/components/table/index.d.ts +2 -0
  338. package/fe/packages/ui/react/components/table/index.js +1 -0
  339. package/fe/packages/ui/react/components/table/table.js +20 -0
  340. package/fe/packages/ui/react/components/testPage/MenuTestPage.d.ts +2 -0
  341. package/fe/packages/ui/react/components/testPage/MenuTestPage.js +101 -0
  342. package/fe/packages/ui/react/components/testPage/index.js +251 -81
  343. package/fe/packages/ui/react/hooks/useExecuteOnce.d.ts +12 -0
  344. package/fe/packages/ui/react/hooks/useExecuteOnce.js +36 -0
  345. package/fe/packages/ui/react/hooks/useInit.d.ts +1 -1
  346. package/fe/packages/ui/react/hooks/useInit.js +1 -1
  347. package/fe/packages/ui/react/hooks/useLanguage.d.ts +1 -6
  348. package/fe/packages/ui/react/hooks/useRefState.d.ts +18 -0
  349. package/fe/packages/ui/react/hooks/useRefState.js +28 -0
  350. package/fe/packages/ui/react/hooks/useWatch.d.ts +15 -0
  351. package/fe/packages/ui/react/hooks/useWatch.js +87 -0
  352. package/fe/packages/ui/react/hooks/useWatch.test.d.ts +2 -0
  353. package/fe/packages/ui/react/hooks/useWatch.test.js +22 -0
  354. package/fe/packages/ui/react/i18n/I18nProvider.d.ts +13 -0
  355. package/fe/packages/ui/react/i18n/I18nProvider.js +25 -0
  356. package/fe/packages/ui/react/i18n/index.d.ts +4 -0
  357. package/fe/packages/ui/react/i18n/index.js +3 -0
  358. package/fe/packages/ui/react/i18n/useI18n.d.ts +9 -0
  359. package/fe/packages/ui/react/i18n/useI18n.js +14 -0
  360. package/fe/packages/ui/react/index.css +238 -0
  361. package/fe/packages/ui/react/index.d.ts +2 -0
  362. package/fe/packages/ui/react/index.js +2 -2
  363. package/fe/packages/ui/react/lib/createStoreHook.d.ts +9 -0
  364. package/fe/packages/ui/react/lib/createStoreHook.js +6 -0
  365. package/fe/packages/ui/react/lib/export.d.ts +2 -46
  366. package/fe/packages/ui/react/lib/export.js +0 -40
  367. package/fe/packages/ui/react/lib/utils.d.ts +0 -24
  368. package/fe/packages/ui/react/lib/utils.js +0 -25
  369. package/fe/packages/ui/react/stores/breadcrumb.js +0 -2
  370. package/fe/packages/ui/react/stores/language.d.ts +3 -12
  371. package/fe/packages/ui/react/stores/language.js +2 -51
  372. package/fe/typings/type.d.ts +5 -0
  373. package/fe/typings/type.js +1 -0
  374. package/package.json +14 -2
  375. package/types/app/controller/base.d.ts +3 -3
  376. package/types/app/router/view.d.ts +2 -3
  377. package/types/app/service/project.d.ts +29 -4
  378. package/types/app/type.d.ts +1 -0
  379. package/types/app/typings.d.ts +12 -21
  380. package/types/bundler/defaultAlias.d.ts +3 -0
  381. package/types/bundler/utils.d.ts +1 -1
  382. package/types/config/config.default.d.ts +14 -0
  383. package/types/packages/common/LRUCache.d.ts +1 -0
  384. package/types/packages/common/array/index.d.ts +6 -0
  385. package/types/packages/common/cache/LRUCache.d.ts +12 -0
  386. package/types/packages/common/cache/index.d.ts +1 -0
  387. package/types/packages/common/guards/index.d.ts +8 -0
  388. package/types/packages/common/i18n/default.d.ts +86 -0
  389. package/types/packages/common/i18n/en-US.d.ts +86 -0
  390. package/types/packages/common/i18n/index.d.ts +18 -0
  391. package/types/packages/common/i18n/locales.d.ts +7 -0
  392. package/types/packages/common/i18n/types.d.ts +46 -0
  393. package/types/packages/common/index.d.ts +9 -0
  394. package/types/packages/common/log/index.d.ts +32 -0
  395. package/types/packages/common/number/index.d.ts +2 -0
  396. package/types/packages/common/object/filterEmpty.d.ts +2 -0
  397. package/types/packages/common/object/filtereEmpty.d.ts +1 -0
  398. package/types/packages/common/object/index.d.ts +4 -0
  399. package/types/packages/common/string/index.d.ts +3 -0
  400. package/types/packages/common/types/index.d.ts +3 -0
  401. package/types/packages/core/index.d.ts +1 -1
  402. package/types/packages/core/loader/router.d.ts +1 -1
  403. package/types/packages/core/types.d.ts +12 -3
  404. package/fe/packages/ui/react/components/ConfirmDialog.js +0 -9
  405. package/fe/packages/ui/react/components/Dropdown.d.ts +0 -16
  406. package/fe/packages/ui/react/components/Dropdown.js +0 -54
  407. package/fe/packages/ui/react/components/Form/SchemeForm/data.d.ts +0 -51
  408. package/fe/packages/ui/react/components/Form/SchemeForm/index.d.ts +0 -152
  409. package/fe/packages/ui/react/components/Form/SchemeForm/index.js +0 -69
  410. package/fe/packages/ui/react/components/Textarea.d.ts +0 -59
  411. package/fe/packages/ui/react/components/Textarea.js +0 -35
  412. package/fe/packages/ui/react/components/Tooltip.d.ts +0 -25
  413. package/fe/packages/ui/react/components/Tooltip.js +0 -118
  414. package/fe/packages/ui/react/components/table.js +0 -20
  415. package/fe/packages/ui/react/locales/index.d.ts +0 -8
  416. package/fe/packages/ui/react/locales/index.js +0 -6
  417. /package/fe/packages/ui/react/components/{breadcrumb.d.ts → breadcrumb/breadcrumb.d.ts} +0 -0
  418. /package/fe/packages/ui/react/components/{table.d.ts → table/table.d.ts} +0 -0
@@ -1,40 +1,261 @@
1
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Button, Form, FormItem, ImageUpload, Input, Label, SchemeForm, Skeleton, TableSearch, TreeSelect, useForm, } from '../../components';
3
- import { useRef, useState } from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Checkbox, ConfirmDialog, DataTable, Drawer, Dropdown, Form, FormItem, ImageUpload, Input, InputNumber, Label, message, Modal, modal, Pagination, PreviewImage, SchemaForm, Search, Select, Skeleton, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, TableSearch, Textarea, Tooltip, TreeSelect, useForm, } from '../../components';
3
+ import React, { useEffect, useRef, useState } from 'react';
4
4
  import DateTestPage from '../Date/DateTestPage';
5
- import { PreviewImage } from '../../components';
5
+ import MenuTestPage from './MenuTestPage';
6
+ function ThemeSwitcher() {
7
+ const [mode, setMode] = useState('dark');
8
+ const [theme, setTheme] = useState('default');
9
+ useEffect(() => {
10
+ const root = document.documentElement;
11
+ const previousTheme = root.getAttribute('data-theme');
12
+ const previousDark = root.classList.contains('dark');
13
+ root.classList.toggle('dark', mode === 'dark');
14
+ if (theme === 'default') {
15
+ root.removeAttribute('data-theme');
16
+ }
17
+ else {
18
+ root.setAttribute('data-theme', theme);
19
+ }
20
+ return () => {
21
+ root.classList.toggle('dark', previousDark);
22
+ if (previousTheme) {
23
+ root.setAttribute('data-theme', previousTheme);
24
+ }
25
+ else {
26
+ root.removeAttribute('data-theme');
27
+ }
28
+ };
29
+ }, [mode, theme]);
30
+ return (_jsx(Section, { title: "Theme", children: _jsxs("div", { className: "flex w-full flex-wrap items-center gap-6 rounded-xl border border-border bg-background p-4", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm text-muted-foreground", children: "\u6A21\u5F0F" }), _jsx(Button, { variant: mode === 'light' ? 'primary' : 'default', size: "sm", onClick: () => setMode('light'), children: "Light" }), _jsx(Button, { variant: mode === 'dark' ? 'primary' : 'default', size: "sm", onClick: () => setMode('dark'), children: "Dark" })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm text-muted-foreground", children: "\u4E3B\u9898" }), _jsx(Button, { variant: theme === 'default' ? 'primary' : 'default', size: "sm", onClick: () => setTheme('default'), children: "Default" }), _jsx(Button, { variant: theme === 'green' ? 'primary' : 'default', size: "sm", onClick: () => setTheme('green'), children: "Green" }), _jsx(Button, { variant: theme === 'gray' ? 'primary' : 'default', size: "sm", onClick: () => setTheme('gray'), children: "Gray" })] }), _jsxs("div", { className: "text-sm text-muted-foreground", children: ["\u5F53\u524D: ", mode, " / ", theme] })] }) }));
31
+ }
32
+ function Section({ title, children }) {
33
+ return (_jsxs("div", { className: "mb-8", children: [_jsx("h2", { className: "text-lg font-semibold mb-3 border-b pb-1", children: title }), _jsx("div", { className: "flex flex-wrap gap-3 items-start", children: children })] }));
34
+ }
35
+ function ButtonDemo() {
36
+ const [loading, setLoading] = useState(false);
37
+ return (_jsxs(Section, { title: "Button", children: [_jsx(Button, { children: "default" }), _jsx(Button, { variant: "primary", children: "primary" }), _jsx(Button, { variant: "dashed", children: "dashed" }), _jsx(Button, { variant: "text", children: "text" }), _jsx(Button, { variant: "link", href: "#button", children: "link" }), _jsx(Button, { state: "danger", children: "danger" }), _jsx(Button, { variant: "primary", state: "danger", children: "primary danger" }), _jsx("div", { className: " bg-red-300 p-1.5", children: _jsx(Button, { state: "ghost", children: "ghost" }) }), _jsx(Button, { variant: "primary", state: "ghost", children: "primary ghost" }), _jsx(Button, { disabled: true, children: "disabled" }), _jsx(Button, { loading: loading, onClick: () => {
38
+ setLoading(true);
39
+ setTimeout(() => setLoading(false), 2000);
40
+ }, children: "loading (click)" }), _jsx(Button, { size: "sm", children: "sm" }), _jsx(Button, { size: "md", children: "md" }), _jsx(Button, { size: "lg", children: "lg" })] }));
41
+ }
42
+ function InputDemo() {
43
+ return (_jsxs(Section, { title: "Input", children: [_jsx(Input, { placeholder: "\u666E\u901A\u8F93\u5165\u6846" }), _jsx(Input, { type: "password", placeholder: "\u5BC6\u7801\u8F93\u5165\u6846" }), _jsx(Input, { disabled: true, placeholder: "\u7981\u7528\u72B6\u6001" })] }));
44
+ }
45
+ function InputNumberDemo() {
46
+ const [price, setPrice] = useState(12.5);
47
+ const [ratio, setRatio] = useState(0.25);
48
+ return (_jsxs(Section, { title: "InputNumber", children: [_jsx(InputNumber, { placeholder: "\u57FA\u7840\u6570\u5B57\u8F93\u5165", className: "w-48" }), _jsx(InputNumber, { value: price, onChange: setPrice, precision: 2, min: 0, max: 9999, placeholder: "\u4EF7\u683C", addonAfter: _jsx("span", { className: "text-xs text-muted-foreground", children: "CNY" }), className: "w-56" }), _jsx(InputNumber, { value: ratio, onChange: setRatio, precision: 2, step: 0.05, min: 0, max: 1, allowStep: true, placeholder: "\u6BD4\u4F8B", className: "w-48" }), _jsx(InputNumber, { defaultValue: 10, step: 0.5, precision: 1, allowStep: true, allowClear: true, className: "w-48" }), _jsx(InputNumber, { disabled: true, defaultValue: 88.8, precision: 1, className: "w-48" })] }));
49
+ }
50
+ function TextareaDemo() {
51
+ const [val, setVal] = useState('');
52
+ return (_jsxs(Section, { title: "Textarea", children: [_jsx(Textarea, { placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9\uFF08\u6700\u591A 500 \u5B57\uFF09", value: val, onChange: (v) => setVal(v), className: "w-80" }), _jsx(Textarea, { placeholder: "\u4E0D\u663E\u793A\u8BA1\u6570", showCount: false, className: "w-80" })] }));
53
+ }
54
+ function SelectDemo() {
55
+ const [val, setVal] = useState(undefined);
56
+ const options = [
57
+ { label: '选项 A', value: 'a' },
58
+ { label: '选项 B', value: 'b' },
59
+ { label: '选项 C', value: 'c' },
60
+ ];
61
+ return (_jsxs(Section, { title: "Select", children: [_jsx(Select, { options: options, value: val, onChange: setVal, placeholder: "\u8BF7\u9009\u62E9", className: "w-40" }), _jsx(Select, { options: options, placeholder: "\u4E0D\u53EF\u641C\u7D22", searchable: false, className: "w-40" }), _jsx(Select, { options: options, placeholder: "\u4E0D\u53EF\u6E05\u9664", clearable: false, className: "w-40" }), _jsx(Select, { options: options, disabled: true, placeholder: "\u7981\u7528", className: "w-40" }), _jsxs("div", { className: "relative w-64 rounded-lg border border-border bg-muted/30 p-4", children: [_jsx("div", { className: "mb-2 text-sm text-muted-foreground", children: "parent popup container" }), _jsx(Select, { options: options, placeholder: "\u6302\u8F7D\u5230\u7236\u5143\u7D20", getPopupContainer: "parent", className: "w-full" })] })] }));
62
+ }
63
+ function CheckboxDemo() {
64
+ const [checked, setChecked] = useState(false);
65
+ return (_jsxs(Section, { title: "Checkbox", children: [_jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [_jsx(Checkbox, { checked: checked, onChange: (c) => setChecked(c) }), _jsxs("span", { children: ["\u53D7\u63A7: ", checked ? '选中' : '未选中'] })] }), _jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [_jsx(Checkbox, { defaultChecked: true }), _jsx("span", { children: "\u975E\u53D7\u63A7\u9ED8\u8BA4\u9009\u4E2D" })] }), _jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [_jsx(Checkbox, { indeterminate: true }), _jsx("span", { children: "\u534A\u9009\u72B6\u6001" })] }), _jsxs("label", { className: "flex items-center gap-2 cursor-pointer", children: [_jsx(Checkbox, { disabled: true }), _jsx("span", { children: "\u7981\u7528" })] })] }));
66
+ }
67
+ function SwitchDemo() {
68
+ const [on, setOn] = useState(false);
69
+ return (_jsxs(Section, { title: "Switch", children: [_jsx(Switch, { checked: on, onChange: setOn }), _jsx("span", { className: "self-center text-sm", children: on ? 'ON' : 'OFF' }), _jsx(Switch, { defaultChecked: true }), _jsx(Switch, { disabled: true }), _jsx(Switch, { disabled: true, checked: true })] }));
70
+ }
71
+ function TooltipDemo() {
72
+ return (_jsx(Section, { title: "Tooltip", children: ['top', 'bottom', 'left', 'right'].map((p) => (_jsx(Tooltip, { content: `placement: ${p}`, placement: p, children: _jsx(Button, { children: p }) }, p))) }));
73
+ }
74
+ function DropdownDemo() {
75
+ const items = [
76
+ { key: 'edit', label: '编辑', onClick: () => console.log('edit') },
77
+ { key: 'copy', label: '复制', onClick: () => console.log('copy') },
78
+ { key: 'delete', label: '删除', danger: true, onClick: () => console.log('delete') },
79
+ ];
80
+ return (_jsxs(Section, { title: "Dropdown", children: [_jsx(Dropdown, { items: items, children: _jsx(Button, { children: "\u64CD\u4F5C \u25BE" }) }), _jsx(Dropdown, { items: items, placement: "bottom-start", children: _jsx(Button, { variant: "text", children: "bottom-start \u25BE" }) })] }));
81
+ }
82
+ function MessageDemo() {
83
+ return (_jsxs(Section, { title: "Message (imperative)", children: [_jsx(Button, { onClick: () => message.success('操作成功'), children: "success" }), _jsx(Button, { onClick: () => message.error('操作失败'), children: "error" }), _jsx(Button, { onClick: () => message.warning('警告信息'), children: "warning" }), _jsx(Button, { onClick: () => message.info('提示信息'), children: "info" }), _jsx(Button, { onClick: () => {
84
+ const id = message.success('5秒后关闭', { duration: 5000 });
85
+ setTimeout(() => message.close(id), 2000);
86
+ }, children: "\u63D0\u524D\u5173\u95ED" })] }));
87
+ }
88
+ function ModalDemo() {
89
+ const [open, setOpen] = useState(false);
90
+ return (_jsxs(Section, { title: "Modal", children: [_jsx(Button, { onClick: () => setOpen(true), children: "JSX Modal" }), _jsx(Button, { onClick: () => modal.open({
91
+ title: '命令式弹窗',
92
+ content: _jsx("p", { children: "\u8FD9\u662F\u547D\u4EE4\u5F0F\u6253\u5F00\u7684\u5F39\u7A97\u5185\u5BB9\u3002" }),
93
+ }), children: "modal.open" }), _jsx(Button, { onClick: () => modal.confirm({
94
+ title: '确认操作',
95
+ content: '确定要执行此操作吗?',
96
+ onOk: () => {
97
+ message.success('已确认');
98
+ },
99
+ onCancel: () => {
100
+ message.info('已取消');
101
+ },
102
+ }), children: "modal.confirm" }), _jsxs(Modal, { open: open, onClose: () => setOpen(false), title: "JSX \u5F39\u7A97", children: [_jsx("p", { children: "\u8FD9\u662F\u4E00\u4E2A\u4F7F\u7528 JSX \u63A7\u5236\u7684\u5F39\u7A97\u3002" }), _jsx("div", { className: "mt-4 flex justify-end gap-2", children: _jsx(Button, { onClick: () => setOpen(false), children: "\u5173\u95ED" }) })] })] }));
103
+ }
104
+ function DrawerDemo() {
105
+ const [placement, setPlacement] = useState('right');
106
+ const [open, setOpen] = useState(false);
107
+ const openDrawer = (nextPlacement) => {
108
+ setPlacement(nextPlacement);
109
+ setOpen(true);
110
+ };
111
+ return (_jsxs(Section, { title: "Drawer", children: [_jsx(Button, { onClick: () => openDrawer('left'), children: "left" }), _jsx(Button, { onClick: () => openDrawer('right'), children: "right" }), _jsx(Button, { onClick: () => openDrawer('top'), children: "top" }), _jsx(Button, { onClick: () => openDrawer('bottom'), children: "bottom" }), _jsx(Button, { onClick: () => openDrawer('right'), variant: "primary", children: "\u6253\u5F00\u8BE6\u60C5" }), _jsx(Drawer, { open: open, onClose: () => setOpen(false), title: `Drawer ${placement}`, placement: placement, width: 420, height: 320, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { onClick: () => setOpen(false), children: "\u53D6\u6D88" }), _jsx(Button, { variant: "primary", onClick: () => {
112
+ message.success('已保存');
113
+ setOpen(false);
114
+ }, children: "\u4FDD\u5B58" })] }), children: _jsxs("div", { className: "space-y-4", children: [_jsxs("div", { children: [_jsx("div", { className: "mb-1 text-sm font-medium text-foreground", children: "\u5916\u90E8 children" }), _jsx("p", { className: "text-sm leading-6 text-muted-foreground", children: "\u8FD9\u91CC\u7684\u5185\u5BB9\u5B8C\u5168\u7531\u8C03\u7528\u65B9\u5B9A\u4E49\uFF0C\u53EF\u4EE5\u653E\u8868\u5355\u3001\u5217\u8868\u3001\u8BE6\u60C5\u6216\u4EFB\u610F JSX\u3002" })] }), _jsxs("div", { className: "grid gap-3", children: [_jsx(Label, { label: "\u540D\u79F0", layout: "vertical", children: _jsx(Input, { placeholder: "\u8BF7\u8F93\u5165\u540D\u79F0" }) }), _jsx(Label, { label: "\u72B6\u6001", layout: "vertical", children: _jsx(Select, { placeholder: "\u8BF7\u9009\u62E9\u72B6\u6001", options: [
115
+ { label: '启用', value: 'enabled' },
116
+ { label: '停用', value: 'disabled' },
117
+ ] }) })] })] }) })] }));
118
+ }
119
+ function ConfirmDialogDemo() {
120
+ const [open, setOpen] = useState(false);
121
+ return (_jsxs(Section, { title: "ConfirmDialog", children: [_jsx(Button, { onClick: () => setOpen(true), children: "\u6253\u5F00\u786E\u8BA4\u6846" }), _jsx(ConfirmDialog, { open: open, title: "\u5220\u9664\u786E\u8BA4", content: "\u786E\u5B9A\u8981\u5220\u9664\u6B64\u6761\u6570\u636E\u5417\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002", onOk: () => {
122
+ message.success('已删除');
123
+ setOpen(false);
124
+ }, onCancel: () => setOpen(false) })] }));
125
+ }
126
+ function PaginationDemo() {
127
+ const [page, setPage] = useState(1);
128
+ const [pageSize, setPageSize] = useState(10);
129
+ return (_jsx(Section, { title: "Pagination", children: _jsxs("div", { className: "w-full", children: [_jsxs("p", { className: "text-sm mb-2", children: ["\u5F53\u524D\u9875: ", page, " / \u6BCF\u9875: ", pageSize] }), _jsx(Pagination, { current: page, pageSize: pageSize, total: 238, onChange: setPage, onPageSizeChange: setPageSize })] }) }));
130
+ }
131
+ function TableDemo() {
132
+ const rows = [
133
+ { id: 1, name: '张三', role: '管理员', status: '正常' },
134
+ { id: 2, name: '李四', role: '用户', status: '禁用' },
135
+ { id: 3, name: '王五', role: '审计员', status: '正常' },
136
+ ];
137
+ return (_jsx(Section, { title: "Table (\u4F4E\u5C42)", children: _jsx("div", { className: "w-full", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs("tr", { children: [_jsx(TableHead, { children: "ID" }), _jsx(TableHead, { children: "\u59D3\u540D" }), _jsx(TableHead, { children: "\u89D2\u8272" }), _jsx(TableHead, { children: "\u72B6\u6001" }), _jsx(TableHead, { isAction: true, children: "\u64CD\u4F5C" })] }) }), _jsx(TableBody, { children: rows.map((row) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: row.id }), _jsx(TableCell, { children: row.name }), _jsx(TableCell, { children: row.role }), _jsx(TableCell, { children: row.status }), _jsx(TableCell, { isAction: true, children: _jsx(Button, { variant: "link", size: "sm", children: "\u7F16\u8F91" }) })] }, row.id))) })] }) }) }));
138
+ }
139
+ function DataTableDemo() {
140
+ const [selectedKeys, setSelectedKeys] = useState([]);
141
+ const columns = [
142
+ { key: 'id', title: 'ID', width: '60px' },
143
+ { key: 'name', title: '姓名' },
144
+ { key: 'role', title: '角色' },
145
+ { key: 'status', title: '状态' },
146
+ ];
147
+ const data = [
148
+ { id: 1, name: '张三', role: '管理员', status: '正常' },
149
+ { id: 2, name: '李四', role: '用户', status: '禁用' },
150
+ { id: 3, name: '王五', role: '审计员', status: '正常' },
151
+ { id: 4, name: '赵六', role: '用户', status: '正常' },
152
+ { id: 5, name: '孙七', role: '用户', status: '正常' },
153
+ ];
154
+ return (_jsx(Section, { title: "DataTable", children: _jsxs("div", { className: "w-full", children: [_jsxs("p", { className: "text-sm mb-2", children: ["\u5DF2\u9009: ", JSON.stringify(selectedKeys)] }), _jsx(DataTable, { columns: columns, data: data, rowKey: "id", rowSelection: {
155
+ selectedRowKeys: selectedKeys,
156
+ onChange: (keys) => setSelectedKeys(keys),
157
+ } })] }) }));
158
+ }
159
+ function SearchDemo() {
160
+ return (_jsx(Section, { title: "Search", children: _jsx("div", { className: "w-full", children: _jsxs(Search, { schemas: [
161
+ { type: 'input', key: 'keyword', label: '关键字', fieldProps: { placeholder: '请输入' } },
162
+ {
163
+ type: 'select',
164
+ key: 'status',
165
+ label: '状态',
166
+ fieldProps: {
167
+ options: [
168
+ { label: '正常', value: 'active' },
169
+ { label: '禁用', value: 'disabled' },
170
+ ],
171
+ placeholder: '请选择',
172
+ },
173
+ },
174
+ ], children: [_jsx(Button, { type: "submit", variant: "primary", children: "\u641C\u7D22" }), _jsx(Button, { type: "reset", children: "\u91CD\u7F6E" })] }) }) }));
175
+ }
176
+ function BreadcrumbDemo() {
177
+ const [items, setItems] = useState([
178
+ { id: 'home', label: '首页' },
179
+ { id: 'list', label: '用户列表' },
180
+ { id: 'detail', label: '用户详情', active: true },
181
+ ]);
182
+ return (_jsx(Section, { title: "Breadcrumb", children: _jsx(Breadcrumb, { children: _jsx(BreadcrumbList, { children: items.map((item, idx) => (_jsxs(React.Fragment, { children: [_jsx(BreadcrumbItem, { children: _jsx(BreadcrumbPage, { active: item.active, onClose: () => setItems((prev) => prev.filter((i) => i.id !== item.id)), onClick: () => setItems((prev) => prev.map((i) => ({ ...i, active: i.id === item.id }))), className: "cursor-pointer", children: item.label }) }), idx < items.length - 1 && _jsx(BreadcrumbSeparator, {})] }, item.id))) }) }) }));
183
+ }
184
+ function LabelDemo() {
185
+ return (_jsxs(Section, { title: "Label", children: [_jsx(Label, { label: "\u6C34\u5E73\u5E03\u5C40", layout: "horizontal", children: _jsx("span", { className: "text-sm", children: "\u5185\u5BB9\u533A\u57DF" }) }), _jsx(Label, { label: "\u5782\u76F4\u5E03\u5C40", layout: "vertical", children: _jsx("span", { className: "text-sm", children: "\u5185\u5BB9\u533A\u57DF" }) })] }));
186
+ }
187
+ function FormDemo() {
188
+ const [form] = useForm();
189
+ return (_jsx(Section, { title: "Form", children: _jsxs(Form, { form: form, onFinish: (v) => console.log('表单值:', v), children: [_jsx(FormItem, { name: "username", label: "\u7528\u6237\u540D", required: true, rules: [{ required: true, message: '请输入用户名' }], children: _jsx(Input, { placeholder: "\u8BF7\u8F93\u5165\u7528\u6237\u540D" }) }), _jsx(FormItem, { name: "password", label: "\u5BC6\u7801", required: true, rules: [{ required: true, message: '请输入密码' }], children: _jsx(Input, { type: "password", placeholder: "\u8BF7\u8F93\u5165\u5BC6\u7801" }) }), _jsx(Button, { type: "submit", children: "\u63D0\u4EA4" })] }) }));
190
+ }
191
+ function SchemaFormDemo() {
192
+ const form = useRef(undefined);
193
+ return (_jsx(Section, { title: "SchemaForm", children: _jsx(SchemaForm, { layout: "horizontal", getForm: (f) => {
194
+ form.current = f;
195
+ }, schemas: [
196
+ {
197
+ key: 'username',
198
+ label: '用户名',
199
+ type: 'input',
200
+ required: true,
201
+ rules: [{ required: true, message: '请输入用户名' }],
202
+ fieldProps: { placeholder: '请输入用户名' },
203
+ },
204
+ {
205
+ key: 'role',
206
+ label: '角色',
207
+ type: 'select',
208
+ fieldProps: {
209
+ placeholder: '请选择',
210
+ options: [
211
+ { label: '管理员', value: 'admin' },
212
+ { label: '用户', value: 'user' },
213
+ ],
214
+ },
215
+ },
216
+ ], onFinish: (values) => console.log(values) }) }));
217
+ }
218
+ function TableSearchDemo() {
219
+ return (_jsx(Section, { title: "TableSearch", children: _jsx(TableSearch, { onSearch: (v) => console.log(v), schemas: [
220
+ { type: 'input', key: 'q1', label: '字段1', fieldProps: {} },
221
+ { type: 'select', key: 'q2', label: '状态', fieldProps: { options: [{ value: 'a', label: 'A' }] } },
222
+ { type: 'switch', key: 'q3', label: '开关', fieldProps: {} },
223
+ { type: 'date', key: 'q4', label: '日期', fieldProps: {} },
224
+ { type: 'date', key: 'q5', label: '范围', fieldProps: { mode: 'range' } },
225
+ { type: 'textarea', key: 'q6', label: '文本', fieldProps: {} },
226
+ { type: 'input', key: 'q7', label: '字段7', fieldProps: {} },
227
+ { type: 'input', key: 'q8', label: '字段8', fieldProps: {} },
228
+ ] }) }));
229
+ }
230
+ function SkeletonDemo() {
231
+ return (_jsx(Section, { title: "Skeleton", children: _jsxs("div", { className: "w-full space-y-4", children: [_jsxs("div", { children: [_jsx("p", { className: "text-xs text-gray-500 mb-1", children: "pageloading" }), _jsx(Skeleton, { mode: "pageloading", rows: 3, showTitle: true, showActions: true })] }), _jsxs("div", { children: [_jsx("p", { className: "text-xs text-gray-500 mb-1", children: "tableloading" }), _jsx(Skeleton, { mode: "tableloading", rows: 4 })] }), _jsxs("div", { children: [_jsx("p", { className: "text-xs text-gray-500 mb-1", children: "componentsloading" }), _jsx(Skeleton, { mode: "componentsloading", rows: 2 })] })] }) }));
232
+ }
6
233
  function TreeSelectDemo() {
7
234
  const [value, setValue] = useState(['1.1.1', '1.1.2']);
8
235
  const [indeterminate, setIndeterminate] = useState([]);
9
236
  const treeData = [
10
237
  {
11
238
  id: '1',
12
- name: '1',
239
+ name: '节点 1',
13
240
  children: [
14
241
  {
15
242
  id: '1.1',
16
- name: '1.1',
243
+ name: '节点 1.1',
17
244
  children: [
18
245
  {
19
246
  id: '1.1.1',
20
- name: '1.1.1',
247
+ name: '节点 1.1.1',
21
248
  children: [
22
- {
23
- id: '1.1.1.1',
24
- name: '1.1.1.1',
25
- },
26
- {
27
- id: '1.1.1.2',
28
- name: '1.1.1.2',
29
- },
249
+ { id: '1.1.1.1', name: '1.1.1.1' },
250
+ { id: '1.1.1.2', name: '1.1.1.2' },
30
251
  ],
31
252
  },
32
- { id: '1.1.2', name: '1.1.2' },
253
+ { id: '1.1.2', name: '节点 1.1.2' },
33
254
  ],
34
255
  },
35
256
  {
36
257
  id: '1.2',
37
- name: '1.2',
258
+ name: '节点 1.2',
38
259
  children: [
39
260
  { id: '1.2.1', name: '1.2.1' },
40
261
  { id: '1.2.2', name: '1.2.2' },
@@ -43,76 +264,25 @@ function TreeSelectDemo() {
43
264
  ],
44
265
  },
45
266
  ];
46
- return (_jsxs("div", { children: [_jsxs("div", { className: "mb-4", children: [_jsxs("div", { children: ["\u9009\u4E2D: ", JSON.stringify(value)] }), _jsxs("div", { children: ["\u534A\u9009: ", JSON.stringify(indeterminate)] })] }), _jsx(TreeSelect, { data: treeData, value: value, onChange: ({ checked, indeterminate }) => {
47
- setValue(checked);
48
- setIndeterminate(indeterminate);
49
- } })] }));
267
+ return (_jsx(Section, { title: "TreeSelect", children: _jsxs("div", { children: [_jsxs("div", { className: "text-sm mb-2", children: [_jsxs("span", { children: ["\u9009\u4E2D: ", JSON.stringify(value)] }), _jsxs("span", { className: "ml-4", children: ["\u534A\u9009: ", JSON.stringify(indeterminate)] })] }), _jsx(TreeSelect, { data: treeData, value: value, onChange: ({ checked, indeterminate }) => {
268
+ setValue(checked);
269
+ setIndeterminate(indeterminate);
270
+ } })] }) }));
50
271
  }
51
272
  function PreviewImageDemo() {
52
273
  const images = [
53
- 'https://s3.ap-northeast-1.amazonaws.com/ezpay-test/52903c41-2eec-4326-95f0-79d56a4dc19c.png',
54
- 'https://aisearch.cdn.bcebos.com/homepage/dashboard/ai_picture_create/15.png',
274
+ 'https://images.unsplash.com/photo-1778512828600-4a6540a1a115?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHw0fHx8ZW58MHx8fHx8',
275
+ 'https://images.unsplash.com/photo-1778392120781-a6b2b55dc12a?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwyNnx8fGVufDB8fHx8fA%3D%3D',
55
276
  ];
56
- return (_jsx(_Fragment, { children: _jsx(PreviewImage, { images: images, initialIndex: 0 }) }));
277
+ return (_jsx(Section, { title: "PreviewImage", children: _jsx(PreviewImage, { images: images, initialIndex: 0 }) }));
57
278
  }
58
- function MyForm() {
59
- const [form] = useForm();
60
- const onFinish = (values) => {
61
- console.log('表单值:', values);
62
- };
63
- return (_jsxs(Form, { form: form, onFinish: onFinish, children: [_jsx(FormItem, { name: "username", label: "\u7528\u6237\u540D", required: true, rules: [{ required: true, message: '请输入用户名' }], children: _jsx(Input, { placeholder: "\u8BF7\u8F93\u5165\u7528\u6237\u540D" }) }), _jsx(FormItem, { name: "password", label: "\u5BC6\u7801", required: true, rules: [{ required: true, message: '请输入密码' }], children: _jsx(Input, { type: "password", placeholder: "\u8BF7\u8F93\u5165\u5BC6\u7801" }) }), _jsx(Button, { type: "submit", children: "\u63D0\u4EA4" })] }));
279
+ function ImageUploadDemo() {
280
+ return (_jsx(Section, { title: "ImageUpload", children: _jsx(ImageUpload, { accept: ".jpg,.png", maxCount: 4, beforeChange: (f) => {
281
+ console.log(f);
282
+ return parseInt(Math.random() * 10 + '') % 2 === 0;
283
+ } }) }));
64
284
  }
65
285
  const TestPage = () => {
66
- const form = useRef(undefined);
67
- return (_jsxs("div", { children: [_jsx("h1", { children: "button" }), _jsx(Button, { onClick: () => console.log(form), children: "click" }), _jsx("h2", { children: "text" }), _jsx(Button, { variant: "text", onClick: () => console.log(form), children: "click" }), _jsx(Button, { disabled: true, variant: "text", onClick: () => console.log(form), children: "click" }), _jsx("h1", { children: "input" }), _jsx(Input, {}), _jsx("h1", { children: "form" }), _jsx(MyForm, {}), _jsx("h1", { children: "schemeform" }), _jsx(SchemeForm, { layout: "horizontal", getForm: (f) => {
68
- form.current = f;
69
- }, schemes: [
70
- {
71
- name: 'username',
72
- label: '用户名',
73
- type: 'input',
74
- required: true,
75
- rules: [{ required: true, message: '请输入用户名' }],
76
- fieldProps: {
77
- placeholder: '请输入用户名',
78
- },
79
- },
80
- {
81
- name: 'role',
82
- label: '角色',
83
- type: 'select',
84
- fieldProps: {
85
- placeholder: '请选择',
86
- options: [
87
- { label: '管理员', value: 'admin' },
88
- { label: '用户', value: 'user' },
89
- ],
90
- },
91
- },
92
- ], onFinish: (values) => console.log(values) }), _jsx("h1", { children: "label" }), _jsx("div", { children: _jsx(Label, { label: "labelName", layout: "horizontal", children: "123" }) }), _jsx("h1", { children: "TableSearch " }), _jsx(TableSearch, { onSearch: (v) => {
93
- console.log(v);
94
- }, schemes: [
95
- { type: 'input', fieldProps: {}, name: '1', label: '1' },
96
- { type: 'switch', fieldProps: {}, name: '2', label: '2' },
97
- { type: 'select', fieldProps: { options: [{ value: '3', label: '3' }] }, name: '3', label: '3' },
98
- { type: 'textarea', fieldProps: {}, name: '4', label: '4' },
99
- { type: 'date', fieldProps: {}, name: '5', label: '5' },
100
- {
101
- type: 'date',
102
- fieldProps: {
103
- mode: 'range',
104
- },
105
- name: '6',
106
- label: '6',
107
- },
108
- { type: 'input', fieldProps: {}, name: '7', label: '7' },
109
- { type: 'date', fieldProps: {}, name: '8', label: '8' },
110
- { type: 'input', fieldProps: {}, name: '9', label: '9' },
111
- { type: 'input', fieldProps: {}, name: '10', label: '10' },
112
- { type: 'input', fieldProps: {}, name: '11', label: '11' },
113
- ] }), _jsx("h1", { children: "Skeleton" }), _jsx(Skeleton, { mode: "pageloading", rows: 5, showTitle: true, showActions: true }), _jsx(Skeleton, { mode: "tableloading", rows: 8 }), _jsx(Skeleton, { mode: "componentsloading", rows: 3 }), _jsx("h1", { children: "TreeSelect" }), _jsx(TreeSelectDemo, {}), _jsx(DateTestPage, {}), _jsx("h1", { children: "PreviewImage" }), _jsx(PreviewImageDemo, {}), _jsx("h1", { children: "ImageUpload" }), _jsx(ImageUpload, { accept: ".jpg,.png", maxCount: 4, beforeChange: (f) => {
114
- console.log(f);
115
- return parseInt(Math.random() * 10 + '') % 2 === 0;
116
- } })] }));
286
+ return (_jsxs("div", { className: "p-6 max-w-5xl mx-auto", children: [_jsx("h1", { className: "text-2xl font-bold mb-6", children: "\u7EC4\u4EF6\u5C55\u793A" }), _jsx(ThemeSwitcher, {}), _jsx(ButtonDemo, {}), _jsx(InputDemo, {}), _jsx(InputNumberDemo, {}), _jsx(TextareaDemo, {}), _jsx(SelectDemo, {}), _jsx(CheckboxDemo, {}), _jsx(SwitchDemo, {}), _jsx(TooltipDemo, {}), _jsx(DropdownDemo, {}), _jsx(MessageDemo, {}), _jsx(ModalDemo, {}), _jsx(DrawerDemo, {}), _jsx(ConfirmDialogDemo, {}), _jsx(PaginationDemo, {}), _jsx(TableDemo, {}), _jsx(DataTableDemo, {}), _jsx(SearchDemo, {}), _jsx(BreadcrumbDemo, {}), _jsx(LabelDemo, {}), _jsx(FormDemo, {}), _jsx(SchemaFormDemo, {}), _jsx(TableSearchDemo, {}), _jsx(SkeletonDemo, {}), _jsx(TreeSelectDemo, {}), _jsx(DateTestPage, {}), _jsx(PreviewImageDemo, {}), _jsx(ImageUploadDemo, {}), _jsx(MenuTestPage, {})] }));
117
287
  };
118
288
  export default TestPage;
@@ -0,0 +1,12 @@
1
+ export declare const executionPhaseType: {
2
+ readonly mount: "mount";
3
+ readonly render: "render";
4
+ readonly unMount: "unMount";
5
+ };
6
+ type ExecutionPhaseTypeKeys = keyof typeof executionPhaseType;
7
+ export type ExecutionPhaseType = (typeof executionPhaseType)[ExecutionPhaseTypeKeys];
8
+ export default function useExecuteOnce<T>(factory: () => T, options?: {
9
+ executionPhase: ExecutionPhaseType[] | ExecutionPhaseType;
10
+ }): T | null;
11
+ export {};
12
+ //# sourceMappingURL=useExecuteOnce.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+ export const executionPhaseType = {
3
+ mount: 'mount',
4
+ render: 'render',
5
+ unMount: 'unMount',
6
+ };
7
+ export default function useExecuteOnce(factory, options) {
8
+ const { executionPhase: pExecutionPhase = executionPhaseType.render } = options ?? {};
9
+ const result = useRef(null);
10
+ const _executionPhase = useMemo(() => (typeof pExecutionPhase === 'string' ? [pExecutionPhase] : pExecutionPhase), [pExecutionPhase]);
11
+ const allowExecution = useRef([]);
12
+ const executionPhase = useRef(_executionPhase);
13
+ const runFN = (phase) => {
14
+ if (!allowExecution.current.includes(phase)) {
15
+ result.current = factory();
16
+ allowExecution.current.push(phase);
17
+ }
18
+ };
19
+ const fn = useRef(runFN);
20
+ executionPhase.current = _executionPhase;
21
+ fn.current = runFN;
22
+ if (executionPhase.current.includes(executionPhaseType.render)) {
23
+ fn.current(executionPhaseType.render);
24
+ }
25
+ useEffect(() => {
26
+ if (executionPhase.current.includes(executionPhaseType.mount)) {
27
+ fn.current(executionPhaseType['mount']);
28
+ }
29
+ return () => {
30
+ if (executionPhase.current.includes(executionPhaseType['unMount'])) {
31
+ fn.current(executionPhaseType['unMount']);
32
+ }
33
+ };
34
+ }, []);
35
+ return result.current;
36
+ }
@@ -1,3 +1,3 @@
1
- declare const useInit: (callback: () => void) => void;
1
+ declare const useInit: (callback: (isInit: boolean) => void) => void;
2
2
  export default useInit;
3
3
  //# sourceMappingURL=useInit.d.ts.map
@@ -2,7 +2,7 @@ import { useRef } from 'react';
2
2
  const useInit = (callback) => {
3
3
  const isInit = useRef(false);
4
4
  if (!isInit.current) {
5
- callback();
5
+ callback(isInit.current);
6
6
  isInit.current = true;
7
7
  }
8
8
  };
@@ -1,7 +1,2 @@
1
- export declare function useLanguage(): {
2
- language: import("../locales").Language;
3
- } & {
4
- setLanguage: (lang: import("../locales").Language) => void;
5
- t: typeof import("../stores/language").t;
6
- };
1
+ export declare function useLanguage(): import("../../../common/index.js").I18nStore;
7
2
  //# sourceMappingURL=useLanguage.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { RefObject } from 'react';
2
+ type SetState<S> = (value: S | ((preValue: S) => S), callback?: CallBackFN<S>) => void;
3
+ type CallBackFN<T> = (value: T) => void;
4
+ type RefState<T> = RefObject<{
5
+ data: T;
6
+ }>;
7
+ export default function useRefState<S>(initialState: S | (() => S)): [
8
+ S,
9
+ SetState<S>,
10
+ RefState<S>
11
+ ];
12
+ export default function useRefState<S = undefined>(): [
13
+ S | undefined,
14
+ SetState<S | undefined>,
15
+ RefState<S | undefined>
16
+ ];
17
+ export {};
18
+ //# sourceMappingURL=useRefState.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { useState as RUS, useCallback, useLayoutEffect, useRef } from 'react';
2
+ import useInit from './useInit';
3
+ export default function useRefState(initialState) {
4
+ const [v, setValue] = RUS(initialState);
5
+ const data = useRef({ data: undefined });
6
+ const callbackRef = useRef(null);
7
+ const [callbackVersion, setCallbackVersion] = RUS(0);
8
+ useInit(() => {
9
+ data.current.data = v;
10
+ });
11
+ const setData = useCallback((action, callback) => {
12
+ const value = typeof action === 'function' ? action(data.current.data) : action;
13
+ setValue(value);
14
+ data.current.data = value;
15
+ if (callback) {
16
+ callbackRef.current = callback;
17
+ setCallbackVersion((version) => version + 1);
18
+ }
19
+ }, [setCallbackVersion, setValue]);
20
+ useLayoutEffect(() => {
21
+ if (callbackRef.current) {
22
+ const callback = callbackRef.current;
23
+ callbackRef.current = null;
24
+ callback(data.current.data);
25
+ }
26
+ }, [callbackVersion]);
27
+ return [v, setData, data];
28
+ }
@@ -0,0 +1,15 @@
1
+ export type WatchCallback<T> = (value: T, prevValue: T | undefined) => void | (() => void);
2
+ export type WatchCompare<T> = (value: T, prevValue: T) => boolean;
3
+ export type WatchCompareType = 'identity' | 'shallow';
4
+ export type WatchSelector<TSource, TValue> = (source: TSource) => TValue;
5
+ export type UseWatchOptions<T> = {
6
+ immediate?: boolean;
7
+ compare?: WatchCompareType | WatchCompare<T>;
8
+ };
9
+ export declare const identityCompare: <T>(value: T, prevValue: T) => boolean;
10
+ export declare const shallowCompare: <T>(value: T, prevValue: T) => boolean;
11
+ export declare const defaultCompare: <T>(value: T, prevValue: T) => boolean;
12
+ export declare function useWatch<T>(value: T, callback: WatchCallback<T>, options?: UseWatchOptions<T>): void;
13
+ export declare function useWatch<TSource, TValue>(source: TSource, selector: WatchSelector<TSource, TValue>, callback: WatchCallback<TValue>, options?: UseWatchOptions<TValue>): void;
14
+ export default useWatch;
15
+ //# sourceMappingURL=useWatch.d.ts.map
@@ -0,0 +1,87 @@
1
+ import { useEffect, useRef } from 'react';
2
+ export const identityCompare = (value, prevValue) => Object.is(value, prevValue);
3
+ export const shallowCompare = (value, prevValue) => {
4
+ if (Object.is(value, prevValue)) {
5
+ return true;
6
+ }
7
+ if (Array.isArray(value) && Array.isArray(prevValue)) {
8
+ if (value.length !== prevValue.length) {
9
+ return false;
10
+ }
11
+ return value.every((item, index) => Object.is(item, prevValue[index]));
12
+ }
13
+ if (value &&
14
+ prevValue &&
15
+ typeof value === 'object' &&
16
+ typeof prevValue === 'object') {
17
+ const valuePrototype = Object.getPrototypeOf(value);
18
+ const prevValuePrototype = Object.getPrototypeOf(prevValue);
19
+ if (valuePrototype !== prevValuePrototype ||
20
+ (valuePrototype !== Object.prototype && valuePrototype !== null)) {
21
+ return false;
22
+ }
23
+ const valueKeys = Object.keys(value);
24
+ const prevValueKeys = Object.keys(prevValue);
25
+ if (valueKeys.length !== prevValueKeys.length) {
26
+ return false;
27
+ }
28
+ return valueKeys.every((key) => Object.prototype.hasOwnProperty.call(prevValue, key) &&
29
+ Object.is(value[key], prevValue[key]));
30
+ }
31
+ return false;
32
+ };
33
+ export const defaultCompare = (value, prevValue) => {
34
+ if (Array.isArray(value) && Array.isArray(prevValue)) {
35
+ return shallowCompare(value, prevValue);
36
+ }
37
+ return identityCompare(value, prevValue);
38
+ };
39
+ const getCompare = (compare) => {
40
+ if (compare === 'identity') {
41
+ return identityCompare;
42
+ }
43
+ if (compare === 'shallow') {
44
+ return shallowCompare;
45
+ }
46
+ return compare ?? defaultCompare;
47
+ };
48
+ const useStableWatchValue = (value, compare) => {
49
+ const valueRef = useRef(value);
50
+ if (!compare(value, valueRef.current)) {
51
+ valueRef.current = value;
52
+ }
53
+ return valueRef.current;
54
+ };
55
+ export function useWatch(source, selectorOrCallback, callbackOrOptions, options) {
56
+ const hasSelector = typeof callbackOrOptions === 'function';
57
+ const selector = hasSelector ? selectorOrCallback : null;
58
+ const callback = hasSelector
59
+ ? callbackOrOptions
60
+ : selectorOrCallback;
61
+ const watchOptions = hasSelector ? options : callbackOrOptions;
62
+ const nextValue = selector ? selector(source) : source;
63
+ const stableValue = useStableWatchValue(nextValue, getCompare(watchOptions?.compare));
64
+ const isInit = useRef(false);
65
+ const valueRef = useRef(stableValue);
66
+ const callbackRef = useRef(callback);
67
+ const optionsRef = useRef(watchOptions);
68
+ callbackRef.current = callback;
69
+ optionsRef.current = watchOptions;
70
+ useEffect(() => {
71
+ if (!isInit.current) {
72
+ isInit.current = true;
73
+ valueRef.current = stableValue;
74
+ if (optionsRef.current?.immediate) {
75
+ return callbackRef.current(stableValue, undefined);
76
+ }
77
+ return;
78
+ }
79
+ const prevValue = valueRef.current;
80
+ if (Object.is(stableValue, prevValue)) {
81
+ return;
82
+ }
83
+ valueRef.current = stableValue;
84
+ return callbackRef.current(stableValue, prevValue);
85
+ }, [stableValue]);
86
+ }
87
+ export default useWatch;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useWatch.test.d.ts.map