@zw-team/react-lib 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/README.md +207 -0
  2. package/dist/components/AccessReport/index.d.ts +29 -0
  3. package/dist/components/AccessReport/index.js +129 -0
  4. package/dist/components/Avatar/Avatar.d.ts +3 -0
  5. package/dist/components/Avatar/Avatar.js +58 -0
  6. package/dist/components/Avatar/index.d.ts +2 -0
  7. package/dist/components/Avatar/index.js +2 -0
  8. package/dist/components/Avatar/types.d.ts +9 -0
  9. package/dist/components/Avatar/types.js +0 -0
  10. package/dist/components/Block/Block.css +8 -0
  11. package/dist/components/Block/Block.d.ts +4 -0
  12. package/dist/components/Block/Block.js +11 -0
  13. package/dist/components/Block/index.d.ts +2 -0
  14. package/dist/components/Block/index.js +2 -0
  15. package/dist/components/Block/types.d.ts +3 -0
  16. package/dist/components/Block/types.js +0 -0
  17. package/dist/components/ConfigProvider/ConfigContext.d.ts +4 -0
  18. package/dist/components/ConfigProvider/ConfigContext.js +19 -0
  19. package/dist/components/ConfigProvider/ConfigProvider.d.ts +4 -0
  20. package/dist/components/ConfigProvider/ConfigProvider.js +57 -0
  21. package/dist/components/ConfigProvider/index.d.ts +2 -0
  22. package/dist/components/ConfigProvider/index.js +2 -0
  23. package/dist/components/ConfigProvider/types.d.ts +19 -0
  24. package/dist/components/ConfigProvider/types.js +0 -0
  25. package/dist/components/CustomColumn/CustomColumn.d.ts +4 -0
  26. package/dist/components/CustomColumn/CustomColumn.js +388 -0
  27. package/dist/components/CustomColumn/CustomColumn.scss +135 -0
  28. package/dist/components/CustomColumn/index.d.ts +2 -0
  29. package/dist/components/CustomColumn/index.js +2 -0
  30. package/dist/components/CustomColumn/types.d.ts +19 -0
  31. package/dist/components/CustomColumn/types.js +0 -0
  32. package/dist/components/DatePicker/DatePicker.d.ts +4 -0
  33. package/dist/components/DatePicker/DatePicker.js +89 -0
  34. package/dist/components/DatePicker/datePickerOption.d.ts +14 -0
  35. package/dist/components/DatePicker/datePickerOption.js +149 -0
  36. package/dist/components/DatePicker/index.d.ts +2 -0
  37. package/dist/components/DatePicker/index.js +2 -0
  38. package/dist/components/DatePicker/types.d.ts +12 -0
  39. package/dist/components/DatePicker/types.js +0 -0
  40. package/dist/components/DatePickerPanel/DatePickerPanel.d.ts +6 -0
  41. package/dist/components/DatePickerPanel/DatePickerPanel.js +397 -0
  42. package/dist/components/DatePickerPanel/datePickerPanel.scss +362 -0
  43. package/dist/components/DatePickerPanel/index.d.ts +2 -0
  44. package/dist/components/DatePickerPanel/index.js +2 -0
  45. package/dist/components/DatePickerPanel/type.d.ts +23 -0
  46. package/dist/components/DatePickerPanel/type.js +0 -0
  47. package/dist/components/DownloadCenter/DownloadCenter.d.ts +5 -0
  48. package/dist/components/DownloadCenter/DownloadCenter.js +367 -0
  49. package/dist/components/DownloadCenter/index.css +54 -0
  50. package/dist/components/DownloadCenter/index.d.ts +2 -0
  51. package/dist/components/DownloadCenter/index.js +2 -0
  52. package/dist/components/DownloadCenter/types.d.ts +27 -0
  53. package/dist/components/DownloadCenter/types.js +0 -0
  54. package/dist/components/Fireworks/Fireworks.d.ts +11 -0
  55. package/dist/components/Fireworks/Fireworks.js +415 -0
  56. package/dist/components/Fireworks/imgs/birthday-cake.svg +180 -0
  57. package/dist/components/Fireworks/imgs/hb.png +0 -0
  58. package/dist/components/Fireworks/imgs/sd.png +0 -0
  59. package/dist/components/Fireworks/imgs/xc.png +0 -0
  60. package/dist/components/Fireworks/imgs/yd.png +0 -0
  61. package/dist/components/Fireworks/index.d.ts +2 -0
  62. package/dist/components/Fireworks/index.js +2 -0
  63. package/dist/components/Fireworks/index.scss +9 -0
  64. package/dist/components/Fireworks/types.d.ts +6 -0
  65. package/dist/components/Fireworks/types.js +0 -0
  66. package/dist/components/Form/Form.css +4 -0
  67. package/dist/components/Form/Form.d.ts +9 -0
  68. package/dist/components/Form/Form.js +18 -0
  69. package/dist/components/Form/index.d.ts +1 -0
  70. package/dist/components/Form/index.js +2 -0
  71. package/dist/components/FormItem/FormItem.css +38 -0
  72. package/dist/components/FormItem/FormItem.d.ts +9 -0
  73. package/dist/components/FormItem/FormItem.js +25 -0
  74. package/dist/components/FormItem/index.d.ts +1 -0
  75. package/dist/components/FormItem/index.js +2 -0
  76. package/dist/components/HomeData/HomeData.d.ts +6 -0
  77. package/dist/components/HomeData/HomeData.js +364 -0
  78. package/dist/components/HomeData/HomeData.scss +161 -0
  79. package/dist/components/HomeData/index.d.ts +1 -0
  80. package/dist/components/HomeData/index.js +2 -0
  81. package/dist/components/Icon/Icon.d.ts +4 -0
  82. package/dist/components/Icon/Icon.js +34 -0
  83. package/dist/components/Icon/index.d.ts +2 -0
  84. package/dist/components/Icon/index.js +2 -0
  85. package/dist/components/Icon/types.d.ts +8 -0
  86. package/dist/components/Icon/types.js +0 -0
  87. package/dist/components/Log/index.d.ts +2 -0
  88. package/dist/components/Log/index.js +2 -0
  89. package/dist/components/Log/src/Detail.d.ts +7 -0
  90. package/dist/components/Log/src/Detail.js +71 -0
  91. package/dist/components/Log/src/Detail.scss +27 -0
  92. package/dist/components/Log/src/Log.d.ts +5 -0
  93. package/dist/components/Log/src/Log.js +335 -0
  94. package/dist/components/Log/src/Log.scss +50 -0
  95. package/dist/components/Log/src/useLogTableColumns.d.ts +2 -0
  96. package/dist/components/Log/src/useLogTableColumns.js +141 -0
  97. package/dist/components/Log/types.d.ts +5 -0
  98. package/dist/components/Log/types.js +0 -0
  99. package/dist/components/LogButton/LogButton.d.ts +4 -0
  100. package/dist/components/LogButton/LogButton.js +30 -0
  101. package/dist/components/LogButton/index.d.ts +2 -0
  102. package/dist/components/LogButton/index.js +2 -0
  103. package/dist/components/LogButton/logbutton.css +15 -0
  104. package/dist/components/LogButton/types.d.ts +10 -0
  105. package/dist/components/LogButton/types.js +0 -0
  106. package/dist/components/LogDialog/BiLogManager.d.ts +29 -0
  107. package/dist/components/LogDialog/BiLogManager.js +78 -0
  108. package/dist/components/LogDialog/LogDialog.d.ts +8 -0
  109. package/dist/components/LogDialog/LogDialog.js +106 -0
  110. package/dist/components/LogDialog/LogDialog.scss +29 -0
  111. package/dist/components/LogDialog/index.d.ts +3 -0
  112. package/dist/components/LogDialog/index.js +3 -0
  113. package/dist/components/LogDialog/types.d.ts +8 -0
  114. package/dist/components/LogDialog/types.js +0 -0
  115. package/dist/components/MediaPreview/MediaPreview.d.ts +5 -0
  116. package/dist/components/MediaPreview/MediaPreview.js +124 -0
  117. package/dist/components/MediaPreview/hook.d.ts +26 -0
  118. package/dist/components/MediaPreview/hook.js +174 -0
  119. package/dist/components/MediaPreview/index.css +202 -0
  120. package/dist/components/MediaPreview/index.d.ts +2 -0
  121. package/dist/components/MediaPreview/index.js +2 -0
  122. package/dist/components/MediaPreview/types.d.ts +24 -0
  123. package/dist/components/MediaPreview/types.js +0 -0
  124. package/dist/components/Modal/Modal.d.ts +3 -0
  125. package/dist/components/Modal/Modal.js +31 -0
  126. package/dist/components/Modal/index.d.ts +2 -0
  127. package/dist/components/Modal/index.js +2 -0
  128. package/dist/components/Modal/types.d.ts +8 -0
  129. package/dist/components/Modal/types.js +0 -0
  130. package/dist/components/ModalStore/ModalProvider.d.ts +11 -0
  131. package/dist/components/ModalStore/ModalProvider.js +15 -0
  132. package/dist/components/ModalStore/ModalStore.d.ts +78 -0
  133. package/dist/components/ModalStore/ModalStore.js +188 -0
  134. package/dist/components/ModalStore/index.d.ts +3 -0
  135. package/dist/components/ModalStore/index.js +4 -0
  136. package/dist/components/ModalStore/types.d.ts +73 -0
  137. package/dist/components/ModalStore/types.js +0 -0
  138. package/dist/components/MoreButton/MoreButton.d.ts +3 -0
  139. package/dist/components/MoreButton/MoreButton.js +50 -0
  140. package/dist/components/MoreButton/index.d.ts +2 -0
  141. package/dist/components/MoreButton/index.js +2 -0
  142. package/dist/components/MoreButton/types.d.ts +15 -0
  143. package/dist/components/MoreButton/types.js +0 -0
  144. package/dist/components/NavbarTool/NavbarTool.d.ts +5 -0
  145. package/dist/components/NavbarTool/NavbarTool.js +143 -0
  146. package/dist/components/NavbarTool/components/index.css +49 -0
  147. package/dist/components/NavbarTool/components/index.d.ts +5 -0
  148. package/dist/components/NavbarTool/components/index.js +98 -0
  149. package/dist/components/NavbarTool/index.css +14 -0
  150. package/dist/components/NavbarTool/index.d.ts +2 -0
  151. package/dist/components/NavbarTool/index.js +2 -0
  152. package/dist/components/NavbarTool/types.d.ts +40 -0
  153. package/dist/components/NavbarTool/types.js +0 -0
  154. package/dist/components/NoticeCenter/NoticeCenter.d.ts +4 -0
  155. package/dist/components/NoticeCenter/NoticeCenter.js +334 -0
  156. package/dist/components/NoticeCenter/assets/notice.png +0 -0
  157. package/dist/components/NoticeCenter/assets/tongzhi.png +0 -0
  158. package/dist/components/NoticeCenter/index.d.ts +2 -0
  159. package/dist/components/NoticeCenter/index.js +2 -0
  160. package/dist/components/NoticeCenter/noticeCenter.scss +232 -0
  161. package/dist/components/NoticeCenter/types.d.ts +6 -0
  162. package/dist/components/NoticeCenter/types.js +0 -0
  163. package/dist/components/Pagination/BiPagination.css +152 -0
  164. package/dist/components/Pagination/Pagination.d.ts +5 -0
  165. package/dist/components/Pagination/Pagination.js +67 -0
  166. package/dist/components/Pagination/index.d.ts +2 -0
  167. package/dist/components/Pagination/index.js +2 -0
  168. package/dist/components/Pagination/types.d.ts +14 -0
  169. package/dist/components/Pagination/types.js +0 -0
  170. package/dist/components/ResponseInterceptor/index.d.ts +17 -0
  171. package/dist/components/ResponseInterceptor/index.js +43 -0
  172. package/dist/components/SuperDate/SuperDate.d.ts +6 -0
  173. package/dist/components/SuperDate/SuperDate.js +113 -0
  174. package/dist/components/SuperDate/SuperDate.scss +42 -0
  175. package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.d.ts +5 -0
  176. package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.js +87 -0
  177. package/dist/components/SuperDate/components/CustomRangPanel/CustomRangPanel.scss +52 -0
  178. package/dist/components/SuperDate/components/DynamicTimeCom/DynamicTimeCom.d.ts +6 -0
  179. package/dist/components/SuperDate/components/DynamicTimeCom/DynamicTimeCom.js +129 -0
  180. package/dist/components/SuperDate/components/DynamicTimeCom/dynamicTimeCom.scss +70 -0
  181. package/dist/components/SuperDate/constant.d.ts +35 -0
  182. package/dist/components/SuperDate/constant.js +27 -0
  183. package/dist/components/SuperDate/index.d.ts +2 -0
  184. package/dist/components/SuperDate/index.js +2 -0
  185. package/dist/components/SuperDate/store.d.ts +68 -0
  186. package/dist/components/SuperDate/store.js +254 -0
  187. package/dist/components/SuperDate/types.d.ts +34 -0
  188. package/dist/components/SuperDate/types.js +0 -0
  189. package/dist/components/SuperDate/utils.d.ts +18 -0
  190. package/dist/components/SuperDate/utils.js +14 -0
  191. package/dist/components/SystemLink/SystemLink.d.ts +4 -0
  192. package/dist/components/SystemLink/SystemLink.js +85 -0
  193. package/dist/components/SystemLink/index.d.ts +1 -0
  194. package/dist/components/SystemLink/index.js +2 -0
  195. package/dist/components/SystemLink/index.scss +142 -0
  196. package/dist/components/Table/ResizableTitle.d.ts +3 -0
  197. package/dist/components/Table/ResizableTitle.js +43 -0
  198. package/dist/components/Table/Table.d.ts +9 -0
  199. package/dist/components/Table/Table.js +189 -0
  200. package/dist/components/Table/index.d.ts +2 -0
  201. package/dist/components/Table/index.js +2 -0
  202. package/dist/components/Table/index.scss +42 -0
  203. package/dist/components/Table/types.d.ts +24 -0
  204. package/dist/components/Table/types.js +0 -0
  205. package/dist/components/Table/useHeaderPopper.d.ts +8 -0
  206. package/dist/components/Table/useHeaderPopper.js +95 -0
  207. package/dist/components/TableHeaderPopper/EditBox.d.ts +6 -0
  208. package/dist/components/TableHeaderPopper/EditBox.js +208 -0
  209. package/dist/components/TableHeaderPopper/Popover.d.ts +6 -0
  210. package/dist/components/TableHeaderPopper/Popover.js +85 -0
  211. package/dist/components/TableHeaderPopper/index.d.ts +3 -0
  212. package/dist/components/TableHeaderPopper/index.js +3 -0
  213. package/dist/components/TableHeaderPopper/index.scss +96 -0
  214. package/dist/components/TaskCenter/TaskCenter.d.ts +4 -0
  215. package/dist/components/TaskCenter/TaskCenter.js +257 -0
  216. package/dist/components/TaskCenter/TaskCenter.scss +44 -0
  217. package/dist/components/TaskCenter/api.d.ts +13 -0
  218. package/dist/components/TaskCenter/api.js +13 -0
  219. package/dist/components/TaskCenter/index.d.ts +2 -0
  220. package/dist/components/TaskCenter/index.js +2 -0
  221. package/dist/components/TaskCenter/types.d.ts +29 -0
  222. package/dist/components/TaskCenter/types.js +0 -0
  223. package/dist/components/TooltipIcon/TooltipIcon.d.ts +3 -0
  224. package/dist/components/TooltipIcon/TooltipIcon.js +43 -0
  225. package/dist/components/TooltipIcon/index.d.ts +2 -0
  226. package/dist/components/TooltipIcon/index.js +2 -0
  227. package/dist/components/TooltipIcon/types.d.ts +14 -0
  228. package/dist/components/TooltipIcon/types.js +0 -0
  229. package/dist/components/Verification/content.d.ts +11 -0
  230. package/dist/components/Verification/content.js +223 -0
  231. package/dist/components/Verification/index.css +43 -0
  232. package/dist/components/Verification/index.d.ts +1 -0
  233. package/dist/components/Verification/index.js +37 -0
  234. package/dist/components/index.d.ts +32 -0
  235. package/dist/components/index.js +29 -0
  236. package/dist/config/index.d.ts +83 -0
  237. package/dist/config/index.js +115 -0
  238. package/dist/config/theme/index.d.ts +368 -0
  239. package/dist/config/theme/index.js +369 -0
  240. package/dist/hooks/createAlive.d.ts +11 -0
  241. package/dist/hooks/createAlive.js +22 -0
  242. package/dist/hooks/createGlobalState.d.ts +7 -0
  243. package/dist/hooks/createGlobalState.js +28 -0
  244. package/dist/hooks/index.d.ts +26 -0
  245. package/dist/hooks/index.js +25 -0
  246. package/dist/hooks/useAsync.d.ts +27 -0
  247. package/dist/hooks/useAsync.js +76 -0
  248. package/dist/hooks/useClickOther.d.ts +10 -0
  249. package/dist/hooks/useClickOther.js +30 -0
  250. package/dist/hooks/useCopyToClipboard.d.ts +7 -0
  251. package/dist/hooks/useCopyToClipboard.js +32 -0
  252. package/dist/hooks/useCreate.d.ts +7 -0
  253. package/dist/hooks/useCreate.js +21 -0
  254. package/dist/hooks/useEventListener.d.ts +22 -0
  255. package/dist/hooks/useEventListener.js +33 -0
  256. package/dist/hooks/useHistoryStore.d.ts +16 -0
  257. package/dist/hooks/useHistoryStore.js +106 -0
  258. package/dist/hooks/useIntersectionObserver.d.ts +8 -0
  259. package/dist/hooks/useIntersectionObserver.js +23 -0
  260. package/dist/hooks/useInterval.d.ts +8 -0
  261. package/dist/hooks/useInterval.js +19 -0
  262. package/dist/hooks/useLatest.d.ts +2 -0
  263. package/dist/hooks/useLatest.js +12 -0
  264. package/dist/hooks/useLockAsyncFn.d.ts +7 -0
  265. package/dist/hooks/useLockAsyncFn.js +24 -0
  266. package/dist/hooks/useLockFn.d.ts +7 -0
  267. package/dist/hooks/useLockFn.js +17 -0
  268. package/dist/hooks/useMergedState.d.ts +10 -0
  269. package/dist/hooks/useMergedState.js +30 -0
  270. package/dist/hooks/useMountedState.d.ts +4 -0
  271. package/dist/hooks/useMountedState.js +13 -0
  272. package/dist/hooks/usePermission.d.ts +8 -0
  273. package/dist/hooks/usePermission.js +21 -0
  274. package/dist/hooks/usePersistFn.d.ts +8 -0
  275. package/dist/hooks/usePersistFn.js +13 -0
  276. package/dist/hooks/useReactive.d.ts +7 -0
  277. package/dist/hooks/useReactive.js +34 -0
  278. package/dist/hooks/useRefresh.d.ts +5 -0
  279. package/dist/hooks/useRefresh.js +8 -0
  280. package/dist/hooks/useToggle.d.ts +16 -0
  281. package/dist/hooks/useToggle.js +20 -0
  282. package/dist/hooks/useUnmount.d.ts +6 -0
  283. package/dist/hooks/useUnmount.js +10 -0
  284. package/dist/hooks/useUpdateEffect.d.ts +9 -0
  285. package/dist/hooks/useUpdateEffect.js +10 -0
  286. package/dist/hooks/useWindowSize.d.ts +6 -0
  287. package/dist/hooks/useWindowSize.js +15 -0
  288. package/dist/hooks/util.d.ts +9 -0
  289. package/dist/hooks/util.js +6 -0
  290. package/dist/index.d.ts +5 -0
  291. package/dist/index.js +2 -0
  292. package/dist/utils/array.d.ts +12 -0
  293. package/dist/utils/array.js +15 -0
  294. package/dist/utils/classNames.d.ts +4 -0
  295. package/dist/utils/classNames.js +19 -0
  296. package/dist/utils/date.d.ts +98 -0
  297. package/dist/utils/date.js +101 -0
  298. package/dist/utils/debounce.d.ts +8 -0
  299. package/dist/utils/debounce.js +38 -0
  300. package/dist/utils/deepClone.d.ts +6 -0
  301. package/dist/utils/deepClone.js +10 -0
  302. package/dist/utils/empty.d.ts +16 -0
  303. package/dist/utils/empty.js +24 -0
  304. package/dist/utils/formatPrice.d.ts +2 -0
  305. package/dist/utils/formatPrice.js +15 -0
  306. package/dist/utils/getUUID.d.ts +1 -0
  307. package/dist/utils/getUUID.js +17 -0
  308. package/dist/utils/getUrlParams.d.ts +11 -0
  309. package/dist/utils/getUrlParams.js +10 -0
  310. package/dist/utils/index.d.ts +20 -0
  311. package/dist/utils/index.js +19 -0
  312. package/dist/utils/listToTree.d.ts +12 -0
  313. package/dist/utils/listToTree.js +14 -0
  314. package/dist/utils/object.d.ts +6 -0
  315. package/dist/utils/object.js +5 -0
  316. package/dist/utils/ossUpload.d.ts +45 -0
  317. package/dist/utils/ossUpload.js +88 -0
  318. package/dist/utils/parseTo.d.ts +6 -0
  319. package/dist/utils/parseTo.js +9 -0
  320. package/dist/utils/request/accessReport.d.ts +2 -0
  321. package/dist/utils/request/accessReport.js +27 -0
  322. package/dist/utils/request/defaultRequest.d.ts +9 -0
  323. package/dist/utils/request/defaultRequest.js +33 -0
  324. package/dist/utils/request/exportDownload.d.ts +2 -0
  325. package/dist/utils/request/exportDownload.js +28 -0
  326. package/dist/utils/request/index.d.ts +29 -0
  327. package/dist/utils/request/index.js +40 -0
  328. package/dist/utils/request/noticeCenter.d.ts +2 -0
  329. package/dist/utils/request/noticeCenter.js +28 -0
  330. package/dist/utils/svgIcon/index.d.ts +47 -0
  331. package/dist/utils/svgIcon/index.js +76 -0
  332. package/dist/utils/throttle.d.ts +10 -0
  333. package/dist/utils/throttle.js +21 -0
  334. package/dist/utils/time/index.d.ts +7 -0
  335. package/dist/utils/time/index.js +12 -0
  336. package/dist/utils/tools.d.ts +43 -0
  337. package/dist/utils/tools.js +57 -0
  338. package/package.json +116 -0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 创建引用不会变的常量
