{"version":3,"file":"use-scrollbar.mjs","sources":["../../../../../../../packages/components/table-v2/src/composables/use-scrollbar.ts"],"sourcesContent":["import { ref, unref, watch } from 'vue'\n\nimport type { Ref } from 'vue'\nimport type { Alignment as ScrollStrategy } from '@element-plus/components/virtual-list'\nimport type { TableV2Props } from '../table'\nimport type { TableGridInstance } from '../table-grid'\n\nexport type ScrollPos = { scrollLeft: number; scrollTop: number }\ntype GridInstanceRef = Ref\n\ntype UseScrollBarProps = {\n mainTableRef: GridInstanceRef\n leftTableRef: GridInstanceRef\n rightTableRef: GridInstanceRef\n\n onMaybeEndReached: () => void\n}\n\nexport type { ScrollStrategy }\n\nexport const useScrollbar = (\n props: TableV2Props,\n {\n mainTableRef,\n leftTableRef,\n rightTableRef,\n onMaybeEndReached,\n }: UseScrollBarProps\n) => {\n const scrollPos = ref({ scrollLeft: 0, scrollTop: 0 })\n\n function doScroll(params: ScrollPos) {\n const { scrollTop } = params\n\n mainTableRef.value?.scrollTo(params)\n leftTableRef.value?.scrollToTop(scrollTop)\n rightTableRef.value?.scrollToTop(scrollTop)\n }\n\n // methods\n function scrollTo(params: ScrollPos) {\n scrollPos.value = params\n\n doScroll(params)\n }\n\n function scrollToTop(scrollTop: number) {\n scrollPos.value.scrollTop = scrollTop\n\n doScroll(unref(scrollPos))\n }\n\n function scrollToLeft(scrollLeft: number) {\n scrollPos.value.scrollLeft = scrollLeft\n\n mainTableRef.value?.scrollTo?.(unref(scrollPos))\n }\n\n function onScroll(params: ScrollPos) {\n scrollTo(params)\n props.onScroll?.(params)\n }\n\n function onVerticalScroll({ scrollTop }: ScrollPos) {\n const { scrollTop: currentScrollTop } = unref(scrollPos)\n if (scrollTop !== currentScrollTop) scrollToTop(scrollTop)\n }\n\n function scrollToRow(row: number, strategy: ScrollStrategy = 'auto') {\n mainTableRef.value?.scrollToRow(row, strategy)\n }\n\n // When scrollTop changes, maybe reaching the bottom\n watch(\n () => unref(scrollPos).scrollTop,\n (cur, prev) => {\n if (cur > prev)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