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
13 KiB
1 lines
13 KiB
{"ast":null,"code":"import { inject } from 'vue';\nimport { getFixedColumnOffset, ensurePosition, getFixedColumnsClass } from '../util.mjs';\nimport { TABLE_INJECTION_KEY } from '../tokens.mjs';\nimport { useNamespace } from '../../../../hooks/use-namespace/index.mjs';\nimport { isFunction, isString, isArray, isObject } from '@vue/shared';\nfunction useStyles(props) {\n const parent = inject(TABLE_INJECTION_KEY);\n const ns = useNamespace(\"table\");\n const getRowStyle = (row, rowIndex) => {\n const rowStyle = parent == null ? void 0 : parent.props.rowStyle;\n if (isFunction(rowStyle)) {\n return rowStyle.call(null, {\n row,\n rowIndex\n });\n }\n return rowStyle || null;\n };\n const getRowClass = (row, rowIndex) => {\n const classes = [ns.e(\"row\")];\n if ((parent == null ? void 0 : parent.props.highlightCurrentRow) && row === props.store.states.currentRow.value) {\n classes.push(\"current-row\");\n }\n if (props.stripe && rowIndex % 2 === 1) {\n classes.push(ns.em(\"row\", \"striped\"));\n }\n const rowClassName = parent == null ? void 0 : parent.props.rowClassName;\n if (isString(rowClassName)) {\n classes.push(rowClassName);\n } else if (isFunction(rowClassName)) {\n classes.push(rowClassName.call(null, {\n row,\n rowIndex\n }));\n }\n return classes;\n };\n const getCellStyle = (rowIndex, columnIndex, row, column) => {\n const cellStyle = parent == null ? void 0 : parent.props.cellStyle;\n let cellStyles = cellStyle != null ? cellStyle : {};\n if (isFunction(cellStyle)) {\n cellStyles = cellStyle.call(null, {\n rowIndex,\n columnIndex,\n row,\n column\n });\n }\n const fixedStyle = getFixedColumnOffset(columnIndex, props == null ? void 0 : props.fixed, props.store);\n ensurePosition(fixedStyle, \"left\");\n ensurePosition(fixedStyle, \"right\");\n return Object.assign({}, cellStyles, fixedStyle);\n };\n const getCellClass = (rowIndex, columnIndex, row, column, offset) => {\n const fixedClasses = getFixedColumnsClass(ns.b(), columnIndex, props == null ? void 0 : props.fixed, props.store, void 0, offset);\n const classes = [column.id, column.align, column.className, ...fixedClasses];\n const cellClassName = parent == null ? void 0 : parent.props.cellClassName;\n if (isString(cellClassName)) {\n classes.push(cellClassName);\n } else if (isFunction(cellClassName)) {\n classes.push(cellClassName.call(null, {\n rowIndex,\n columnIndex,\n row,\n column\n }));\n }\n classes.push(ns.e(\"cell\"));\n return classes.filter(className => Boolean(className)).join(\" \");\n };\n const getSpan = (row, column, rowIndex, columnIndex) => {\n let rowspan = 1;\n let colspan = 1;\n const fn = parent == null ? void 0 : parent.props.spanMethod;\n if (isFunction(fn)) {\n const result = fn({\n row,\n column,\n rowIndex,\n columnIndex\n });\n if (isArray(result)) {\n rowspan = result[0];\n colspan = result[1];\n } else if (isObject(result)) {\n rowspan = result.rowspan;\n colspan = result.colspan;\n }\n }\n return {\n rowspan,\n colspan\n };\n };\n const getColspanRealWidth = (columns, colspan, index) => {\n if (colspan < 1) {\n return columns[index].realWidth;\n }\n const widthArr = columns.map(({\n realWidth,\n width\n }) => realWidth || width).slice(index, index + colspan);\n return Number(widthArr.reduce((acc, width) => Number(acc) + Number(width), -1));\n };\n return {\n getRowStyle,\n getRowClass,\n getCellStyle,\n getCellClass,\n getSpan,\n getColspanRealWidth\n };\n}\nexport { useStyles as default };","map":{"version":3,"names":["useStyles","props","parent","inject","TABLE_INJECTION_KEY","ns","useNamespace","getRowStyle","row","rowIndex","rowStyle","isFunction","call","getRowClass","classes","e","highlightCurrentRow","store","states","currentRow","value","push","stripe","em","rowClassName","isString","getCellStyle","columnIndex","column","cellStyle","cellStyles","fixedStyle","getFixedColumnOffset","fixed","ensurePosition","Object","assign","getCellClass","offset","fixedClasses","getFixedColumnsClass","b","id","align","className","cellClassName","filter","Boolean","join","getSpan","rowspan","colspan","fn","spanMethod","result","isArray","isObject","getColspanRealWidth","columns","index","realWidth","widthArr","map","width","slice","Number","reduce","acc"],"sources":["../../../../../../../packages/components/table/src/table-body/styles-helper.ts"],"sourcesContent":["// @ts-nocheck\nimport { inject } from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { isArray, isFunction, isObject, isString } from '@element-plus/utils'\nimport {\n ensurePosition,\n getFixedColumnOffset,\n getFixedColumnsClass,\n} from '../util'\nimport { TABLE_INJECTION_KEY } from '../tokens'\nimport type { TableColumnCtx } from '../table-column/defaults'\nimport type { TableBodyProps } from './defaults'\n\nfunction useStyles<T>(props: Partial<TableBodyProps<T>>) {\n const parent = inject(TABLE_INJECTION_KEY)\n const ns = useNamespace('table')\n\n const getRowStyle = (row: T, rowIndex: number) => {\n const rowStyle = parent?.props.rowStyle\n if (isFunction(rowStyle)) {\n return rowStyle.call(null, {\n row,\n rowIndex,\n })\n }\n return rowStyle || null\n }\n\n const getRowClass = (row: T, rowIndex: number) => {\n const classes = [ns.e('row')]\n if (\n parent?.props.highlightCurrentRow &&\n row === props.store.states.currentRow.value\n ) {\n classes.push('current-row')\n }\n\n if (props.stripe && rowIndex % 2 === 1) {\n classes.push(ns.em('row', 'striped'))\n }\n const rowClassName = parent?.props.rowClassName\n if (isString(rowClassName)) {\n classes.push(rowClassName)\n } else if (isFunction(rowClassName)) {\n classes.push(\n rowClassName.call(null, {\n row,\n rowIndex,\n })\n )\n }\n return classes\n }\n\n const getCellStyle = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx<T>\n ) => {\n const cellStyle = parent?.props.cellStyle\n let cellStyles = cellStyle ?? {}\n if (isFunction(cellStyle)) {\n cellStyles = cellStyle.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n }\n const fixedStyle = getFixedColumnOffset(\n columnIndex,\n props?.fixed,\n props.store\n )\n ensurePosition(fixedStyle, 'left')\n ensurePosition(fixedStyle, 'right')\n return Object.assign({}, cellStyles, fixedStyle)\n }\n\n const getCellClass = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx<T>,\n offset: number\n ) => {\n const fixedClasses = getFixedColumnsClass(\n ns.b(),\n columnIndex,\n props?.fixed,\n props.store,\n undefined,\n offset\n )\n const classes = [column.id, column.align, column.className, ...fixedClasses]\n const cellClassName = parent?.props.cellClassName\n if (isString(cellClassName)) {\n classes.push(cellClassName)\n } else if (isFunction(cellClassName)) {\n classes.push(\n cellClassName.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n )\n }\n classes.push(ns.e('cell'))\n return classes.filter((className) => Boolean(className)).join(' ')\n }\n const getSpan = (\n row: T,\n column: TableColumnCtx<T>,\n rowIndex: number,\n columnIndex: number\n ) => {\n let rowspan = 1\n let colspan = 1\n const fn = parent?.props.spanMethod\n if (isFunction(fn)) {\n const result = fn({\n row,\n column,\n rowIndex,\n columnIndex,\n })\n if (isArray(result)) {\n rowspan = result[0]\n colspan = result[1]\n } else if (isObject(result)) {\n rowspan = result.rowspan\n colspan = result.colspan\n }\n }\n return { rowspan, colspan }\n }\n const getColspanRealWidth = (\n columns: TableColumnCtx<T>[],\n colspan: number,\n index: number\n ): number => {\n if (colspan < 1) {\n return columns[index].realWidth\n }\n const widthArr = columns\n .map(({ realWidth, width }) => realWidth || width)\n .slice(index, index + colspan)\n return Number(\n widthArr.reduce((acc, width) => Number(acc) + Number(width), -1)\n )\n }\n\n return {\n getRowStyle,\n getRowClass,\n getCellStyle,\n getCellClass,\n getSpan,\n getColspanRealWidth,\n }\n}\n\nexport default useStyles\n"],"mappings":";;;;;AASA,SAASA,SAASA,CAACC,KAAK,EAAE;EACxB,MAAMC,MAAM,GAAGC,MAAM,CAACC,mBAAmB,CAAC;EAC1C,MAAMC,EAAE,GAAGC,YAAY,CAAC,OAAO,CAAC;EAChC,MAAMC,WAAW,GAAGA,CAACC,GAAG,EAAEC,QAAQ,KAAK;IACrC,MAAMC,QAAQ,GAAGR,MAAM,IAAI,IAAI,GAAG,KAAK,CAAC,GAAGA,MAAM,CAACD,KAAK,CAACS,QAAQ;IAChE,IAAIC,UAAU,CAACD,QAAQ,CAAC,EAAE;MACxB,OAAOA,QAAQ,CAACE,IAAI,CAAC,IAAI,EAAE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