482063b8bed034da1ff18413e53dc01040af4c477f501dcb717b6045d383f90fd239a67cd8f1710547b5a2de0023c220960b51e80a8da40d26a9420f76d245 7.1 KB

1
  1. {"version":3,"file":"header.js","sources":["../../../../../../../packages/components/table-v2/src/components/header.tsx"],"sourcesContent":["import {\n computed,\n defineComponent,\n inject,\n nextTick,\n onUpdated,\n ref,\n unref,\n} from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { ensureArray } from '@element-plus/utils'\nimport { tableV2HeaderProps } from '../header'\nimport { enforceUnit } from '../utils'\nimport { TABLE_V2_GRID_INJECTION_KEY } from '../tokens'\n\nimport type { CSSProperties, Ref, UnwrapRef } from 'vue'\nimport type { TableV2HeaderProps } from '../header'\nimport type { UseColumnsReturn } from '../composables/use-columns'\n\nconst COMPONENT_NAME = 'ElTableV2Header'\nconst TableV2Header = defineComponent({\n name: COMPONENT_NAME,\n props: tableV2HeaderProps,\n setup(props, { slots, expose }) {\n const ns = useNamespace('table-v2')\n const scrollLeftInfo = inject<Ref<number>>(TABLE_V2_GRID_INJECTION_KEY)\n\n const headerRef = ref<HTMLElement>()\n\n const headerStyle = computed(() =>\n enforceUnit({\n width: props.width,\n height: props.height,\n })\n )\n\n const rowStyle = computed(() =>\n enforceUnit({\n width: props.rowWidth,\n height: props.height,\n })\n )\n\n const headerHeights = computed(() => ensureArray(unref(props.headerHeight)))\n\n const scrollToLeft = (left?: number) => {\n const headerEl = unref(headerRef)\n nextTick(() => {\n headerEl?.scroll &&\n headerEl.scroll({\n left,\n })\n })\n }\n\n const renderFixedRows = () => {\n const fixedRowClassName = ns.e('fixed-header-row')\n\n const { columns, fixedHeaderData, rowHeight } = props\n\n return fixedHeaderData?.map((fixedRowData, fixedRowIndex) => {\n const style: CSSProperties = enforceUnit({\n height: rowHeight,\n width: '100%',\n })\n\n return slots.fixed?.({\n class: fixedRowClassName,\n columns,\n rowData: fixedRowData,\n rowIndex: -(fixedRowIndex + 1),\n style,\n })\n })\n }\n\n const renderDynamicRows = () => {\n const dynamicRowClassName = ns.e('dynamic-header-row')\n const { columns } = props\n\n return unref(headerHeights).map((rowHeight, rowIndex) => {\n const style: CSSProperties = enforceUnit({\n width: '100%',\n height: rowHeight,\n })\n\n return slots.dynamic?.({\n class: dynamicRowClassName,\n columns,\n headerIndex: rowIndex,\n style,\n })\n })\n }\n\n onUpdated(() => {\n if (scrollLeftInfo?.value) {\n scrollToLeft(scrollLeftInfo.value)\n }\n })\n expose({\n /**\n * @description scroll to position based on the provided value\n */\n scrollToLeft,\n })\n\n return () => {\n if (props.height <= 0) return\n\n return (\n <div\n ref={headerRef}\n class={props.class}\n style={unref(headerStyle)}\n role=\"rowgroup\"\n >\n <div style={unref(rowStyle)} class={ns.e('header')}>\n {renderDynamicRows()}\n {renderFixedRows()}\n </div>\n </div>\n )\n }\n },\n})\n\nexport default TableV2Header\n\nexport type TableV2HeaderInstance = InstanceType<typeof TableV2Header> & {\n /**\n * @description scroll to position based on the provided value\n */\n scrollToLeft: (left?: number) => void\n}\n\nexport type TableV2HeaderRendererParams = {\n class: string\n columns: TableV2HeaderProps['columns']\n columnsStyles: UnwrapRef<UseColumnsReturn['columnsStyles']>\n headerIndex: number\n style: CSSProperties\n}\n\nexport type TableV2HeaderRowRendererParams = {\n rowData: any\n rowIndex: number\n} & Omit<TableV2HeaderRendererParams, 'headerIndex'>\n"],"names":["COMPONENT_NAME","TableV2Header","defineComponent","name","props","tableV2HeaderProps","slots","expose","useNamespace","ns","inject","scrollLeftInfo","ref","headerRef","enforceUnit","computed","width","height","rowWidth","ensureArray","unref","headerHeights","scrollToLeft","nextTick","headerEl","left","renderFixedRows","rowHeight","fixedHeaderData","style","class","fixedRowClassName","columns","rowData","rowIndex","renderDynamicRows","headerIndex","onUpdated","_createVNode","headerStyle"],"mappings":";;;;;;;;;;;AAmBA,MAAMA,cAAc,GAAG,iBAAvB,CAAA;AACA,MAAMC,aAAa,GAAGC,mBAAe,CAAC;AACpCC,EAAAA,IAAI,EAAEH,cAD8B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