{"version":3,"file":"use-table.js","sources":["../../../../../../packages/components/table-v2/src/use-table.ts"],"sourcesContent":["import {\n computed,\n getCurrentInstance,\n ref,\n shallowRef,\n toRef,\n unref,\n watch,\n} from 'vue'\nimport { isArray } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport {\n useColumns,\n useData,\n useRow,\n useScrollbar,\n useStyles,\n} from './composables'\n\nimport type { TableV2Props } from './table'\nimport type { TableGridInstance } from './table-grid'\n\nfunction useTable(props: TableV2Props) {\n const mainTableRef = ref()\n const leftTableRef = ref()\n const rightTableRef = ref()\n const {\n columns,\n columnsStyles,\n columnsTotalWidth,\n fixedColumnsOnLeft,\n fixedColumnsOnRight,\n hasFixedColumns,\n mainColumns,\n\n onColumnSorted,\n } = useColumns(props, toRef(props, 'columns'), toRef(props, 'fixed'))\n\n const {\n scrollTo,\n scrollToLeft,\n scrollToTop,\n scrollToRow,\n onScroll,\n onVerticalScroll,\n scrollPos,\n } = useScrollbar(props, {\n mainTableRef,\n leftTableRef,\n rightTableRef,\n\n onMaybeEndReached,\n })\n\n const ns = useNamespace('table-v2')\n const instance = getCurrentInstance()!\n\n // state\n const isScrolling = shallowRef(false)\n\n const {\n expandedRowKeys,\n lastRenderedRowIndex,\n isDynamic,\n isResetting,\n rowHeights,\n resetAfterIndex,\n onRowExpanded,\n onRowHeightChange,\n onRowHovered,\n onRowsRendered,\n } = useRow(props, {\n mainTableRef,\n leftTableRef,\n rightTableRef,\n tableInstance: instance,\n ns,\n isScrolling,\n })\n\n const { data, depthMap } = useData(props, {\n expandedRowKeys,\n lastRenderedRowIndex,\n resetAfterIndex,\n })\n\n const {\n bodyWidth,\n fixedTableHeight,\n mainTableHeight,\n leftTableWidth,\n rightTableWidth,\n headerWidth,\n rowsHeight,\n windowHeight,\n footerHeight,\n emptyStyle,\n rootStyle,\n headerHeight,\n } = useStyles(props, {\n columnsTotalWidth,\n data,\n fixedColumnsOnLeft,\n fixedColumnsOnRight,\n })\n\n // DOM/Component refs\n const containerRef = ref()\n\n const showEmpty = computed(() => {\n const noData = unref(data).length === 0\n\n return isArray(props.fixedData)\n ? props.fixedData.length === 0 && noData\n : noData\n })\n\n function getRowHeight(rowIndex: number) {\n const { estimatedRowHeight, rowHeight, rowKey } = props\n\n if (!estimatedRowHeight) return rowHeight\n\n return (\n unref(rowHeights)[unref(data)[rowIndex][rowKey]] || estimatedRowHeight\n )\n }\n\n function onMaybeEndReached() {\n const { onEndReached } = props\n if (!onEndReached) return\n\n const { scrollTop } = unref(scrollPos)\n\n const _totalHeight = unref(rowsHeight)\n const clientHeight = unref(windowHeight)\n\n const heightUntilEnd =\n _totalHeight - (scrollTop + clientHeight) + props.hScrollbarSize\n\n if (\n unref(lastRenderedRowIndex) >= 0 &&\n _totalHeight === scrollTop + unref(mainTableHeight) - unref(headerHeight)\n ) {\n onEndReached(heightUntilEnd)\n }\n }\n\n // events\n\n watch(\n () => props.expandedRowKeys,\n (val) => (expandedRowKeys.value = val),\n {\n deep: true,\n }\n )\n\n return {\n // models\n columns,\n containerRef,\n mainTableRef,\n leftTableRef,\n rightTableRef,\n // states\n isDynamic,\n isResetting,\n isScrolling,\n hasFixedColumns,\n // records\n columnsStyles,\n columnsTotalWidth,\n data,\n expandedRowKeys,\n depthMap,\n fixedColumnsOnLeft,\n fixedColumnsOnRight,\n mainColumns,\n // metadata\n bodyWidth,\n emptyStyle,\n rootStyle,\n headerWidth,\n footerHeight,\n mainTableHeight,\n fixedTableHeight,\n leftTableWidth,\n rightTableWidth,\n // flags\n showEmpty,\n\n // methods\n getRowHeight,\n\n // event handlers\n onColumnSorted,\n onRowHovered,\n onRowExpanded,\n onRowsRendered,\n onRowHeightChange,\n // use scrollbars\n scrollTo,\n scrollToLeft,\n scrollToTop,\n scrollToRow,\n onScroll,\n onVerticalScroll,\n }\n}\n\nexport { useTable }\n\nexport type UseTableReturn = ReturnType\n"],"names":["ref","useColumns","toRef","useScrollbar","useNamespace","getCurrentInstance","shallowRef","useRow","useData","useSt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