@easyv/biz-components 1.0.17 → 1.0.19
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/hooks/index.d.ts +1 -0
- package/dist/hooks/use-document-unmount/index.d.ts +1 -0
- package/dist/hooks/use-document-unmount/use-document-unmount.d.ts +1 -0
- package/dist/hooks/use-document-unmount/use-document-unmount.es.js +18 -0
- package/dist/hooks/use-document-unmount/use-document-unmount.es.js.map +1 -0
- package/dist/hooks/use-initialized.d.ts +1 -1
- package/dist/hooks/use-initialized.es.js +2 -1
- package/dist/hooks/use-initialized.es.js.map +1 -1
- package/dist/hooks/use-watch-value/playground.cy.d.ts +1 -0
- package/dist/hooks/use-watch-value/use-watch-value.d.ts +39 -12
- package/dist/hooks/use-watch-value/use-watch-value.es.js +20 -29
- package/dist/hooks/use-watch-value/use-watch-value.es.js.map +1 -1
- package/dist/index.es.js +2 -0
- package/dist/index.es.js.map +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-document-unmount';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDocumentUnmount(fn: () => void): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import useMemoizedFn from "../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMemoizedFn/index.es.js";
|
|
3
|
+
function useDocumentUnmount(fn) {
|
|
4
|
+
const finalFn = useMemoizedFn(fn);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const handleBeforeUnload = () => {
|
|
7
|
+
finalFn();
|
|
8
|
+
};
|
|
9
|
+
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
10
|
+
return () => {
|
|
11
|
+
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
12
|
+
};
|
|
13
|
+
}, [finalFn]);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
useDocumentUnmount
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=use-document-unmount.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-document-unmount.es.js","sources":["../../../src/hooks/use-document-unmount/use-document-unmount.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { useMemoizedFn } from 'ahooks';\n\nexport function useDocumentUnmount(fn: () => void) {\n const finalFn = useMemoizedFn(fn);\n // 监听页面卸载事件\n useEffect(() => {\n const handleBeforeUnload = () => {\n finalFn();\n };\n\n window.addEventListener('beforeunload', handleBeforeUnload);\n\n return () => {\n window.removeEventListener('beforeunload', handleBeforeUnload);\n };\n }, [finalFn]);\n}\n"],"names":[],"mappings":";;AAGO,SAAS,mBAAmB,IAAgB;AAC3C,QAAA,UAAU,cAAc,EAAE;AAEhC,YAAU,MAAM;AACd,UAAM,qBAAqB,MAAM;AACvB,cAAA;AAAA,IACV;AAEO,WAAA,iBAAiB,gBAAgB,kBAAkB;AAE1D,WAAO,MAAM;AACJ,aAAA,oBAAoB,gBAAgB,kBAAkB;AAAA,IAC/D;AAAA,EAAA,GACC,CAAC,OAAO,CAAC;AACd;"}
|
|
@@ -3,5 +3,5 @@ type FunctionType = () => void;
|
|
|
3
3
|
* @param fn 初始化函数, fn 返回的如果是一个函数,会在卸载时运行。
|
|
4
4
|
* @returns initialized 是否初始化,boolean 值是一个 react state,会触发重新渲染
|
|
5
5
|
*/
|
|
6
|
-
export declare function useInitialized(fn
|
|
6
|
+
export declare function useInitialized(fn?: () => void | FunctionType): boolean;
|
|
7
7
|
export {};
|
|
@@ -6,8 +6,9 @@ function useInitialized(fn) {
|
|
|
6
6
|
const cleanFnRef = useRef();
|
|
7
7
|
updateFnRef.current = fn;
|
|
8
8
|
useEffect(() => {
|
|
9
|
+
var _a;
|
|
9
10
|
if (!initializedRef.current) {
|
|
10
|
-
cleanFnRef.current = updateFnRef.current();
|
|
11
|
+
cleanFnRef.current = (_a = updateFnRef.current) == null ? void 0 : _a.call(updateFnRef);
|
|
11
12
|
setInitialized(true);
|
|
12
13
|
initializedRef.current = true;
|
|
13
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-initialized.es.js","sources":["../../src/hooks/use-initialized.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\ntype FunctionType = () => void;\n/** 传入的函数只会初始化运行一次\n * @param fn 初始化函数, fn 返回的如果是一个函数,会在卸载时运行。\n * @returns initialized 是否初始化,boolean 值是一个 react state,会触发重新渲染\n */\nexport function useInitialized(fn
|
|
1
|
+
{"version":3,"file":"use-initialized.es.js","sources":["../../src/hooks/use-initialized.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\ntype FunctionType = () => void;\n/** 传入的函数只会初始化运行一次\n * @param fn 初始化函数, fn 返回的如果是一个函数,会在卸载时运行。\n * @returns initialized 是否初始化,boolean 值是一个 react state,会触发重新渲染\n */\nexport function useInitialized(fn?: () => void | FunctionType) {\n const [initialized, setInitialized] = useState(false);\n const initializedRef = useRef(false);\n const updateFnRef = useRef(fn);\n const cleanFnRef = useRef<FunctionType | void>();\n updateFnRef.current = fn;\n\n useEffect(() => {\n if (!initializedRef.current) {\n cleanFnRef.current = updateFnRef.current?.();\n setInitialized(true);\n initializedRef.current = true;\n }\n return () => {\n if (typeof cleanFnRef.current === 'function') {\n cleanFnRef.current();\n }\n };\n }, []);\n\n return initialized;\n}\n"],"names":[],"mappings":";AAOO,SAAS,eAAe,IAAgC;AAC7D,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,KAAK;AAC9C,QAAA,iBAAiB,OAAO,KAAK;AAC7B,QAAA,cAAc,OAAO,EAAE;AAC7B,QAAM,aAAa,OAA4B;AAC/C,cAAY,UAAU;AAEtB,YAAU,MAAM;;AACV,QAAA,CAAC,eAAe,SAAS;AAChB,iBAAA,WAAU,iBAAY,YAAZ;AACrB,qBAAe,IAAI;AACnB,qBAAe,UAAU;AAAA,IAAA;AAE3B,WAAO,MAAM;AACP,UAAA,OAAO,WAAW,YAAY,YAAY;AAC5C,mBAAW,QAAQ;AAAA,MAAA;AAAA,IAEvB;AAAA,EACF,GAAG,EAAE;AAEE,SAAA;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
type
|
|
2
|
-
interface
|
|
1
|
+
type WatchableValue = string | number | boolean | object | Array<unknown> | null | undefined;
|
|
2
|
+
interface UseWatchValueOptions<T> {
|
|
3
|
+
/** 自定义比较函数,默认使用 lodash isEqual */
|
|
4
|
+
equalFn?: (value1: T, value2: T) => boolean;
|
|
5
|
+
/** 是否立即执行回调,默认为 true */
|
|
6
|
+
immediate?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface UseWatchValueParams<T> {
|
|
9
|
+
/** 要监听的值 */
|
|
3
10
|
value: T;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
11
|
+
/** 值变化时的回调函数 */
|
|
12
|
+
callback: (newValue: T, oldValue?: T) => void | Promise<void>;
|
|
13
|
+
/** 配置选项 */
|
|
14
|
+
options?: UseWatchValueOptions<T>;
|
|
9
15
|
}
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
16
|
+
/**
|
|
17
|
+
* 监听值变化的 React Hook
|
|
18
|
+
*
|
|
19
|
+
* @description 当监听的值发生变化时,会调用提供的回调函数
|
|
20
|
+
* @param params 配置参数
|
|
21
|
+
* @param params.value 要监听的值
|
|
22
|
+
* @param params.callback 值变化时的回调函数
|
|
23
|
+
* @param params.options 配置选项
|
|
24
|
+
* @param params.options.equalFn 自定义比较函数,默认使用 lodash isEqual
|
|
25
|
+
* @param params.options.immediate 是否立即执行回调,默认为 true
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const [count, setCount] = useState(0);
|
|
30
|
+
*
|
|
31
|
+
* useWatchValue({
|
|
32
|
+
* value: count,
|
|
33
|
+
* callback: (newValue, oldValue) => {
|
|
34
|
+
* console.log(`Count changed from ${oldValue} to ${newValue}`);
|
|
35
|
+
* },
|
|
36
|
+
* options: {
|
|
37
|
+
* immediate: false // 不立即执行
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
14
41
|
*/
|
|
15
|
-
export declare function useWatchValue<T extends
|
|
42
|
+
export declare function useWatchValue<T extends WatchableValue>(params: UseWatchValueParams<T>): void;
|
|
16
43
|
export {};
|
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
|
+
import useMemoizedFn from "../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMemoizedFn/index.es.js";
|
|
2
3
|
import isEqual from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isEqual.es.js";
|
|
3
|
-
const initValue = Symbol("initValue");
|
|
4
4
|
function useWatchValue(params) {
|
|
5
|
-
const { value, callback, options } = params;
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
equalFn,
|
|
12
|
-
immediate
|
|
13
|
-
});
|
|
14
|
-
fnObj.current = {
|
|
15
|
-
callback,
|
|
16
|
-
equalFn,
|
|
17
|
-
immediate
|
|
18
|
-
};
|
|
5
|
+
const { value, callback, options = {} } = params;
|
|
6
|
+
const { equalFn = isEqual, immediate = true } = options;
|
|
7
|
+
const prevValueRef = useRef(value);
|
|
8
|
+
const isFirstRenderRef = useRef(true);
|
|
9
|
+
const stableCallback = useMemoizedFn(callback);
|
|
10
|
+
const stableEqualFn = useMemoizedFn(equalFn);
|
|
19
11
|
useEffect(() => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
const isFirstRender = isFirstRenderRef.current;
|
|
13
|
+
const prevValue = prevValueRef.current;
|
|
14
|
+
if (isFirstRender) {
|
|
15
|
+
isFirstRenderRef.current = false;
|
|
16
|
+
if (immediate) {
|
|
17
|
+
stableCallback(value, void 0);
|
|
18
|
+
}
|
|
19
|
+
prevValueRef.current = value;
|
|
20
|
+
return;
|
|
28
21
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
callbackInner(value, ref.current);
|
|
33
|
-
ref.current = value;
|
|
22
|
+
if (!stableEqualFn(value, prevValue)) {
|
|
23
|
+
stableCallback(value, prevValue);
|
|
24
|
+
prevValueRef.current = value;
|
|
34
25
|
}
|
|
35
|
-
}, [value]);
|
|
26
|
+
}, [value, stableCallback, stableEqualFn, immediate]);
|
|
36
27
|
}
|
|
37
28
|
export {
|
|
38
29
|
useWatchValue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-watch-value.es.js","sources":["../../../src/hooks/use-watch-value/use-watch-value.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { isEqual } from 'lodash-es';\n\ntype
|
|
1
|
+
{"version":3,"file":"use-watch-value.es.js","sources":["../../../src/hooks/use-watch-value/use-watch-value.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport { isEqual } from 'lodash-es';\n\n// 更精确的类型定义,排除函数类型以避免潜在问题\ntype WatchableValue = string | number | boolean | object | Array<unknown> | null | undefined;\n\ninterface UseWatchValueOptions<T> {\n /** 自定义比较函数,默认使用 lodash isEqual */\n equalFn?: (value1: T, value2: T) => boolean;\n /** 是否立即执行回调,默认为 true */\n immediate?: boolean;\n}\n\ninterface UseWatchValueParams<T> {\n /** 要监听的值 */\n value: T;\n /** 值变化时的回调函数 */\n callback: (newValue: T, oldValue?: T) => void | Promise<void>;\n /** 配置选项 */\n options?: UseWatchValueOptions<T>;\n}\n\n/**\n * 监听值变化的 React Hook\n *\n * @description 当监听的值发生变化时,会调用提供的回调函数\n * @param params 配置参数\n * @param params.value 要监听的值\n * @param params.callback 值变化时的回调函数\n * @param params.options 配置选项\n * @param params.options.equalFn 自定义比较函数,默认使用 lodash isEqual\n * @param params.options.immediate 是否立即执行回调,默认为 true\n *\n * @example\n * ```tsx\n * const [count, setCount] = useState(0);\n *\n * useWatchValue({\n * value: count,\n * callback: (newValue, oldValue) => {\n * console.log(`Count changed from ${oldValue} to ${newValue}`);\n * },\n * options: {\n * immediate: false // 不立即执行\n * }\n * });\n * ```\n */\nexport function useWatchValue<T extends WatchableValue>(params: UseWatchValueParams<T>) {\n const { value, callback, options = {} } = params;\n const { equalFn = isEqual, immediate = true } = options;\n\n // 存储上一次的值\n const prevValueRef = useRef<T>(value);\n // 标记是否为首次渲染\n const isFirstRenderRef = useRef(true);\n\n // 使用 useMemoizedFn 优化回调函数,避免不必要的依赖更新\n const stableCallback = useMemoizedFn(callback);\n const stableEqualFn = useMemoizedFn(equalFn);\n\n useEffect(() => {\n const isFirstRender = isFirstRenderRef.current;\n const prevValue = prevValueRef.current;\n\n // 首次渲染且 immediate 为 true 时执行回调\n if (isFirstRender) {\n isFirstRenderRef.current = false;\n if (immediate) {\n stableCallback(value, undefined);\n }\n prevValueRef.current = value;\n return;\n }\n\n // 值发生变化时执行回调\n if (!stableEqualFn(value, prevValue)) {\n stableCallback(value, prevValue);\n prevValueRef.current = value;\n }\n }, [value, stableCallback, stableEqualFn, immediate]);\n}\n"],"names":[],"mappings":";;;AAiDO,SAAS,cAAwC,QAAgC;AACtF,QAAM,EAAE,OAAO,UAAU,UAAU,CAAA,EAAO,IAAA;AAC1C,QAAM,EAAE,UAAU,SAAS,YAAY,KAAS,IAAA;AAG1C,QAAA,eAAe,OAAU,KAAK;AAE9B,QAAA,mBAAmB,OAAO,IAAI;AAG9B,QAAA,iBAAiB,cAAc,QAAQ;AACvC,QAAA,gBAAgB,cAAc,OAAO;AAE3C,YAAU,MAAM;AACd,UAAM,gBAAgB,iBAAiB;AACvC,UAAM,YAAY,aAAa;AAG/B,QAAI,eAAe;AACjB,uBAAiB,UAAU;AAC3B,UAAI,WAAW;AACb,uBAAe,OAAO,MAAS;AAAA,MAAA;AAEjC,mBAAa,UAAU;AACvB;AAAA,IAAA;AAIF,QAAI,CAAC,cAAc,OAAO,SAAS,GAAG;AACpC,qBAAe,OAAO,SAAS;AAC/B,mBAAa,UAAU;AAAA,IAAA;AAAA,KAExB,CAAC,OAAO,gBAAgB,eAAe,SAAS,CAAC;AACtD;"}
|
package/dist/index.es.js
CHANGED
|
@@ -14,6 +14,7 @@ import { useInitialized } from "./hooks/use-initialized.es.js";
|
|
|
14
14
|
import { useWatchValue } from "./hooks/use-watch-value/use-watch-value.es.js";
|
|
15
15
|
import { useSocketEvents } from "./hooks/use-socket-events/use-socket-events.es.js";
|
|
16
16
|
import { EXPLICIT_DISCONNECT_REASON, MAX_TIMEOUT, MessageType, MpsErrorCode, ROOM_PREFIX, RoomType, RoomTypeIdMap, SocketEventType, messageWindowByType, socketBroadcastMessageList, socketNormalMessageList } from "./hooks/use-socket-events/constant.es.js";
|
|
17
|
+
import { useDocumentUnmount } from "./hooks/use-document-unmount/use-document-unmount.es.js";
|
|
17
18
|
import { FunASRManager, getWebSocketConnectForFunASR } from "./utils/fun-ASR/fun-ASR-manager.es.js";
|
|
18
19
|
import { XFStreamVoiceManager } from "./utils/xun-fei-voice/XF-stream-voice-manager.es.js";
|
|
19
20
|
import { RecorderManager } from "./utils/xun-fei-voice/recorder-manager/RecorderManager.es.js";
|
|
@@ -51,6 +52,7 @@ export {
|
|
|
51
52
|
socketBroadcastMessageList,
|
|
52
53
|
socketNormalMessageList,
|
|
53
54
|
useDivAutoScroll,
|
|
55
|
+
useDocumentUnmount,
|
|
54
56
|
useInitialized,
|
|
55
57
|
useSocketEvents,
|
|
56
58
|
useWatchValue,
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
|