vuestic-ui
Version:
Vue 3 UI Framework
1 lines • 3.43 kB
Source Map (JSON)
{"version":3,"file":"useTableScroll.mjs","sources":["../../../../../../src/components/va-data-table/hooks/useTableScroll.ts"],"sourcesContent":["import { getCurrentInstance, computed, ExtractPropTypes } from 'vue'\n\nimport { useIntersectionObserver, useElementRef, useNumericProp } from '../../../composables'\n\nexport const useTableScrollProps = {\n scrollTopMargin: { type: [Number, String], default: 0 },\n scrollBottomMargin: { type: [Number, String], default: 0 },\n}\n\nexport const useTableScrollEmits = ['scroll:top', 'scroll:bottom']\n\nexport const useTableScroll = (\n props: ExtractPropTypes<typeof useTableScrollProps>,\n emit: (event: 'scroll:bottom' | 'scroll:top', ...args: any[]) => void,\n) => {\n // NOTE: unfortunately, this is not reactive\n // TODO: replace 'vNodeProps' with '$listeners' when it's available in vue 3\n const vNodeProps = getCurrentInstance()?.vnode.props\n const doRenderTopTrigger = vNodeProps?.['onScroll:top'] !== undefined\n const doRenderBottomTrigger = vNodeProps?.['onScroll:bottom'] !== undefined\n\n const scrollContainer = useElementRef()\n const topTrigger = useElementRef()\n const bottomTrigger = useElementRef()\n const scrollTopMarginComputed = useNumericProp('scrollTopMargin')\n const scrollBottomMarginComputed = useNumericProp('scrollBottomMargin')\n\n const isObservable = computed(() => !!scrollContainer.value)\n\n const intersectionHandler = (entries: IntersectionObserverEntry[]) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n entry.target === topTrigger.value\n ? emit('scroll:top')\n : emit('scroll:bottom')\n }\n })\n }\n\n const targets = computed<HTMLElement[]>(() => {\n const list: HTMLElement[] = []\n\n if (isObservable.value) {\n topTrigger.value && list.push(topTrigger.value)\n bottomTrigger.value && list.push(bottomTrigger.value)\n }\n\n return list\n })\n\n const options = computed<IntersectionObserverInit>(() => ({\n root: scrollContainer.value,\n rootMargin: `${scrollTopMarginComputed.value ?? 0}px 0px ${scrollBottomMarginComputed.value ?? 0}px 0px`,\n }))\n\n useIntersectionObserver(intersectionHandler, options, targets)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