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.

0 lines
7.0 KiB

1 month ago
  1. {"ast":null,"code":"import { getCurrentInstance, watch } from 'vue';\nimport { parseWidth, parseMinWidth } from '../util.mjs';\nimport { hasOwn } from '@vue/shared';\nfunction getAllAliases(props, aliases) {\n return props.reduce((prev, cur) => {\n prev[cur] = cur;\n return prev;\n }, aliases);\n}\nfunction useWatcher(owner, props_) {\n const instance = getCurrentInstance();\n const registerComplexWatchers = () => {\n const props = [\"fixed\"];\n const aliases = {\n realWidth: \"width\",\n realMinWidth: \"minWidth\"\n };\n const allAliases = getAllAliases(props, aliases);\n Object.keys(allAliases).forEach(key => {\n const columnKey = aliases[key];\n if (hasOwn(props_, columnKey)) {\n watch(() => props_[columnKey], newVal => {\n let value = newVal;\n if (columnKey === \"width\" && key === \"realWidth\") {\n value = parseWidth(newVal);\n }\n if (columnKey === \"minWidth\" && key === \"realMinWidth\") {\n value = parseMinWidth(newVal);\n }\n instance.columnConfig.value[columnKey] = value;\n instance.columnConfig.value[key] = value;\n const updateColumns = columnKey === \"fixed\";\n owner.value.store.scheduleLayout(updateColumns);\n });\n }\n });\n };\n const registerNormalWatchers = () => {\n const props = [\"label\", \"filters\", \"filterMultiple\", \"filteredValue\", \"sortable\", \"index\", \"formatter\", \"className\", \"labelClassName\", \"filterClassName\", \"showOverflowTooltip\"];\n const aliases = {\n property: \"prop\",\n align: \"realAlign\",\n headerAlign: \"realHeaderAlign\"\n };\n const allAliases = getAllAliases(props, aliases);\n Object.keys(allAliases).forEach(key => {\n const columnKey = aliases[key];\n if (hasOwn(props_, columnKey)) {\n watch(() => props_[columnKey], newVal => {\n instance.columnConfig.value[key] = newVal;\n });\n }\n });\n };\n return {\n registerComplexWatchers,\n registerNormalWatchers\n };\n}\nexport { useWatcher as default };","map":{"version":3,"names":["getAllAliases","props","aliases","reduce","prev","cur","useWatcher","owner","props_","instance","getCurrentInstance","registerComplexWatchers","realWidth","realMinWidth","allAliases","Object","keys","forEach","key","columnKey","hasOwn","watch","newVal","value","parseWidth","parseMinWidth","columnConfig","updateColumns","store","scheduleLayout","registerNormalWatchers","property","align","headerAlign"],"sources":["../../../../../../../packages/components/table/src/table-column/watcher-helper.ts"],"sourcesContent":["// @ts-nocheck\nimport { getCurrentInstance, watch } from 'vue'\nimport { hasOwn } from '@element-plus/utils'\nimport { parseMinWidth, parseWidth } from '../util'\n\nimport type { ComputedRef } from 'vue'\nimport type { TableColumn, TableColumnCtx, ValueOf } from './defaults'\n\nfunction getAllAliases(props, aliases) {\n return props.reduce((prev, cur) => {\n prev[cur] = cur\n return prev\n }, aliases)\n}\nfunction useWatcher<T>(\n owner: ComputedRef<any>,\n props_: Partial<TableColumnCtx<T>>\n) {\n const instance = getCurrentInstance() as TableColumn<T>\n const registerComplexWatchers = () => {\n const props = ['fixed']\n const aliases = {\n realWidth: 'width',\n realMinWidth: 'minWidth',\n }\n const allAliases = getAllAliases(props, aliases)\n Object.keys(allAliases).forEach((key) => {\n const columnKey = aliases[key]\n if (hasOwn(props_, columnKey)) {\n watch(\n () => props_[columnKey],\n (newVal) => {\n let value: ValueOf<TableColumnCtx<T>> = newVal\n if (columnKey === 'width' && key === 'realWidth') {\n value = parseWidth(newVal)\n }\n if (columnKey === 'minWidth' && key === 'realMinWidth') {\n value = parseMinWidth(newVal)\n }\n instance.columnConfig.value[columnKey as any] = value\n instance.colu