@wzyjs/hooks 0.3.27 → 0.3.29

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 (45) hide show
  1. package/dist/antd/index.d.ts +0 -3
  2. package/dist/antd/index.js +0 -3
  3. package/dist/antd/useDateRange.d.ts +2 -2
  4. package/dist/antd/useDateRange.js +1 -0
  5. package/dist/antd/useForm.d.ts +3 -3
  6. package/dist/antd/useForm.js +1 -0
  7. package/dist/antd/useModalConfirmFooter.d.ts +8 -3
  8. package/dist/antd/useModalConfirmFooter.js +1 -0
  9. package/dist/antd/usePaginationState.d.ts +1 -4
  10. package/dist/antd/usePaginationState.js +2 -0
  11. package/dist/antd/useStep.d.ts +1 -1
  12. package/dist/antd/useStep.js +1 -0
  13. package/dist/common/index.d.ts +3 -4
  14. package/dist/common/index.js +3 -4
  15. package/dist/common/useClick.js +1 -0
  16. package/dist/common/useComputeState.d.ts +1 -0
  17. package/dist/common/{useEffectValue.js → useComputeState.js} +2 -1
  18. package/dist/common/useControlState.d.ts +1 -0
  19. package/dist/common/useControlState.js +10 -0
  20. package/dist/common/useDeepDebouncedEffect.d.ts +2 -0
  21. package/dist/common/useDeepDebouncedEffect.js +12 -0
  22. package/dist/common/useMergeState.js +2 -0
  23. package/dist/common/useOnceEffect.js +1 -0
  24. package/dist/dom/index.d.ts +2 -1
  25. package/dist/dom/index.js +2 -1
  26. package/dist/dom/{useCacheValue.d.ts → useCacheState.d.ts} +1 -1
  27. package/dist/dom/{useCacheValue.js → useCacheState.js} +2 -1
  28. package/dist/dom/useElement.d.ts +2 -3
  29. package/dist/dom/useElement.js +1 -0
  30. package/dist/dom/useElementScrollVisible.d.ts +3 -3
  31. package/dist/dom/useElementScrollVisible.js +1 -1
  32. package/dist/{antd → dom}/useHovered.js +1 -0
  33. package/package.json +11 -4
  34. package/dist/antd/useHideFooter.d.ts +0 -1
  35. package/dist/antd/useHideFooter.js +0 -11
  36. package/dist/antd/useImperativeHandleForm.d.ts +0 -5
  37. package/dist/antd/useImperativeHandleForm.js +0 -9
  38. package/dist/common/useControlValue.d.ts +0 -1
  39. package/dist/common/useControlValue.js +0 -8
  40. package/dist/common/useDebouncedEffect.d.ts +0 -2
  41. package/dist/common/useDebouncedEffect.js +0 -13
  42. package/dist/common/useEffectValue.d.ts +0 -1
  43. package/dist/common/useVisibleInfo.d.ts +0 -5
  44. package/dist/common/useVisibleInfo.js +0 -18
  45. /package/dist/{antd → dom}/useHovered.d.ts +0 -0
@@ -1,8 +1,5 @@
1
1
  export * from './useForm';
2
- export * from './useImperativeHandleForm';
3
2
  export * from './useModalConfirmFooter';
4
3
  export * from './usePaginationState';
5
- export * from './useHideFooter';
6
- export * from './useHovered';
7
4
  export * from './useStep';
8
5
  export * from './useDateRange';
@@ -1,8 +1,5 @@
1
1
  export * from './useForm';
2
- export * from './useImperativeHandleForm';
3
2
  export * from './useModalConfirmFooter';
4
3
  export * from './usePaginationState';
5
- export * from './useHideFooter';
6
- export * from './useHovered';
7
4
  export * from './useStep';
8
5
  export * from './useDateRange';
