@webitel/ui-chats 0.1.48 → 0.1.49
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/package.json
CHANGED
|
@@ -3,15 +3,17 @@ import { onUnmounted, type Ref } from 'vue';
|
|
|
3
3
|
/**
|
|
4
4
|
* @author PolinaSukhorukova-webitel
|
|
5
5
|
*
|
|
6
|
-
* Fires the callback on every resize and
|
|
7
|
-
*
|
|
6
|
+
* Fires the callback on every resize of the target element and stops
|
|
7
|
+
* either after the given timeout or on unmount.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export const useObserveHeightUntilStable = (
|
|
11
|
-
|
|
11
|
+
target: Ref<HTMLElement | null>,
|
|
12
12
|
callback: () => void,
|
|
13
|
+
timeout?: number,
|
|
13
14
|
) => {
|
|
14
15
|
let observer: ResizeObserver | null = null;
|
|
16
|
+
let stopTimer: ReturnType<typeof setTimeout> | null = null;
|
|
15
17
|
let isViewportTransition = false;
|
|
16
18
|
let viewportTransitionTimer: ReturnType<typeof setTimeout> | null = null;
|
|
17
19
|
|
|
@@ -29,29 +31,25 @@ export const useObserveHeightUntilStable = (
|
|
|
29
31
|
const stopObserve = () => {
|
|
30
32
|
observer?.disconnect();
|
|
31
33
|
observer = null;
|
|
34
|
+
|
|
35
|
+
if (stopTimer) {
|
|
36
|
+
clearTimeout(stopTimer);
|
|
37
|
+
stopTimer = null;
|
|
38
|
+
}
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
const startObserve = () => {
|
|
35
|
-
if (!
|
|
36
|
-
|
|
37
|
-
let lastClientHeight: number | undefined = chatContainer.value.clientHeight;
|
|
38
|
-
let stableCount = 0;
|
|
42
|
+
if (!target.value) return;
|
|
39
43
|
|
|
40
44
|
observer = new ResizeObserver(() => {
|
|
41
|
-
const currentClientHeight = chatContainer.value?.clientHeight;
|
|
42
|
-
|
|
43
45
|
if (!isViewportTransition) callback();
|
|
44
|
-
|
|
45
|
-
if (currentClientHeight === lastClientHeight) {
|
|
46
|
-
stableCount++;
|
|
47
|
-
if (stableCount >= 2) stopObserve();
|
|
48
|
-
} else {
|
|
49
|
-
stableCount = 0;
|
|
50
|
-
lastClientHeight = currentClientHeight;
|
|
51
|
-
}
|
|
52
46
|
});
|
|
53
47
|
|
|
54
|
-
observer.observe(
|
|
48
|
+
observer.observe(target.value);
|
|
49
|
+
|
|
50
|
+
if (timeout !== undefined) {
|
|
51
|
+
stopTimer = setTimeout(stopObserve, timeout);
|
|
52
|
+
}
|
|
55
53
|
};
|
|
56
54
|
|
|
57
55
|
/**
|