@wzyjs/hooks 0.3.28 → 0.3.30
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.
- package/dist/antd/index.d.ts +0 -3
- package/dist/antd/index.js +0 -3
- package/dist/antd/useDateRange.js +1 -0
- package/dist/antd/useForm.js +1 -0
- package/dist/antd/useModalConfirmFooter.d.ts +8 -3
- package/dist/antd/useModalConfirmFooter.js +1 -0
- package/dist/antd/usePaginationState.js +2 -0
- package/dist/antd/useStep.js +1 -0
- package/dist/common/index.d.ts +3 -4
- package/dist/common/index.js +3 -4
- package/dist/common/useClick.js +1 -0
- package/dist/common/useComputeState.d.ts +1 -0
- package/dist/common/{useEffectValue.js → useComputeState.js} +2 -1
- package/dist/common/useControlState.d.ts +2 -0
- package/dist/common/useControlState.js +10 -0
- package/dist/common/useDeepDebouncedEffect.d.ts +2 -0
- package/dist/common/useDeepDebouncedEffect.js +12 -0
- package/dist/common/useMergeState.d.ts +2 -1
- package/dist/common/useMergeState.js +13 -3
- package/dist/common/useOnceEffect.d.ts +2 -1
- package/dist/common/useOnceEffect.js +1 -0
- package/dist/dom/index.d.ts +2 -1
- package/dist/dom/index.js +2 -1
- package/dist/dom/{useCacheValue.d.ts → useCacheState.d.ts} +1 -1
- package/dist/dom/{useCacheValue.js → useCacheState.js} +2 -1
- package/dist/dom/useElement.js +1 -0
- package/dist/dom/useElementScrollVisible.js +1 -1
- package/dist/{antd → dom}/useHovered.js +1 -0
- package/dist/web.d.ts +0 -2
- package/dist/web.js +0 -2
- package/package.json +13 -6
- package/dist/antd/useHideFooter.d.ts +0 -1
- package/dist/antd/useHideFooter.js +0 -11
- package/dist/antd/useImperativeHandleForm.d.ts +0 -5
- package/dist/antd/useImperativeHandleForm.js +0 -9
- package/dist/common/useControlValue.d.ts +0 -1
- package/dist/common/useControlValue.js +0 -8
- package/dist/common/useDebouncedEffect.d.ts +0 -2
- package/dist/common/useDebouncedEffect.js +0 -13
- package/dist/common/useEffectValue.d.ts +0 -1
- package/dist/common/useVisibleInfo.d.ts +0 -5
- package/dist/common/useVisibleInfo.js +0 -18
- /package/dist/{antd → dom}/useHovered.d.ts +0 -0
package/dist/antd/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/antd/index.js
CHANGED
|
@@ -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';
|
|
@@ -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)
|
package/dist/antd/useForm.js
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
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);
|
|
@@ -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,
|
package/dist/antd/useStep.js
CHANGED
|
@@ -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);
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './useVisibleInfo';
|
|
1
|
+
export * from './useComputeState';
|
|
3
2
|
export * from './useClick';
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './useDeepDebouncedEffect';
|
|
5
4
|
export * from './useMergeState';
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './useControlState';
|
|
7
6
|
export * from './useOnceEffect';
|
package/dist/common/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './useVisibleInfo';
|
|
1
|
+
export * from './useComputeState';
|
|
3
2
|
export * from './useClick';
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './useDeepDebouncedEffect';
|
|
5
4
|
export * from './useMergeState';
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './useControlState';
|
|
7
6
|
export * from './useOnceEffect';
|
package/dist/common/useClick.js
CHANGED
|
@@ -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
|
-
|
|
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,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,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,3 +1,4 @@
|
|
|
1
1
|
type StateType = Record<string, any>;
|
|
2
|
-
|
|
2
|
+
type MergeMode = 'deep' | 'shallow';
|
|
3
|
+
export declare const useMergeState: <T extends StateType>(initialState: T, mergeMode?: MergeMode) => [T, (partialState: Partial<T>) => void];
|
|
3
4
|
export {};
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
// 功能:管理对象 state,并用 lodash.merge 对局部更新做深度合并。
|
|
4
|
+
// 与 ahooks/useSetState 区别:这里是深度合并,ahooks/useSetState 是浅合并。
|
|
5
|
+
export const useMergeState = (initialState, mergeMode = 'deep') => {
|
|
4
6
|
const [state, setState] = useState(initialState);
|
|
5
7
|
const mergeState = (partialState) => {
|
|
6
8
|
if (typeof partialState !== 'object' || partialState === null) {
|
|
7
9
|
throw new Error('mergeState must be called with an object');
|
|
8
10
|
}
|
|
9
|
-
setState((prevState) =>
|
|
11
|
+
setState((prevState) => {
|
|
12
|
+
if (mergeMode === 'shallow') {
|
|
13
|
+
return {
|
|
14
|
+
...prevState,
|
|
15
|
+
...partialState,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return merge({}, prevState, partialState);
|
|
19
|
+
});
|
|
10
20
|
};
|
|
11
21
|
return [state, mergeState];
|
|
12
22
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { DependencyList } from 'react';
|
|
2
|
+
export declare const useOnceEffect: (effect: () => boolean, deps: DependencyList) => void;
|
package/dist/dom/index.d.ts
CHANGED
package/dist/dom/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const
|
|
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
|
-
|
|
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(() => {
|
package/dist/dom/useElement.js
CHANGED
|
@@ -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();
|
package/dist/web.d.ts
CHANGED
package/dist/web.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wzyjs/hooks",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.30",
|
|
4
4
|
"description": "description",
|
|
5
5
|
"author": "wzy",
|
|
6
6
|
"type": "module",
|
|
@@ -34,15 +34,22 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ahooksjs/use-url-state": "^3.5.1",
|
|
38
37
|
"ahooks": "^3.8.4",
|
|
39
|
-
"antd": "^5.24.3",
|
|
40
38
|
"dayjs": "^1.11.12",
|
|
41
|
-
"
|
|
42
|
-
|
|
39
|
+
"lodash-es": "^4.17.21"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"antd": "^6.3.1",
|
|
43
|
+
"react": "^19.1.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/lodash-es": "^4.17.12",
|
|
47
|
+
"@types/react": "^19.1.10",
|
|
48
|
+
"antd": "^6.3.1",
|
|
49
|
+
"react": "^19.1.0"
|
|
43
50
|
},
|
|
44
51
|
"publishConfig": {
|
|
45
52
|
"access": "public"
|
|
46
53
|
},
|
|
47
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "4e50539cd20e721602a057645c9b859530a1b8c5"
|
|
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 +0,0 @@
|
|
|
1
|
-
export declare const useControlValue: <T>(state: T) => [T, React.Dispatch<React.SetStateAction<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,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
|