This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { onMount, type Snippet, tick } from 'svelte';
|
||||
|
||||
export let onUpdate: () => Promise<any> = Promise.resolve;
|
||||
let { children, onUpdate }: { children: Snippet; onUpdate: () => Promise<any> } = $props();
|
||||
|
||||
let bodyElem: HTMLTableSectionElement;
|
||||
let intersectionElem: HTMLElement;
|
||||
|
||||
let intersectionObserver: IntersectionObserver;
|
||||
|
||||
let intersectionElement: HTMLElement;
|
||||
async function getIntersectionElement(): Promise<HTMLElement> {
|
||||
if (!bodyElem.lastElementChild) {
|
||||
await new Promise<void>((resolve) => {
|
||||
@@ -26,10 +24,10 @@
|
||||
await onUpdate();
|
||||
await tick();
|
||||
|
||||
intersectionObserver = new IntersectionObserver(
|
||||
const intersectionObserver = new IntersectionObserver(
|
||||
async (entries, observer) => {
|
||||
if (entries.filter((e) => e.isIntersecting).length === 0 || !entries) return;
|
||||
observer.unobserve(intersectionElement);
|
||||
observer.unobserve(intersectionElem);
|
||||
|
||||
const rows = bodyElem.rows.length;
|
||||
|
||||
@@ -37,7 +35,7 @@
|
||||
await tick();
|
||||
|
||||
if (rows === bodyElem.rows.length) return;
|
||||
observer.observe((intersectionElement = await getIntersectionElement()));
|
||||
observer.observe((intersectionElem = await getIntersectionElement()));
|
||||
},
|
||||
{ threshold: 0.25 }
|
||||
);
|
||||
@@ -51,14 +49,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (intersectionElement) intersectionObserver.unobserve(intersectionElement);
|
||||
intersectionObserver.observe((intersectionElement = await getIntersectionElement()));
|
||||
if (intersectionElem) intersectionObserver.unobserve(intersectionElem);
|
||||
intersectionObserver.observe((intersectionElem = await getIntersectionElement()));
|
||||
}).observe(bodyElem, { childList: true });
|
||||
|
||||
intersectionObserver.observe((intersectionElement = await getIntersectionElement()));
|
||||
intersectionObserver.observe((intersectionElem = await getIntersectionElement()));
|
||||
});
|
||||
</script>
|
||||
|
||||
<tbody bind:this={bodyElem}>
|
||||
<slot />
|
||||
{@render children()}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user