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.

1 lines
9.4 KiB

{"ast":null,"code":"import { computed, unref } from 'vue';\nimport { sum, enforceUnit } from '../utils.mjs';\nimport { isNumber } from '../../../../utils/types.mjs';\nimport { addUnit } from '../../../../utils/dom/style.mjs';\nconst useStyles = (props, {\n columnsTotalWidth,\n rowsHeight,\n fixedColumnsOnLeft,\n fixedColumnsOnRight\n}) => {\n const bodyWidth = computed(() => {\n const {\n fixed,\n width,\n vScrollbarSize\n } = props;\n const ret = width - vScrollbarSize;\n return fixed ? Math.max(Math.round(unref(columnsTotalWidth)), ret) : ret;\n });\n const headerWidth = computed(() => unref(bodyWidth) + props.vScrollbarSize);\n const mainTableHeight = computed(() => {\n const {\n height = 0,\n maxHeight = 0,\n footerHeight: footerHeight2,\n hScrollbarSize\n } = props;\n if (maxHeight > 0) {\n const _fixedRowsHeight = unref(fixedRowsHeight);\n const _rowsHeight = unref(rowsHeight);\n const _headerHeight = unref(headerHeight);\n const total = _headerHeight + _fixedRowsHeight + _rowsHeight + hScrollbarSize;\n return Math.min(total, maxHeight - footerHeight2);\n }\n return height - footerHeight2;\n });\n const fixedTableHeight = computed(() => {\n const {\n maxHeight\n } = props;\n const tableHeight = unref(mainTableHeight);\n if (isNumber(maxHeight) && maxHeight > 0) return tableHeight;\n const totalHeight = unref(rowsHeight) + unref(headerHeight) + unref(fixedRowsHeight);\n return Math.min(tableHeight, totalHeight);\n });\n const mapColumn = column => column.width;\n const leftTableWidth = computed(() => sum(unref(fixedColumnsOnLeft).map(mapColumn)));\n const rightTableWidth = computed(() => sum(unref(fixedColumnsOnRight).map(mapColumn)));\n const headerHeight = computed(() => sum(props.headerHeight));\n const fixedRowsHeight = computed(() => {\n var _a;\n return (((_a = props.fixedData) == null ? void 0 : _a.length) || 0) * props.rowHeight;\n });\n const windowHeight = computed(() => {\n return unref(mainTableHeight) - unref(headerHeight) - unref(fixedRowsHeight);\n });\n const rootStyle = computed(() => {\n const {\n style = {},\n height,\n width\n } = props;\n return enforceUnit({\n ...style,\n height,\n width\n });\n });\n const footerHeight = computed(() => enforceUnit({\n height: props.footerHeight\n }));\n const emptyStyle = computed(() => ({\n top: addUnit(unref(headerHeight)),\n bottom: addUnit(props.footerHeight),\n width: addUnit(props.width)\n }));\n return {\n bodyWidth,\n fixedTableHeight,\n mainTableHeight,\n leftTableWidth,\n rightTableWidth,\n headerWidth,\n windowHeight,\n footerHeight,\n emptyStyle,\n rootStyle,\n headerHeight\n };\n};\nexport { useStyles };","map":{"version":3,"names":["useStyles","props","columnsTotalWidth","rowsHeight","fixedColumnsOnLeft","fixedColumnsOnRight","bodyWidth","computed","fixed","width","vScrollbarSize","ret","Math","max","round","unref","headerWidth","mainTableHeight","height","maxHeight","footerHeight","footerHeight2","hScrollbarSize","_fixedRowsHeight","fixedRowsHeight","_rowsHeight","_headerHeight","headerHeight","total","min","fixedTableHeight","tableHeight","isNumber","totalHeight","mapColumn","column","leftTableWidth","sum","map","rightTableWidth","_a","fixedData","length","rowHeight","windowHeight","rootStyle","style","enforceUnit","emptyStyle","top","addUnit","bottom"],"sources":["../../../../../../../packages/components/table-v2/src/composables/use-styles.ts"],"sourcesContent":["import { ComputedRef, computed, unref } from 'vue'\nimport { addUnit, isNumber } from '@element-plus/utils'\nimport { enforceUnit, sum } from '../utils'\n\nimport type { CSSProperties } from 'vue'\nimport type { TableV2Props } from '../table'\nimport type { UseColumnsReturn } from './use-columns'\n\ntype UseStyleProps = {\n columnsTotalWidth: UseColumnsReturn['columnsTotalWidth']\n fixedColumnsOnLeft: UseColumnsReturn['fixedColumnsOnLeft']\n fixedColumnsOnRight: UseColumnsReturn['fixedColumnsOnRight']\n rowsHeight: ComputedRef<number>\n}\n\nexport const useStyles = (\n props: TableV2Props,\n {\n columnsTotalWidth,\n rowsHeight,\n fixedColumnsOnLeft,\n fixedColumnsOnRight,\n }: UseStyleProps\n) => {\n const bodyWidth = computed(() => {\n const { fixed, width, vScrollbarSize } = props\n const ret = width - vScrollbarSize\n return fixed ? Math.max(Math.round(unref(columnsTotalWidth)), ret) : ret\n })\n\n const headerWidth = computed(() => unref(bodyWidth) + props.vScrollbarSize)\n\n const mainTableHeight = computed(() => {\n const { height = 0, maxHeight = 0, footerHeight, hScrollbarSize } = props\n\n if (maxHeight > 0) {\n const _fixedRowsHeight = unref(fixedRowsHeight)\n const _rowsHeight = unref(rowsHeight)\n const _headerHeight = unref(headerHeight)\n const total =\n _headerHeight + _fixedRowsHeight + _rowsHeight + hScrollbarSize\n\n return Math.min(total, maxHeight - footerHeight)\n }\n\n return height - footerHeight\n })\n\n const fixedTableHeight = computed(() => {\n const { maxHeight } = props\n const tableHeight = unref(mainTableHeight)\n if (isNumber(maxHeight) && maxHeight > 0) return tableHeight\n\n const totalHeight =\n unref(rowsHeight) + unref(headerHeight) + unref(fixedRowsHeight)\n\n return Math.min(tableHeight, totalHeight)\n })\n\n const mapColumn = (column: TableV2Props['columns'][number]) => column.width\n\n const leftTableWidth = computed(() =>\n sum(unref(fixedColumnsOnLeft).map(mapColumn))\n )\n\n const rightTableWidth = computed(() =>\n sum(unref(fixedColumnsOnRight).map(mapColumn))\n )\n\n const headerHeight = computed(() => sum(props.headerHeight))\n\n const fixedRowsHeight = computed(() => {\n return (props.fixedData?.length || 0) * props.rowHeight\n })\n\n const windowHeight = computed(() => {\n return unref(mainTableHeight) - unref(headerHeight) - unref(fixedRowsHeight)\n })\n\n const rootStyle = computed<CSSProperties>(() => {\n const { style = {}, height, width } = props\n return enforceUnit({\n ...style,\n height,\n width,\n })\n })\n\n const footerHeight = computed(() =>\n enforceUnit({ height: props.footerHeight })\n )\n\n const emptyStyle = computed<CSSProperties>(() => ({\n top: addUnit(unref(headerHeight)),\n bottom: addUnit(props.footerHeight),\n width: addUnit(props.width),\n }))\n\n return {\n bodyWidth,\n fixedTableHeight,\n mainTableHeight,\n leftTableWidth,\n rightTableWidth,\n headerWidth,\n windowHeight,\n footerHeight,\n emptyStyle,\n rootSt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