forked from vrtmrz/obsidian-tagfolder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnDemandRender.svelte
53 lines (48 loc) · 1020 Bytes
/
OnDemandRender.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<script lang="ts">
import { performHide } from "store";
import { getContext, onDestroy, onMount } from "svelte";
export let cssClass = "";
export let isVisible = false;
let hidingScheduled = false;
const { observe, unobserve } = getContext("observer") as {
observe: (el: Element, callback: (visibility: boolean) => void) => void;
unobserve: (el: Element) => void;
};
function setIsVisible(visibility: boolean) {
if (isVisible != visibility) {
if (visibility) {
isVisible = visibility;
}
}
hidingScheduled = !visibility;
}
onMount(() => {
performHide.subscribe(() => {
if (hidingScheduled) {
isVisible = false;
hidingScheduled = false;
}
});
});
onDestroy(() => {
if (_el) {
unobserve(_el);
}
});
let _el: HTMLDivElement;
let el: HTMLDivElement;
$: {
if (_el != el) {
if (_el) {
unobserve(_el);
}
_el = el;
if (el) {
observe(el, setIsVisible);
}
}
}
</script>
<div class={cssClass} bind:this={el}>
<slot {isVisible} />
</div>