3
+ * @param factory 工厂函数
4
+ * @param deps 依赖项
5
+ */
6
+ declare const useCreate: <T>(factory: () => T, deps: any[]) => T;
7
+ export default useCreate;
@@ -0,0 +1,21 @@
1
+ import { useRef } from "react";
2
+ const useCreate_useCreate = (factory, deps)=>{
3
+ const { current } = useRef({
4
+ deps,
5
+ obj: void 0,
6
+ initialized: false
7
+ });
8
+ if (false === current.initialized || !depsAreSame(current.deps, deps)) {
9
+ current.deps = deps;
10
+ current.obj = factory();
11
+ current.initialized = true;
12
+ }
13
+ return current.obj;
14
+ };
15
+ function depsAreSame(oldDeps, deps) {
16
+ if (oldDeps === deps) return true;
17
+ for(const i in oldDeps)if (oldDeps[i] !== deps[i]) return false;
18
+ return true;
19
+ }
20
+ const useCreate = useCreate_useCreate;
21
+ export { useCreate as default };
@@ -0,0 +1,22 @@
1
+ import { type MutableRefObject } from 'react';
2
+ type Target = HTMLElement | Window;
3
+ type Dom = Target | (() => Target) | null;
4
+ /**
5
+ * 在 DOM 节点或 `window` 上注册原生事件,组件卸载时移除监听;内部用 ref 保存最新 `handler`。
6
+ *
7
+ * @param eventName - 事件类型,如 `click`、`keydown`
8
+ * @param handler - 监听回调
9
+ * @param options - 可选:`dom` 为监听目标(元素、返回元素的函数或 `null`);不传 `dom` 时用返回的 `ref` 对应节点,无节点时监听 `window`。`capture` / `once` / `passive` 含义同 `addEventListener`。
10
+ */
11
+ declare function useEventListener<T extends Target = HTMLElement>(eventName: string, handler: Function, options?: {
12
+ capture?: boolean;
13
+ once?: boolean;
14
+ passive?: boolean;
15
+ }): MutableRefObject<T>;
16
+ declare function useEventListener<T extends Target = HTMLElement>(eventName: string, handler: Function, options?: {
17
+ dom: Dom;
18
+ capture?: boolean;
19
+ once?: boolean;
20
+ passive?: boolean;
21
+ }): void;
22
+ export default useEventListener;
@@ -0,0 +1,33 @@
1
+ import { useEffect, useRef } from "react";
2
+ function useEventListener_useEventListener(eventName, handler, options) {
3
+ const ref = useRef(null);
4
+ const savedHandler = useRef(null);
5
+ useEffect(()=>{
6
+ savedHandler.current = handler;
7
+ }, [
8
+ handler
9
+ ]);
10
+ useEffect(()=>{
11
+ const passedInElement = options && ('function' == typeof options.dom ? options.dom() : options.dom);
12
+ const element = passedInElement ? passedInElement : ref.current || window;
13
+ const isSupported = element.addEventListener;
14
+ if (!isSupported) return;
15
+ const eventListener = (event)=>savedHandler.current && savedHandler.current(event);
16
+ element.addEventListener(eventName, eventListener, {
17
+ capture: options?.capture,
18
+ once: options?.once,
19
+ passive: options?.passive
20
+ });
21
+ return ()=>{
22
+ element.removeEventListener(eventName, eventListener, {
23
+ capture: options?.capture
24
+ });
25
+ };
26
+ }, [
27
+ eventName,
28
+ options
29
+ ]);
30
+ return ref;
31
+ }
32
+ const useEventListener = useEventListener_useEventListener;
33
+ export { useEventListener as default };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 用于管理历史状态,包含撤销,重做等功能
3
+ * 用 past / present / future 三段栈管理状态,支持撤销、重做、写入新状态并重置。
4
+ *
5
+ * @param initialValue - `present` 的初始值
6
+ */
7
+ declare const useHistoryStore: <T>(initialValue: T) => {
8
+ state: T;
9
+ canUndo: boolean;
10
+ canRedo: boolean;
11
+ setState: (newPresent: T) => void;
12
+ undo: () => void;
13
+ redo: () => void;
14
+ reset: () => void;
15
+ };
16
+ export default useHistoryStore;
@@ -0,0 +1,106 @@
1
+ import { useCallback, useReducer } from "react";
2
+ const initialState = {
3
+ past: [],
4
+ present: null,
5
+ future: []
6
+ };
7
+ const reducer = (state, action)=>{
8
+ const { past, present, future } = state;
9
+ switch(action.type){
10
+ case 'UNDO':
11
+ {
12
+ const previous = past[past.length - 1];
13
+ const newPast = past.slice(0, past.length - 1);
14
+ return {
15
+ past: newPast,
16
+ present: previous,
17
+ future: [
18
+ present,
19
+ ...future
20
+ ]
21
+ };
22
+ }
23
+ case 'REDO':
24
+ {
25
+ const next = future[0];
26
+ const newFuture = future.slice(1);
27
+ return {
28
+ past: [
29
+ ...past,
30
+ present
31
+ ],
32
+ present: next,
33
+ future: newFuture
34
+ };
35
+ }
36
+ case 'SET':
37
+ {
38
+ const { newPresent } = action;
39
+ if (newPresent === present) return state;
40
+ return {
41
+ past: [
42
+ ...past,
43
+ present
44
+ ],
45
+ present: newPresent,
46
+ future: []
47
+ };
48
+ }
49
+ case 'RESET':
50
+ {
51
+ const { initialValue } = action;
52
+ return {
53
+ ...initialState,
54
+ present: initialValue
55
+ };
56
+ }
57
+ default:
58
+ break;
59
+ }
60
+ };
61
+ const useHistoryStore_useHistoryStore = (initialValue)=>{
62
+ const [state, dispatch] = useReducer(reducer, {
63
+ ...initialState,
64
+ present: initialValue
65
+ });
66
+ const present = state.present;
67
+ const canUndo = 0 !== state.past.length;
68
+ const canRedo = 0 !== state.future.length;
69
+ const undo = useCallback(()=>{
70
+ if (canUndo) dispatch({
71
+ type: 'UNDO'
72
+ });
73
+ }, [
74
+ canUndo,
75
+ dispatch
76
+ ]);
77
+ const redo = useCallback(()=>{
78
+ if (canRedo) dispatch({
79
+ type: 'REDO'
80
+ });
81
+ }, [
82
+ canRedo,
83
+ dispatch
84
+ ]);
85
+ const setState = useCallback((newPresent)=>dispatch({
86
+ type: 'SET',
87
+ newPresent
88
+ }), []);
89
+ const reset = useCallback(()=>dispatch({
90
+ type: 'RESET',
91
+ initialValue
92
+ }), [
93
+ initialValue
94
+ ]);
95
+ return {
96
+ state: present,
97
+ canUndo,
98
+ canRedo,
99
+ setState,
100
+ undo,
101
+ redo,
102
+ reset
103
+ };
104
+ };
105
+ const useHistoryStore = useHistoryStore_useHistoryStore;
106
+ export { useHistoryStore as default };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 为一组节点创建 `IntersectionObserver`,用于在元素与视口相交时执行回调(如懒加载)。
3
+ *
4
+ * @param domList - 需要被观察的 DOM 节点列表
5
+ * @param deps - 传给观察器选项的 `threshold`,默认 `[0]`
6
+ */
7
+ declare const useIntersectionObserver: (domList: HTMLImageElement[], deps?: number[]) => void;
8
+ export default useIntersectionObserver;
@@ -0,0 +1,23 @@
1
+ import { useEffect, useRef } from "react";
2
+ const useIntersectionObserver_useIntersectionObserver = (domList, deps = [
3
+ 0
4
+ ])=>{
5
+ const ioRef = useRef(null);
6
+ useEffect(()=>{
7
+ ioRef.current = new IntersectionObserver((entries)=>{
8
+ entries.forEach((item)=>{
9
+ if (item.intersectionRatio <= 0) return;
10
+ const { target } = item;
11
+ if (target.src) target.dataset.src;
12
+ });
13
+ }, {
14
+ threshold: deps
15
+ });
16
+ domList.forEach((item)=>ioRef.current.observe(item));
17
+ return ()=>{
18
+ ioRef.current.disconnect();
19
+ };
20
+ }, []);
21
+ };
22
+ const useIntersectionObserver = useIntersectionObserver_useIntersectionObserver;
23
+ export { useIntersectionObserver as default };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 按固定间隔重复执行 `callback`,卸载或 `delay` 变化时会清理旧定时器;`callback` 始终取最新引用。
3
+ *
4
+ * @param callback - 每个周期调用的函数
5
+ * @param delay - 间隔毫秒数;`null` / `undefined` 时不创建定时器
6
+ */
7
+ declare const useInterval: (callback: Function, delay?: number | null) => void;
8
+ export default useInterval;
@@ -0,0 +1,19 @@
1
+ import { useEffect, useRef } from "react";
2
+ const useInterval_useInterval = (callback, delay)=>{
3
+ const savedCallback = useRef(()=>{});
4
+ useEffect(()=>{
5
+ savedCallback.current = callback;
6
+ });
7
+ useEffect(()=>{
8
+ if (delay) {
9
+ const interval = setInterval(()=>savedCallback.current(), delay || 0);
10
+ return ()=>{
11
+ clearInterval(interval);
12
+ };
13
+ }
14
+ }, [
15
+ delay
16
+ ]);
17
+ };
18
+ const useInterval = useInterval_useInterval;
19
+ export { useInterval as default };
@@ -0,0 +1,2 @@
1
+ declare const useLatest: (value: any) => import("react").RefObject<any>;
2
+ export default useLatest;
@@ -0,0 +1,12 @@
1
+ import { useEffect, useRef } from "react";
2
+ const useLatest = (value)=>{
3
+ const ref = useRef(value);
4
+ useEffect(()=>{
5
+ ref.current = value;
6
+ }, [
7
+ value
8
+ ]);
9
+ return ref;
10
+ };
11
+ const hooks_useLatest = useLatest;
12
+ export { hooks_useLatest as default };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 异步函数竞态锁(同一时间只能触发一次)
3
+ * @param fn 异步函数
4
+ * @param lockTime 额外追加的锁定时间
5
+ */
6
+ declare function useLockFn<P extends any[] = any[], V = any>(fn: (...args: P) => Promise<V>, lockTime?: number): (...args: P) => Promise<V | undefined>;
7
+ export default useLockFn;
@@ -0,0 +1,24 @@
1
+ import { useCallback, useRef } from "react";
2
+ function useLockFn(fn, lockTime) {
3
+ const lockRef = useRef(false);
4
+ return useCallback(async (...args)=>{
5
+ if (lockRef.current) return;
6
+ lockRef.current = true;
7
+ try {
8
+ const ret = await fn(...args);
9
+ if (lockTime) setTimeout(()=>{
10
+ lockRef.current = false;
11
+ }, lockTime);
12
+ else lockRef.current = false;
13
+ return ret;
14
+ } catch (e) {
15
+ lockRef.current = false;
16
+ throw e;
17
+ }
18
+ }, [
19
+ lockTime,
20
+ fn
21
+ ]);
22
+ }
23
+ const useLockAsyncFn = useLockFn;
24
+ export { useLockAsyncFn as default };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 同步函数竞态锁
3
+ * @param fn 要控制的函数
4
+ * @param lockTime 锁定时间
5
+ */
6
+ declare function useLockFn<P extends any[] = any[]>(fn: (...args: P) => any, lockTime?: number): (...args: P) => void;
7
+ export default useLockFn;
@@ -0,0 +1,17 @@
1
+ import { useCallback, useRef } from "react";
2
+ function useLockFn_useLockFn(fn, lockTime = 600) {
3
+ const lockRef = useRef(false);
4
+ return useCallback((...args)=>{
5
+ if (lockRef.current) return;
6
+ lockRef.current = true;
7
+ fn(...args);
8
+ setTimeout(()=>{
9
+ lockRef.current = false;
10
+ }, lockTime);
11
+ }, [
12
+ lockTime,
13
+ fn
14
+ ]);
15
+ }
16
+ const useLockFn = useLockFn_useLockFn;
17
+ export { useLockFn as default };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 合并受控与非受控:传入 `value` 时以外部为准,否则用内部 state;`defaultValue` 仅作初始值。
3
+ *
4
+ * @param option - `value` 受控值;`defaultValue` 非受控初始值(可为懒函数);`onChange` 在值变化时调用,参数为 `(新值, 旧值)`
5
+ */
6
+ export default function useMergedState<T, R = T>(option?: {
7
+ value?: T;
8
+ defaultValue?: T | (() => T);
9
+ onChange?: (value: T, prevValue: T) => void;
10
+ }): [R, (value: T, ignoreDestroy?: boolean) => void];
@@ -0,0 +1,30 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ function useMergedState(option) {
3
+ const { value, defaultValue, onChange } = option || {};
4
+ const [innerValue, setInnerValue] = useState(()=>{
5
+ if (void 0 !== value) return value;
6
+ if (void 0 !== defaultValue) return 'function' == typeof defaultValue ? defaultValue() : defaultValue;
7
+ });
8
+ const mergedValue = void 0 !== value ? value : innerValue;
9
+ const onChangeRef = useRef(onChange);
10
+ const prevValueRef = useRef(value);
11
+ onChangeRef.current = onChange;
12
+ useEffect(()=>{
13
+ if (void 0 === value && value !== prevValueRef.current) setInnerValue(value);
14
+ prevValueRef.current = value;
15
+ }, [
16
+ value
17
+ ]);
18
+ const handleChange = useCallback((newValue)=>{
19
+ setInnerValue(newValue);
20
+ if (mergedValue !== newValue && onChangeRef.current) onChangeRef.current(newValue, mergedValue);
21
+ }, [
22
+ mergedValue,
23
+ onChangeRef
24
+ ]);
25
+ return [
26
+ mergedValue,
27
+ handleChange
28
+ ];
29
+ }
30
+ export { useMergedState as default };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 检测当前组件是否已经挂载
3
+ */
4
+ export default function useMountedState(): () => boolean;
@@ -0,0 +1,13 @@
1
+ import { useCallback, useEffect, useRef } from "react";
2
+ function useMountedState() {
3
+ const mountedRef = useRef(false);
4
+ const get = useCallback(()=>mountedRef.current, []);
5
+ useEffect(()=>{
6
+ mountedRef.current = true;
7
+ return ()=>{
8
+ mountedRef.current = false;
9
+ };
10
+ });
11
+ return get;
12
+ }
13
+ export { useMountedState as default };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 检查用户是否有指定权限
3
+ * @param buttonInfo 权限信息(字符串数组或单个权限字符串)
4
+ * @param userPermission 用户权限(字符串,支持多种格式)
5
+ * @returns 用户是否拥有指定权限
6
+ */
7
+ declare const usePermission: (buttonInfo: string[] | string | any[], userPermission: string) => boolean;
8
+ export default usePermission;
@@ -0,0 +1,21 @@
1
+ const usePermission_usePermission = (buttonInfo, userPermission)=>{
2
+ let hasPermission = false;
3
+ const normalizePermission = (permission)=>{
4
+ if (permission.startsWith('/')) permission = permission.slice(1);
5
+ return permission.replace(/\//g, '-');
6
+ };
7
+ const normalizedUserPermission = normalizePermission(userPermission);
8
+ if (Array.isArray(buttonInfo)) buttonInfo.forEach((permission)=>{
9
+ if (!hasPermission) {
10
+ const normalizedPermission = normalizePermission(String(permission));
11
+ hasPermission = normalizedUserPermission === normalizedPermission;
12
+ }
13
+ });
14
+ else if ('string' == typeof buttonInfo) {
15
+ const normalizedPermission = normalizePermission(buttonInfo);
16
+ hasPermission = normalizedUserPermission === normalizedPermission;
17
+ } else if ('object' == typeof userPermission) hasPermission = !!Object.hasOwn(buttonInfo, userPermission);
18
+ return hasPermission;
19
+ };
20
+ const usePermission = usePermission_usePermission;
21
+ export { usePermission as default };
@@ -0,0 +1,8 @@
1
+ export type noop = (...args: any[]) => any;
2
+ /**
3
+ * 返回引用稳定的包装函数,依赖列表里可安全省略;内部始终调用传入的最新 `fn`。
4
+ *
5
+ * @param fn - 被包装的函数,每次渲染会更新其实现,但返回的函数引用不变
6
+ */
7
+ declare function usePersistFn<T extends noop>(fn: T): T;
8
+ export default usePersistFn;
@@ -0,0 +1,13 @@
1
+ import { useCallback, useRef } from "react";
2
+ function usePersistFn(fn) {
3
+ const ref = useRef(()=>{
4
+ throw new Error('Cannot call function while rendering.');
5
+ });
6
+ ref.current = fn;
7
+ const persistFn = useCallback((...args)=>ref.current(...args), [
8
+ ref
9
+ ]);
10
+ return persistFn;
11
+ }
12
+ const hooks_usePersistFn = usePersistFn;
13
+ export { hooks_usePersistFn as default };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 用 Proxy 包装对象,属性变更时触发重渲染;返回的代理引用在同一组件多次渲染间不变。
3
+ *
4
+ * @param initialState - 初始状态对象(仅首次渲染用于 `useRef` 初值)
5
+ */
6
+ declare const useReactive: <S extends object>(initialState: S) => S;
7
+ export default useReactive;
@@ -0,0 +1,34 @@
1
+ import { useRef, useState } from "react";
2
+ import useCreate from "./useCreate.js";
3
+ import { isObject } from "./util.js";
4
+ const proxyMap = new WeakMap();
5
+ const rawMap = new WeakMap();
6
+ const observer = (initialVal, callback)=>{
7
+ const existingProxy = proxyMap.get(initialVal);
8
+ if (existingProxy) return existingProxy;
9
+ if (rawMap.has(initialVal)) return initialVal;
10
+ const proxy = new Proxy(initialVal, {
11
+ get (target, key, receiver) {
12
+ const res = Reflect.get(target, key, receiver);
13
+ return isObject(res) ? observer(res, callback) : Reflect.get(target, key);
14
+ },
15
+ set (target, key, val) {
16
+ const ret = Reflect.set(target, key, val);
17
+ callback();
18
+ return ret;
19
+ }
20
+ });
21
+ proxyMap.set(initialVal, proxy);
22
+ rawMap.set(proxy, initialVal);
23
+ return proxy;
24
+ };
25
+ const useReactive_useReactive = (initialState)=>{
26
+ const [, setFlag] = useState({});
27
+ const stateRef = useRef(initialState);
28
+ const state = useCreate(()=>observer(stateRef.current, ()=>{
29
+ setFlag({});
30
+ }), []);
31
+ return state;
32
+ };
33
+ const useReactive = useReactive_useReactive;
34
+ export { useReactive as default };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 更新当前组件
3
+ */
4
+ declare const useRefresh: () => () => void;
5
+ export default useRefresh;
@@ -0,0 +1,8 @@
1
+ import { useCallback, useState } from "react";
2
+ const useRefresh = ()=>{
3
+ const [, setState] = useState({});
4
+ const refresh = useCallback(()=>setState({}), []);
5
+ return refresh;
6
+ };
7
+ const hooks_useRefresh = useRefresh;
8
+ export { hooks_useRefresh as default };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 用 boolean 管理显隐,提供 `show` / `hide` / `toggle` 以及含 `visible`、`onCancel` 的 `props`(便于对接弹层等)。
3
+ *
4
+ * @param defaultVisible - 初始是否可见,默认 `false`
5
+ */
6
+ declare const useToggle: (defaultVisible?: boolean) => {
7
+ visible: boolean;
8
+ props: {
9
+ visible: boolean;
10
+ onCancel: () => void;
11
+ };
12
+ show: () => void;
13
+ hide: () => void;
14
+ toggle: () => void;
15
+ };
16
+ export default useToggle;
@@ -0,0 +1,20 @@
1
+ import { useCallback, useState } from "react";
2
+ const useToggle = (defaultVisible = false)=>{
3
+ const [visible, setVisible] = useState(defaultVisible);
4
+ const show = useCallback(()=>setVisible(true), []);
5
+ const hide = useCallback(()=>setVisible(false), []);
6
+ const toggle = useCallback(()=>setVisible((visible)=>!visible), []);
7
+ const props = {
8
+ visible,
9
+ onCancel: hide
10
+ };
11
+ return {
12
+ visible,
13
+ props,
14
+ show,
15
+ hide,
16
+ toggle
17
+ };
18
+ };
19
+ const hooks_useToggle = useToggle;
20
+ export { hooks_useToggle as default };
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param fn 组件卸载时执行的函数
4
+ */
5
+ declare const useUnmount: (fn: () => any) => void;
6
+ export default useUnmount;
@@ -0,0 +1,10 @@
1
+ import { useEffect, useRef } from "react";
2
+ const useUnmount = (fn)=>{
3
+ const fnRef = useRef(fn);
4
+ fnRef.current = fn;
5
+ useEffect(()=>()=>{
6
+ if (fnRef.current && 'function' == typeof fnRef.current) fnRef.current();
7
+ }, []);
8
+ };
9
+ const hooks_useUnmount = useUnmount;
10
+ export { hooks_useUnmount as default };
@@ -0,0 +1,9 @@
1
+ import { useEffect } from 'react';
2
+ /**
3
+ * 用法同 `useEffect`,但跳过首次渲染后的那次执行,仅在依赖变化导致的更新时执行 `effect`。
4
+ *
5
+ * @param effect - 副作用函数,可返回清理函数
6
+ * @param deps - 依赖数组,语义与 `useEffect` 一致
7
+ */
8
+ export declare const useUpdateEffect: typeof useEffect;
9
+ export default useUpdateEffect;
@@ -0,0 +1,10 @@
1
+ import { useEffect, useRef } from "react";
2
+ const useUpdateEffect_useUpdateEffect = (effect, deps)=>{
3
+ const isMounted = useRef(false);
4
+ useEffect(()=>{
5
+ if (isMounted.current) return effect();
6
+ isMounted.current = true;
7
+ }, deps);
8
+ };
9
+ const useUpdateEffect = useUpdateEffect_useUpdateEffect;
10
+ export { useUpdateEffect as default, useUpdateEffect_useUpdateEffect as useUpdateEffect };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 在window宽高变化时更新 state。
3
+ *
4
+ * @returns `[width, height]`,分别为 `window.innerWidth` 与 `window.innerHeight`
5
+ */
6
+ export default function useWindowSize(): number[];
@@ -0,0 +1,15 @@
1
+ import { useState } from "react";
2
+ import useEventListener from "./useEventListener.js";
3
+ function useWindowSize() {
4
+ const [width, setWidth] = useState(window.innerWidth);
5
+ const [height, setHeight] = useState(window.innerHeight);
6
+ useEventListener('resize', ()=>{
7
+ setWidth(window.innerWidth);
8
+ setHeight(window.innerHeight);
9
+ });
10
+ return [
11
+ width,
12
+ height
13
+ ];
14
+ }
15
+ export { useWindowSize as default };
@@ -0,0 +1,9 @@
1
+ export type IHookStateInitialSetter<S> = () => S;
2
+ export type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
3
+ export type IHookStateSetter<S> = ((prevState: S) => S) | (() => S);
4
+ export type IHookStateSetAction<S> = S | IHookStateSetter<S>;
5
+ export type IHookStateResolvable<S> = S | IHookStateInitialSetter<S> | IHookStateSetter<S>;
6
+ export declare function resolveHookState<S>(nextState: IHookStateInitAction<S>): S;
7
+ export declare function resolveHookState<S, C extends S>(nextState: IHookStateSetAction<S>, currentState?: C): S;
8
+ export declare function resolveHookState<S, C extends S>(nextState: IHookStateResolvable<S>, currentState?: C): S;
9
+ export declare const isObject: (val: object) => boolean;
@@ -0,0 +1,6 @@
1
+ function resolveHookState(nextState, currentState) {
2
+ if ('function' == typeof nextState) return nextState.length ? nextState(currentState) : nextState();
3
+ return nextState;
4
+ }
5
+ const isObject = (val)=>'object' == typeof val && null !== val;
6
+ export { isObject, resolveHookState };