zcw-shared 1.24.0 → 1.25.0
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.
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UnwrapRef } from '../../../references/vue.d';
|
|
2
|
+
import type { VueCompositionAPI } from '../../../types/vue.d';
|
|
3
|
+
import type { CreateThrottledEventListenerDeps } from '../../functions/dom/createThrottledEventListener';
|
|
4
|
+
export interface StateData {
|
|
5
|
+
visible: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type State = UnwrapRef<StateData>;
|
|
8
|
+
export interface UseAutoUpdateDeps extends CreateThrottledEventListenerDeps {
|
|
9
|
+
watch: VueCompositionAPI['watch'];
|
|
10
|
+
}
|
|
11
|
+
export interface UseAutoUpdateOptions {
|
|
12
|
+
state: State;
|
|
13
|
+
update: () => void;
|
|
14
|
+
throttleMs?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface UseAutoUpdateReturn {
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function useAutoUpdate(options: UseAutoUpdateOptions, deps: UseAutoUpdateDeps): UseAutoUpdateReturn;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createThrottledEventListener } from '../../functions/dom/createThrottledEventListener';
|
|
2
|
+
export function useAutoUpdate(options, deps) {
|
|
3
|
+
const { state, update, throttleMs = 0 } = options;
|
|
4
|
+
let resizeCleanup = null;
|
|
5
|
+
let scrollCleanup = null;
|
|
6
|
+
const stopAutoUpdateWatch = deps.watch(() => state.visible, (visible) => {
|
|
7
|
+
if (visible) {
|
|
8
|
+
if (!resizeCleanup) {
|
|
9
|
+
resizeCleanup = createThrottledEventListener('resize', update, throttleMs, deps);
|
|
10
|
+
}
|
|
11
|
+
if (!scrollCleanup) {
|
|
12
|
+
scrollCleanup = createThrottledEventListener('scroll', update, throttleMs, deps);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (resizeCleanup) {
|
|
17
|
+
resizeCleanup();
|
|
18
|
+
resizeCleanup = null;
|
|
19
|
+
}
|
|
20
|
+
if (scrollCleanup) {
|
|
21
|
+
scrollCleanup();
|
|
22
|
+
scrollCleanup = null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, { immediate: true });
|
|
26
|
+
const destroy = () => {
|
|
27
|
+
try {
|
|
28
|
+
stopAutoUpdateWatch();
|
|
29
|
+
resizeCleanup?.();
|
|
30
|
+
scrollCleanup?.();
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
resizeCleanup = null;
|
|
34
|
+
scrollCleanup = null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
destroy,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useAutoUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutoUpdate.js","sourceRoot":"","sources":["../../../src/vue-hooks/dom/useAutoUpdate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAA;AA8E/F,MAAM,UAAU,aAAa,CAC3B,OAA6B,EAC7B,IAAuB;IAEvB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;IAEjD,IAAI,aAAa,GAAwB,IAAI,CAAA;IAC7C,IAAI,aAAa,GAAwB,IAAI,CAAA;IAG7C,MAAM,mBAAmB,GAAoB,IAAI,CAAC,KAAM,CACtD,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EACnB,CAAC,OAAO,EAAE,EAAE;QACV,IAAI,OAAO,EAAE,CAAC;YAEZ,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,aAAa,GAAG,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;YAClF,CAAC;YACD,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,aAAa,GAAG,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;YAClF,CAAC;QACH,CAAC;aAAM,CAAC;YAEN,IAAI,aAAa,EAAE,CAAC;gBAClB,aAAa,EAAE,CAAA;gBACf,aAAa,GAAG,IAAI,CAAA;YACtB,CAAC;YACD,IAAI,aAAa,EAAE,CAAC;gBAClB,aAAa,EAAE,CAAA;gBACf,aAAa,GAAG,IAAI,CAAA;YACtB,CAAC;QACH,CAAC;IACH,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAA;IAED,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,IAAI,CAAC;YACH,mBAAmB,EAAE,CAAA;YACrB,aAAa,EAAE,EAAE,CAAA;YACjB,aAAa,EAAE,EAAE,CAAA;QACnB,CAAC;gBAAS,CAAC;YACT,aAAa,GAAG,IAAI,CAAA;YACpB,aAAa,GAAG,IAAI,CAAA;QACtB,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,OAAO;KACR,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcw-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"references",
|
|
6
6
|
"dist",
|
|
@@ -265,6 +265,7 @@
|
|
|
265
265
|
"./vue-hooks/browser/useScreenWakeLock": "./dist/vue-hooks/browser/useScreenWakeLock.js",
|
|
266
266
|
"./vue-hooks/browser/useShare": "./dist/vue-hooks/browser/useShare.js",
|
|
267
267
|
"./vue-hooks/browser/useVibration": "./dist/vue-hooks/browser/useVibration.js",
|
|
268
|
+
"./vue-hooks/dom/useAutoUpdate": "./dist/vue-hooks/dom/useAutoUpdate.js",
|
|
268
269
|
"./vue-hooks/dom/useClickOutside": "./dist/vue-hooks/dom/useClickOutside.js",
|
|
269
270
|
"./vue-hooks/dom/useDraggable": "./dist/vue-hooks/dom/useDraggable.js",
|
|
270
271
|
"./vue-hooks/dom/useEventListener": "./dist/vue-hooks/dom/useEventListener.js",
|
package/types/vue.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ColorReference } from './design-system.d'
|
|
2
|
-
import type { Ref, InjectionKey } from '../references/vue.d'
|
|
2
|
+
import type { Ref, InjectionKey, WatchStopHandle } from '../references/vue.d'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Vue Composition API 通用接口
|
|
@@ -19,7 +19,7 @@ export interface VueCompositionAPI {
|
|
|
19
19
|
/** 注入依赖 */
|
|
20
20
|
inject?: <T>(key: InjectionKey<T> | string, defaultValue?: T) => T | undefined
|
|
21
21
|
/** 监听响应式数据变化 */
|
|
22
|
-
watch?: (source:
|
|
22
|
+
watch?: <T>(source: (() => T) | Ref<T>, callback: (newValue: T, oldValue: T) => void, options?: { deep?: boolean; flush?: string; immediate?: boolean }) => WatchStopHandle
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|