{"version":3,"file":"render-helper.js","sources":["../../../../../../../packages/components/table/src/table-column/render-helper.ts"],"sourcesContent":["// @ts-nocheck\nimport {\n Comment,\n computed,\n getCurrentInstance,\n h,\n ref,\n renderSlot,\n unref,\n watchEffect,\n} from 'vue'\nimport { debugWarn } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport {\n cellForced,\n defaultRenderCell,\n getDefaultClassName,\n treeCellPrefix,\n} from '../config'\nimport { parseMinWidth, parseWidth } from '../util'\nimport type { ComputedRef } from 'vue'\nimport type { TableColumn, TableColumnCtx } from './defaults'\n\nfunction useRender(\n props: TableColumnCtx,\n slots,\n owner: ComputedRef\n) {\n const instance = getCurrentInstance() as TableColumn\n const columnId = ref('')\n const isSubColumn = ref(false)\n const realAlign = ref()\n const realHeaderAlign = ref()\n const ns = useNamespace('table')\n watchEffect(() => {\n realAlign.value = props.align ? `is-${props.align}` : null\n // nextline help render\n realAlign.value\n })\n watchEffect(() => {\n realHeaderAlign.value = props.headerAlign\n ? `is-${props.headerAlign}`\n : realAlign.value\n // nextline help render\n realHeaderAlign.value\n })\n const columnOrTableParent = computed(() => {\n let parent: any = instance.vnode.vParent || instance.parent\n while (parent && !parent.tableId && !parent.columnId) {\n parent = parent.vnode.vParent || parent.parent\n }\n return parent\n })\n const hasTreeColumn = computed(() => {\n const { store } = instance.parent\n if (!store) return false\n const { treeData } = store.states\n const treeDataValue = treeData.value\n return treeDataValue && Object.keys(treeDataValue).length > 0\n })\n\n const realWidth = ref(parseWidth(props.width))\n const realMinWidth = ref(parseMinWidth(props.minWidth))\n const setColumnWidth = (column: TableColumnCtx) => {\n if (realWidth.value) column.width = realWidth.value\n if (realMinWidth.value) {\n column.minWidth = realMinWidth.value\n }\n if (!realWidth.value && realMinWidth.value) {\n column.width = undefined\n }\n if (!column.minWidth) {\n column.minWidth = 80\n }\n column.realWidth = Number(\n column.width === undefined ? column.minWidth : column.width\n )\n return column\n }\n const setColumnForcedProps = (column: TableColumnCtx) => {\n // 对于特定类型的 column,某些属性不允许设置\n const type = column.type\n const source = cellForced[type] || {}\n Object.keys(source).forEach((prop) => {\n const value = source[prop]\n if (prop !== 'className' && value !== undefined) {\n column[prop] = value\n }\n })\n const className = getDefaultClassName(type)\n if (className) {\n const forceClass = `${unref(ns.namespace)}-${className}`\n column.className = column.className\n ? `${column.className} ${forceClass}`\n : forceClass\n }\n return column\n }\n\n const checkSubColumn = (children: TableColumn | TableColumn[]) => {\n if (Array.isArray(children)) {\n children.forEach((child) => check(child))\n } else {\n check(children)\n }\n function check(item: TableColumn) {\n if (item?.type?.name === 'ElTableColumn') {\n item.vParent = instance\n }\n }\n }\n const setColumnRenders = (column: TableColumnCtx) => {\n // renderHeader 属性不推荐使用。\n if (props.renderHeader) {\n debugWarn(\n 'TableColumn',\n 'Comparing to render-header, scoped-slot header is easier to use. We recommend users to use scoped-slot header.'\n )\n } else if (column.type !== 'selection') {\n column.renderHeader = (scope) => {\n // help render\n instance.columnConfig.value['label']\n return renderSlot(slots, 'header', scope, () => [column.label])\n }\n }\n\n if (slots['filter-icon']) {\n column.renderFilterIcon = (scope) => {\n return renderSlot(slots, 'filter-icon', scope)\n }\n }\n\n let originRenderCell = column.renderCell\n // TODO: 这里的实现调整\n if (column.type === 'expand') {\n // 对于展开行,renderCell 不允许配置的。在上一步中已经设置过,这里需要简单封装一下。\n column.renderCell = (data) =>\n h(\n 'div',\n {\n class: 'cell',\n },\n [originRenderCell(data)]\n )\n owner.value.renderExpanded = (data) => {\n return slots.default ? slots.default(data) : slots.default\n }\n } else {\n originRenderCell = originRenderCell || defaultRenderCell\n // 对 renderCell 进行包装\n column.renderCell = (data) => {\n let children = null\n if (slots.default) {\n const vnodes = slots.default(data)\n children = vnodes.some((v) => v.type !== Comment)\n ? vnodes\n : originRenderCell(data)\n } else {\n children = originRenderCell(data)\n }\n\n const { columns } = owner.value.store.states\n const firstUserColumnIndex = columns.value.findIndex(\n (item) => item.type === 'default'\n )\n const shouldCreatePlaceholder =\n hasTreeColumn.value && data.cellIndex === firstUserColumnIndex\n const prefix = treeCellPrefix(data, shouldCreatePlaceholder)\n const props = {\n class: 'cell',\n style: {},\n }\n if (column.showOverflowTooltip) {\n props.class = `${props.class} ${unref(ns.namespace)}-tooltip`\n props.style = {\n width: `${\n (data.column.realWidth || Number(data.column.width)) - 1\n }px`,\n }\n }\n checkSubColumn(children)\n return h('div', props, [prefix, children])\n }\n }\n return column\n }\n const getPropsData = (...propsKey: unknown[]) => {\n return propsKey.reduce((prev, cur) => {\n if (Array.isArray(cur)) {\n cur.forEach((key) => {\n prev[key] = props[key]\n })\n }\n return prev\n }, {})\n }\n const getColumnElIndex = (children, child) => {\n return Array.prototype.indexOf.call(children, child)\n }\n\n const updateColumnOrder = () => {\n owner.value.store.commit('updateColumnOrder', instance.columnConfig.value)\n }\n\n return {\n columnId,\n realAlign,\n isSubColumn,\n realHeaderAlign,\n columnOrTableParent,\n setColumnWidth,\n setColumnForcedProps,\n setColumnRenders,\n getPropsData,\n getColumnElIndex,\n updateColumnOrder,\n }\n}\n\nexport default useRender\n"],"names":["getCurrentInstance","ref","useNamespace","watchEffect","computed","parseWidth","parseMinWidth","cellForced","getDefaultClassName","unref","debugWarn","renderSlot","h","defaultRenderCell","Comment","treeCellPrefix"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;AACxC,EAAE,MAAM,QAAQ,GAAGA,sBAAkB,EAAE,CAAC;AACxC,EAAE,MAAM,QAAQ,GAAGC,OAAG,CAAC,EAAE,CAAC,CAAC;AAC3B,EAAE,MAAM,WAAW,GAAGA,OAAG,CAAC,KAAK,CAAC,CAAC;AACjC,EAAE,MAAM,SAAS,GAAGA,OAAG,EAAE,CAAC;AAC1B,EAAE,MAAM,eAAe,GAAGA,OAAG,EAAE,CAAC;AAChC,EAAE,MAAM,EAAE,GAAGC,kBAAY,CAAC,OAAO,CAAC,CAAC;AACnC,EAAEC,eAAW,CAA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