You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
20 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, inject, provide, unref, createVNode, ref, computed } from 'vue';\nimport { TableV2InjectionKey } from './tokens.mjs';\nimport { tableV2GridProps } from './grid.mjs';\nimport { sum } from './utils.mjs';\nimport Header from './components/header.mjs';\nimport DynamicSizeGrid from '../../virtual-list/src/components/dynamic-size-grid.mjs';\nimport FixedSizeGrid from '../../virtual-list/src/components/fixed-size-grid.mjs';\nimport { isObject } from '@vue/shared';\nimport { isNumber } from '../../../utils/types.mjs';\nconst COMPONENT_NAME = \"ElTableV2Grid\";\nconst useTableGrid = props => {\n const headerRef = ref();\n const bodyRef = ref();\n const scrollLeft = ref(0);\n const totalHeight = computed(() => {\n const {\n data,\n rowHeight,\n estimatedRowHeight\n } = props;\n if (estimatedRowHeight) {\n return;\n }\n return data.length * rowHeight;\n });\n const fixedRowHeight = computed(() => {\n const {\n fixedData,\n rowHeight\n } = props;\n return ((fixedData == null ? void 0 : fixedData.length) || 0) * rowHeight;\n });\n const headerHeight = computed(() => sum(props.headerHeight));\n const gridHeight = computed(() => {\n const {\n height\n } = props;\n return Math.max(0, height - unref(headerHeight) - unref(fixedRowHeight));\n });\n const hasHeader = computed(() => {\n return unref(headerHeight) + unref(fixedRowHeight) > 0;\n });\n const itemKey = ({\n data,\n rowIndex\n }) => data[rowIndex][props.rowKey];\n function onItemRendered({\n rowCacheStart,\n rowCacheEnd,\n rowVisibleStart,\n rowVisibleEnd\n }) {\n var _a;\n (_a = props.onRowsRendered) == null ? void 0 : _a.call(props, {\n rowCacheStart,\n rowCacheEnd,\n rowVisibleStart,\n rowVisibleEnd\n });\n }\n function resetAfterRowIndex(index, forceUpdate2) {\n var _a;\n (_a = bodyRef.value) == null ? void 0 : _a.resetAfterRowIndex(index, forceUpdate2);\n }\n function scrollTo(leftOrOptions, top) {\n const header$ = unref(headerRef);\n const body$ = unref(bodyRef);\n if (isObject(leftOrOptions)) {\n header$ == null ? void 0 : header$.scrollToLeft(leftOrOptions.scrollLeft);\n scrollLeft.value = leftOrOptions.scrollLeft;\n body$ == null ? void 0 : body$.scrollTo(leftOrOptions);\n } else {\n header$ == null ? void 0 : header$.scrollToLeft(leftOrOptions);\n scrollLeft.value = leftOrOptions;\n body$ == null ? void 0 : body$.scrollTo({\n scrollLeft: leftOrOptions,\n scrollTop: top\n });\n }\n }\n function scrollToTop(scrollTop) {\n var _a;\n (_a = unref(bodyRef)) == null ? void 0 : _a.scrollTo({\n scrollTop\n });\n }\n function scrollToRow(row, strategy) {\n var _a;\n (_a = unref(bodyRef)) == null ? void 0 : _a.scrollToItem(row, 1, strategy);\n }\n function forceUpdate() {\n var _a, _b;\n (_a = unref(bodyRef)) == null ? void 0 : _a.$forceUpdate();\n (_b = unref(headerRef)) == null ? void 0 : _b.$forceUpdate();\n }\n return {\n bodyRef,\n forceUpdate,\n fixedRowHeight,\n gridHeight,\n hasHeader,\n headerHeight,\n headerRef,\n totalHeight,\n itemKey,\n onItemRendered,\n resetAfterRowIndex,\n scrollTo,\n scrollToTop,\n scrollToRow,\n scrollLeft\n };\n};\nconst TableGrid = defineComponent({\n name: COMPONENT_NAME,\n props: tableV2GridProps,\n setup(props, {\n slots,\n expose\n }) {\n const {\n ns\n } = inject(TableV2InjectionKey);\n const {\n bodyRef,\n fixedRowHeight,\n gridHeight,\n hasHeader,\n headerRef,\n headerHeight,\n totalHeight,\n forceUpdate,\n itemKey,\n onItemRendered,\n resetAfterRowIndex,\n scrollTo,\n scrollToTop,\n scrollToRow,\n scrollLeft\n } = useTableGrid(props);\n provide(\"tableV2GridScrollLeft\", scrollLeft);\n expose({\n forceUpdate,\n totalHeight,\n scrollTo,\n scrollToTop,\n scrollToRow,\n r