Work on export and moving to Vue composition API

This commit is contained in:
N-Pex 2025-06-27 16:10:25 +02:00
parent b0fae3396d
commit 9a124c5ab9
22 changed files with 660 additions and 906 deletions

View file

@ -0,0 +1,39 @@
import { ComponentInstance, onBeforeUnmount, Ref, ref, ShallowRef, watch } from "vue";
import Intersect, { ObserveDirectiveBinding } from "vuetify/directives/intersect";
export const useLazyLoad = (props: { root: Readonly<ShallowRef<ComponentInstance<any>>> }) => {
const isVisible: Ref<boolean> = ref(false);
const binding: Ref<ObserveDirectiveBinding | undefined> = ref(undefined);
watch(
props.root,
(newval: ComponentInstance<any>) => {
if (newval && !binding.value) {
const binding: ObserveDirectiveBinding = {
modifiers: {
once: false,
quiet: false,
},
value(isIntersecting, entries, observer) {
isVisible.value = isIntersecting;
},
instance: newval,
oldValue: undefined,
dir: {},
};
Intersect.mounted(newval.$el, binding);
}
},
{ immediate: true }
);
onBeforeUnmount(() => {
if (binding.value && binding.value.instance) {
Intersect.unmounted(binding.value.instance.$el, binding.value);
}
});
return {
isVisible,
};
};