|
|
@ -1,6 +1,7 @@
|
|
|
|
import type { VNodeProps, Ref, ShallowRef } from 'vue';
|
|
|
|
import type { VNodeProps, Ref, ShallowRef } from 'vue';
|
|
|
|
import { watch, ref } from 'vue';
|
|
|
|
import { onUnmounted, watch, ref } from 'vue';
|
|
|
|
import type { GetKey } from '../interface';
|
|
|
|
import type { GetKey } from '../interface';
|
|
|
|
|
|
|
|
import wrapperRaf from '../../_util/raf';
|
|
|
|
|
|
|
|
|
|
|
|
export type CacheMap = Map<any, number>;
|
|
|
|
export type CacheMap = Map<any, number>;
|
|
|
|
|
|
|
|
|
|
|
@ -16,14 +17,14 @@ export default function useHeights<T>(
|
|
|
|
watch(mergedData, () => {
|
|
|
|
watch(mergedData, () => {
|
|
|
|
updatedMark.value = Symbol('update');
|
|
|
|
updatedMark.value = Symbol('update');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let heightUpdateId = 0;
|
|
|
|
let collectRaf: number = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cancelRaf() {
|
|
|
|
|
|
|
|
wrapperRaf.cancel(collectRaf);
|
|
|
|
|
|
|
|
}
|
|
|
|
function collectHeight() {
|
|
|
|
function collectHeight() {
|
|
|
|
heightUpdateId += 1;
|
|
|
|
cancelRaf();
|
|
|
|
const currentId = heightUpdateId;
|
|
|
|
collectRaf = wrapperRaf(() => {
|
|
|
|
Promise.resolve().then(() => {
|
|
|
|
|
|
|
|
// Only collect when it's latest call
|
|
|
|
|
|
|
|
if (currentId !== heightUpdateId) return;
|
|
|
|
|
|
|
|
// let changed = false;
|
|
|
|
|
|
|
|
instance.forEach((element, key) => {
|
|
|
|
instance.forEach((element, key) => {
|
|
|
|
if (element && element.offsetParent) {
|
|
|
|
if (element && element.offsetParent) {
|
|
|
|
const { offsetHeight } = element;
|
|
|
|
const { offsetHeight } = element;
|
|
|
@ -57,6 +58,9 @@ export default function useHeights<T>(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
|
|
cancelRaf();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return [setInstance, collectHeight, heights, updatedMark];
|
|
|
|
return [setInstance, collectHeight, heights, updatedMark];
|
|
|
|
}
|
|
|
|
}
|
|
|
|