@@ -1,4 +1,4 @@
1
- import dayjs, { Dayjs } from 'dayjs';
1
+ import { Dayjs } from 'dayjs';
2
2
  export declare enum PresetType {
3
3
  TODAY = "\u4ECA\u5929",
4
4
  THIS_WEEK = "\u672C\u5468",
@@ -14,7 +14,7 @@ interface Config {
14
14
  defaultDateRange?: PresetType | [Dayjs, Dayjs];
15
15
  }
16
16
  export declare const useDateRange: (config: Config) => {
17
- dateRange: [dayjs.Dayjs, dayjs.Dayjs];
17
+ dateRange: any;
18
18
  onChange: (dateRange?: any) => void;
19
19
  onClickPrev: () => void;
20
20
  onClickNext: () => void;
@@ -50,6 +50,7 @@ const checkDateRules = (dateRange) => {
50
50
  // 如果没有匹配到任何规则,可以根据需要返回默认值,这里假设返回 0
51
51
  return 0;
52
52
  };
53
+ // 功能:管理 antd RangePicker 日期范围,内置常用预设并按日、周、月规则前后切换。
53
54
  export const useDateRange = (config) => {
54
55
  const { defaultDateRange = PresetType.TODAY } = config;
55
56
  const [dateRange, setDateRange] = useState(Array.isArray(defaultDateRange)
@@ -7,9 +7,9 @@ interface Options<P, V> {
7
7
  }
8
8
  export declare const useForm: <P = any, V = P>(options?: Options<P, V>) => {
9
9
  form: import("antd").FormInstance<any>;
10
- formValues: V;
11
- setFormValues: import("react").Dispatch<import("react").SetStateAction<V>>;
12
- formParams: P;
10
+ formValues: any;
11
+ setFormValues: any;
12
+ formParams: any;
13
13
  clearFieldsValues: () => void;
14
14
  setFieldsValues: (values: V) => void;
15
15
  onQuery: () => Promise<void>;
@@ -3,6 +3,7 @@ import { Form } from 'antd';
3
3
  const cloneDeep = (value) => {
4
4
  return JSON.parse(JSON.stringify(value));
5
5
  };
6
+ // 功能:封装 antd Form,维护表单原始值和转换后的查询参数,并提供查询、重置、清空、赋值和 ref 暴露能力。
6
7
  export const useForm = (options = {}) => {
7
8
  const [form] = Form.useForm();
8
9
  useImperativeHandle(options.ref, () => form);
@@ -1,8 +1,13 @@
1
+ import type { ComponentType, ReactNode } from 'react';
1
2
  interface Option {
2
3
  onOk?: () => Promise<void>;
3
4
  onConfirm?: () => void;
4
5
  }
5
- export declare const useModalConfirmFooter: (option: Option) => {
6
- footer: (_: unknown, extra: any) => import("react/jsx-runtime").JSX.Element;
7
- };
6
+ interface ModalFooterExtra {
7
+ CancelBtn: ComponentType;
8
+ }
9
+ interface ModalConfirmFooter {
10
+ footer: (_: unknown, extra: ModalFooterExtra) => ReactNode;
11
+ }
12
+ export declare const useModalConfirmFooter: (option: Option) => ModalConfirmFooter;
8
13
  export {};
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { Space, Popconfirm, Button } from 'antd';
4
+ // 功能:为 antd Modal 生成带 Popconfirm 二次确认的 footer。
4
5
  export const useModalConfirmFooter = (option) => {
5
6
  const { onOk, onConfirm } = option;
6
7
  const [open, setOpen] = useState(false);
@@ -2,8 +2,5 @@ import { type PaginationProps } from 'antd';
2
2
  export declare const usePaginationState: (paginationProps?: PaginationProps) => {
3
3
  resetPage: () => void;
4
4
  pagination: PaginationProps;
5
- pageParams: {
6
- pageNum: number;
7
- pageSize: number;
8
- };
5
+ pageParams: any;
9
6
  };
@@ -1,4 +1,6 @@
1
1
  import { useMemo, useState } from 'react';
2
+ // 功能:管理 antd Pagination/Table 分页状态,并生成后端常用的 pageNum/pageSize 参数。
3
+ // 与 ahooks/usePagination 区别:这里只管理 antd 分页配置和参数,不负责请求数据、loading 或 total 状态。
2
4
  export const usePaginationState = (paginationProps) => {
3
5
  const options = {
4
6
  current: 1,
@@ -9,7 +9,7 @@ interface Option {
9
9
  onChangeAfter?: () => void;
10
10
  }
11
11
  export declare const useStep: (option: Option) => {
12
- current: number;
12
+ current: any;
13
13
  onPrev: () => void;
14
14
  onNext: () => void;
15
15
  };
@@ -4,6 +4,7 @@ export var Dir;
4
4
  Dir["Prev"] = "Prev";
5
5
  Dir["Next"] = "Next";
6
6
  })(Dir || (Dir = {}));
7
+ // 功能:管理简单步骤 current,并提供带切换前校验和前后回调的上一页、下一页方法。
7
8
  export const useStep = (option) => {
8
9
  const { defaultCurrent = 0, onChangeCheck, onChangeBefore, onChangeAfter } = option;
9
10
  const [current, setCurrent] = useState(defaultCurrent);
@@ -1,7 +1,6 @@
1
- export * from './useEffectValue';
2
- export * from './useVisibleInfo';
1
+ export * from './useComputeState';
3
2
  export * from './useClick';
4
- export * from './useDebouncedEffect';
3
+ export * from './useDeepDebouncedEffect';
5
4
  export * from './useMergeState';
6
- export * from './useControlValue';
5
+ export * from './useControlState';
7
6
  export * from './useOnceEffect';
@@ -1,7 +1,6 @@
1
- export * from './useEffectValue';
2
- export * from './useVisibleInfo';
1
+ export * from './useComputeState';
3
2
  export * from './useClick';
4
- export * from './useDebouncedEffect';
3
+ export * from './useDeepDebouncedEffect';
5
4
  export * from './useMergeState';
6
- export * from './useControlValue';
5
+ export * from './useControlState';
7
6
  export * from './useOnceEffect';
@@ -1,4 +1,5 @@
1
1
  import { useRef } from 'react';
2
+ // 功能:自动判断是单击还是双击,单击会延迟触发以等待可能出现的第二次点击。
2
3
  export const useClick = (option) => {
3
4
  const { onClick, onDoubleClick, delay = 300 } = option;
4
5
  const clickCount = useRef(0);
@@ -0,0 +1 @@
1
+ export declare const useComputeState: (defaultValue: any, fn: any, deps?: any[]) => any[];
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
- export const useEffectValue = (defaultValue, fn, deps = []) => {
2
+ // 功能:初始化一个可手动 set state,并在 deps 变化时用 fn 自动计算 state。
3
+ export const useComputeState = (defaultValue, fn, deps = []) => {
3
4
  const [value, setValue] = useState(defaultValue);
4
5
  useEffect(() => setValue(fn()), deps);
5
6
  return [value, setValue];
@@ -0,0 +1 @@
1
+ export declare const useControlState: <T>(state: T) => [T, React.Dispatch<React.SetStateAction<T>>];
@@ -0,0 +1,10 @@
1
+ import { useEffect, useState } from 'react';
2
+ // 功能:维护一个本地 state,并在外部传入的 state 变化时更新,以外部值为准。
3
+ // 与 ahooks/useControllableValue 区别:这里只镜像外部值,不处理 value/defaultValue/onChange 的受控非受控组件协议。
4
+ export const useControlState = (state) => {
5
+ const [state_, setState_] = useState(state);
6
+ useEffect(() => {
7
+ setState_(state);
8
+ }, [state]);
9
+ return [state_, setState_];
10
+ };
@@ -0,0 +1,2 @@
1
+ import { type DependencyList } from 'react';
2
+ export declare const useDeepDebouncedEffect: (effect: () => void | Promise<void>, deps: DependencyList, options?: any) => void;
@@ -0,0 +1,12 @@
1
+ import { useDebounceFn, useDeepCompareEffect } from 'ahooks';
2
+ // 功能:在 deps 深比较变化后,以 debounce 方式执行 effect。
3
+ // 与 ahooks/useDebounceEffect 区别:这里使用深比较依赖,默认 wait 为 300ms。
4
+ export const useDeepDebouncedEffect = (effect, deps, options = { wait: 300 }) => {
5
+ const { run, cancel } = useDebounceFn(effect, options);
6
+ useDeepCompareEffect(() => {
7
+ run();
8
+ return () => {
9
+ cancel();
10
+ };
11
+ }, deps);
12
+ };
@@ -1,5 +1,7 @@
1
1
  import { useState } from 'react';
2
2
  import _ from 'lodash';
3
+ // 功能:管理对象 state,并用 lodash.merge 对局部更新做深度合并。
4
+ // 与 ahooks/useSetState 区别:这里是深度合并,ahooks/useSetState 是浅合并。
3
5
  export const useMergeState = (initialState) => {
4
6
  const [state, setState] = useState(initialState);
5
7
  const mergeState = (partialState) => {
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
+ // 功能:在 deps 变化时执行 effect,effect 返回 true 即使后再次触发也不执行。
2
3
  export const useOnceEffect = (effect, deps) => {
3
4
  const [hasRun, setHasRun] = useState(false);
4
5
  useEffect(() => {
@@ -1,3 +1,4 @@
1
1
  export * from './useElement';
2
2
  export * from './useElementScrollVisible';
3
- export * from './useCacheValue';
3
+ export * from './useCacheState';
4
+ export * from './useHovered';
package/dist/dom/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './useElement';
2
2
  export * from './useElementScrollVisible';
3
- export * from './useCacheValue';
3
+ export * from './useCacheState';
4
+ export * from './useHovered';
@@ -1,3 +1,3 @@
1
- export declare const useCacheValue: <T>(key: string | undefined, value: T | undefined, onChange: ((value: T | undefined) => void) | undefined) => {
1
+ export declare const useCacheState: <T>(key: string | undefined, value: T | undefined, onChange: ((value: T | undefined) => void) | undefined) => {
2
2
  updateValue: (newValue: T | undefined) => void;
3
3
  };
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useRef } from 'react';
2
- export const useCacheValue = (key, value, onChange) => {
2
+ // 功能:给受控值增加 localStorage 缓存恢复和写入能力,并通过 onChange 回写外部状态。
3
+ export const useCacheState = (key, value, onChange) => {
3
4
  const loadedRef = useRef(false);
4
5
  // Load from cache on mount
5
6
  useEffect(() => {
@@ -1,5 +1,4 @@
1
- import { type CSSProperties } from 'react';
2
1
  export declare const useElement: () => {
3
- elementRef: import("react").RefObject<HTMLDivElement>;
4
- elementStyles: CSSProperties;
2
+ elementRef: any;
3
+ elementStyles: any;
5
4
  };
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useRef, useState } from 'react';
2
+ // 功能:返回一个元素 ref,并通过 ResizeObserver 记录元素尺寸变化后的 contentRect。
2
3
  export const useElement = () => {
3
4
  const elementRef = useRef(null);
4
5
  const [elementStyles, setElementStyles] = useState();
@@ -1,5 +1,5 @@
1
1
  export declare const useElementScrollVisible: (scroll: any, target: any) => {
2
- visible: boolean;
3
- direction: string;
4
- rect: string;
2
+ visible: any;
3
+ direction: any;
4
+ rect: any;
5
5
  };
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
- // 判断某元素滚动时,指定元素是否显示
2
+ // 功能:监听滚动容器滚动,判断目标元素在容器视口内、上方或下方。
3
3
  export const useElementScrollVisible = (scroll, target) => {
4
4
  const $scroll = document.querySelector(scroll) || {};
5
5
  const $scrollRect = $scroll.getBoundingClientRect();
@@ -1,4 +1,5 @@
1
1
  import { useBoolean } from 'ahooks';
2
+ // 功能:返回 hover 状态和可直接 spread 到元素上的 mouse enter/leave 事件 props。
2
3
  export const useHovered = () => {
3
4
  const [isHovered, { setTrue, setFalse }] = useBoolean(false);
4
5
  const hoverProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/hooks",
3
- "version": "0.3.27",
3
+ "version": "0.3.29",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "type": "module",
@@ -36,13 +36,20 @@
36
36
  "dependencies": {
37
37
  "@ahooksjs/use-url-state": "^3.5.1",
38
38
  "ahooks": "^3.8.4",
39
- "antd": "^5.24.3",
40
39
  "dayjs": "^1.11.12",
41
- "react": "^19.1.0",
40
+ "lodash": "^4.17.21",
42
41
  "react-use": "^17.4.0"
43
42
  },
43
+ "peerDependencies": {
44
+ "antd": "^5.24.3",
45
+ "react": "^19.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "antd": "^5.24.3",
49
+ "react": "^19.1.0"
50
+ },
44
51
  "publishConfig": {
45
52
  "access": "public"
46
53
  },
47
- "gitHead": "f9e5dcf56fea3b93a2614ad468ecb466e5da7945"
54
+ "gitHead": "a78702bb9367a10779eaa376ed70834d8b42b5a8"
48
55
  }
@@ -1 +0,0 @@
1
- export declare const useHideFooter: (el?: string) => void;
@@ -1,11 +0,0 @@
1
- import { useEffect } from 'react';
2
- // 进入时隐藏指定元素,销毁时恢复该元素
3
- export const useHideFooter = (el = '.ant-layout-footer') => {
4
- useEffect(() => {
5
- const e = document.querySelector(el);
6
- e.style.display = 'none';
7
- return () => {
8
- e.style.display = 'block';
9
- };
10
- }, []);
11
- };
@@ -1,5 +0,0 @@
1
- import { type Ref } from 'react';
2
- import { type FormInstance } from 'antd';
3
- export declare const useImperativeHandleForm: (ref: Ref<FormInstance>) => {
4
- form: FormInstance<any>;
5
- };
@@ -1,9 +0,0 @@
1
- import { useImperativeHandle } from 'react';
2
- import { Form } from 'antd';
3
- export const useImperativeHandleForm = (ref) => {
4
- const [form] = Form.useForm();
5
- useImperativeHandle(ref, () => form);
6
- return {
7
- form,
8
- };
9
- };
@@ -1 +0,0 @@
1
- export declare const useControlValue: <T>(state: T) => [T, React.Dispatch<React.SetStateAction<T>>];
@@ -1,8 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- export const useControlValue = (state) => {
3
- const [state_, setState_] = useState(state);
4
- useEffect(() => {
5
- setState_(state);
6
- }, [state]);
7
- return [state_, setState_];
8
- };
@@ -1,2 +0,0 @@
1
- import { type DependencyList } from 'react';
2
- export declare const useDebouncedEffect: <T>(effect: () => (T | Promise<T>), deps: DependencyList, options?: any) => T;
@@ -1,13 +0,0 @@
1
- import { useState } from 'react';
2
- import { useDebounceFn, useDeepCompareEffect } from 'ahooks';
3
- export const useDebouncedEffect = (effect, deps, options = { wait: 300 }) => {
4
- const { run, cancel } = useDebounceFn(effect, options);
5
- const [value, setValue] = useState();
6
- useDeepCompareEffect(() => {
7
- setValue(run());
8
- return () => {
9
- cancel();
10
- };
11
- }, deps);
12
- return value;
13
- };
@@ -1 +0,0 @@
1
- export declare const useEffectValue: (defaultValue: any, fn: any, deps?: any[]) => any[];
@@ -1,5 +0,0 @@
1
- export declare const useVisibleInfo: (v: boolean, i: any) => (boolean | any[] | {
2
- setTrue: () => void;
3
- setFalse: () => void;
4
- toggle: () => void;
5
- })[];
@@ -1,18 +0,0 @@
1
- import { useState } from 'react';
2
- // visible和info的集合体
3
- export const useVisibleInfo = (v = false, i) => {
4
- const [visible, setVisible] = useState(v);
5
- const [info, setInfo] = useState(i);
6
- return [
7
- visible,
8
- {
9
- setTrue: () => setVisible(true),
10
- setFalse: () => setVisible(false),
11
- toggle: () => setVisible(!visible),
12
- },
13
- [
14
- info,
15
- setInfo,
16
- ],
17
- ];
18
- };
File without changes