{"version":3,"file":"use-columns.js","sources":["../../../../../../../packages/components/table-v2/src/composables/use-columns.ts"],"sourcesContent":["// @ts-nocheck\nimport { computed, unref } from 'vue'\nimport { isObject } from '@element-plus/utils'\nimport { SortOrder, oppositeOrderMap } from '../constants'\nimport { placeholderSign } from '../private'\nimport { calcColumnStyle } from './utils'\n\nimport type { CSSProperties, Ref } from 'vue'\nimport type { TableV2Props } from '../table'\nimport type { AnyColumns, Column, KeyType } from '../types'\n\nfunction useColumns(\n props: TableV2Props,\n columns: Ref,\n fixed: Ref\n) {\n const _columns = computed(() =>\n unref(columns).map((column, index) => ({\n ...column,\n key: column.key ?? column.dataKey ?? index,\n }))\n )\n\n const visibleColumns = computed(() => {\n return unref(_columns).filter((column) => !column.hidden)\n })\n\n const fixedColumnsOnLeft = computed(() =>\n unref(visibleColumns).filter(\n (column) => column.fixed === 'left' || column.fixed === true\n )\n )\n\n const fixedColumnsOnRight = computed(() =>\n unref(visibleColumns).filter((column) => column.fixed === 'right')\n )\n\n const normalColumns = computed(() =>\n unref(visibleColumns).filter((column) => !column.fixed)\n )\n\n const mainColumns = computed(() => {\n const ret: AnyColumns = []\n\n unref(fixedColumnsOnLeft).forEach((column) => {\n ret.push({\n ...column,\n placeholderSign,\n })\n })\n\n unref(normalColumns).forEach((column) => {\n ret.push(column)\n })\n\n unref(fixedColumnsOnRight).forEach((column) => {\n ret.push({\n ...column,\n placeholderSign,\n })\n })\n\n return ret\n })\n\n const hasFixedColumns = computed(() => {\n return unref(fixedColumnsOnLeft).length || unref(fixedColumnsOnRight).length\n })\n\n const columnsStyles = computed(() => {\n return unref(_columns).reduce['key'], CSSProperties>>(\n (style, column) => {\n style[column.key] = calcColumnStyle(column, unref(fixed), props.fixed)\n return style\n },\n {}\n )\n })\n\n const columnsTotalWidth = computed(() => {\n return unref(visibleColumns).reduce(\n (width, column) => width + column.width,\n 0\n )\n })\n\n const getColumn = (key: KeyType) => {\n return unref(_columns).find((column) => column.key === key)\n }\n\n const getColumnStyle = (key: KeyType) => {\n return unref(columnsStyles)[key]\n }\n\n const updateColumnWidth = (column: Column, width: number) => {\n column.width = width\n }\n\n function onColumnSorted(e: MouseEvent) {\n const { key } = (e.currentTarget as HTMLElement).dataset\n if (!key) return\n const { sortState, sortBy } = props\n\n let order = SortOrder.ASC\n\n if (isObject(sortState)) {\n order = oppositeOrderMap[sortState[key]]\n } else {\n order = oppositeOrderMap[sortBy.order]\n }\n\n props.onColumnSort?.({ column: getColumn(key)!, key, order })\n }\n\n return {\n columns: _columns,\n columnsStyles,\n columnsTotalWidth,\n fixedColumnsOnLeft,\n fixedColumnsOnRight,\n hasFixedColumns,\n mainColumns,\n normalColumns,\n visibleColumns,\n\n getColumn,\n getColumnStyle,\n updateColumnWidth,\n onColumnSorted,\n }\n}\n\nexport { useColumns }\nexport type UseColumnsReturn = ReturnType\n"],"names":["computed","unref","placeholderSign","calcColumnStyle","SortOrder","isObject","oppositeOrderMap"],"mappings":";;;;;;;;;;;AAKA,SAAS,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;AAC3C,EAAE,MAAM,QAAQ,GAAGA,YAAQ,CAAC,MAAMC,SAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,KAAK;AACxE,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC;AACf,IAAI,OAAO;AACX,MAAM,GAAG,MAAM;AACf,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,KAAK,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,OAAO,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK;AACtF,KAAK,CAAC;AACN,GAAG,CAAC,CAAC,CAAC;AACN,EAAE,MAAM,cAAc,GAAGD,YAAQ,CAAC,MAAM;AACxC,IAAI,OAAOC,SAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,MAA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