Files
chuanggao-website/client/node_modules/element-plus/es/components/table/src/table-layout.mjs.map

1 line
12 KiB
Plaintext
Raw Normal View History

2026-05-12 16:53:18 +08:00
{"version":3,"file":"table-layout.mjs","names":[],"sources":["../../../../../../packages/components/table/src/table-layout.ts"],"sourcesContent":["import { isRef, nextTick, ref } from 'vue'\nimport { isNull } from 'lodash-unified'\nimport { hasOwn, isClient, isNumber, isString } from '@element-plus/utils'\nimport { parseHeight } from './util'\n\nimport type { Ref } from 'vue'\nimport type { TableColumnCtx } from './table-column/defaults'\nimport type { TableHeader } from './table-header'\nimport type { DefaultRow, Table } from './table/defaults'\nimport type { Store } from './store'\n\nclass TableLayout<T extends DefaultRow> {\n observers: TableHeader[]\n table: Table<T>\n store: Store<T>\n columns: TableColumnCtx<T>[]\n fit: boolean\n showHeader: boolean\n heightMap: Record<string, string | number | null>\n\n height: Ref<null | number>\n scrollX: Ref<boolean>\n scrollY: Ref<boolean>\n bodyWidth: Ref<null | number>\n fixedWidth: Ref<null | number>\n rightFixedWidth: Ref<null | number>\n tableHeight!: Ref<null | number>\n headerHeight!: Ref<null | number> // Table Header Height\n appendHeight!: Ref<null | number> // Append Slot Height\n footerHeight!: Ref<null | number> // Table Footer Height\n gutterWidth: number\n constructor(options: Record<string, any>) {\n this.observers = []\n this.table = null as unknown as Table<T>\n this.store = null as unknown as Store<T>\n this.columns = []\n this.fit = true\n this.showHeader = true\n this.heightMap = {}\n this.height = ref(null)\n this.scrollX = ref(false)\n this.scrollY = ref(false)\n this.bodyWidth = ref(null)\n this.fixedWidth = ref(null)\n this.rightFixedWidth = ref(null)\n this.gutterWidth = 0\n for (const name in options) {\n if (hasOwn(options, name)) {\n if (isRef(this[name])) {\n ;(this[name] as Ref).value = options[name]\n } else {\n this[name as keyof typeof this] = options[name]\n }\n }\n }\n if (!this.table) {\n throw new Error('Table is required for Table Layout')\n }\n if (!this.store) {\n throw new Error('Store is required for Table Layout')\n }\n }\n\n updateScrollY() {\n const height = this.height.value\n /**\n * When the height is not initialized, it is null.\n * After the table is initialized, when the height is not configured, the height is 0.\n */\n if (isNull(height)) return false\n const scrollBarRef = this.table.refs.scrollBarRef\n if (this.table.vnode.el && scrollBarRef?.wrapRef) {\n let scrollY = true\n const prevScrollY = this.scrollY.value\n scrollY =\n scrollBarRef.wrapRef.scrollHeight > scrollBarRef.wrapRef.clientHeight\n this.scrollY.value = scrollY\n return prevScrollY !== scrollY\n }\n return false\n }\n\n setHeight(value: string | number | null, prop = 'height') {\n if (!isClient) return\n const el = this.table.vnode.el\n value = parseHeight(value)\n this.height.value = Number(value)\n this.heightMap[prop] = value\n\n if (!el && (value || value === 0)) {\n nextTick(() => {\n if (this.heightMap[prop] === value) {\n this.setHeight(value, prop)\n }\n })\n return\n }\n\n if (el && isNumber(value)) {\n el.style[prop] = `${value}px`\n this.updateElsHeight()\n } else if (el && isString(value)) {\n el.style[prop] = value\n this.updateElsHeight()\n }\n }\n\n setMaxHeight(value: string | number | null) {\n this.setHeight(value, 'max-height')\n }\n\n getFlattenColumns(): TableColumnCtx<T>[] {\n const flattenColumns: TableColumnCtx<T>[] = []\n const columns = this.table.store.states.columns.value\n columns.forEach((column) => {\n if (column.isColumnGroup) {\n // eslint-disable-next-line prefer-spread\n flattenColumns.push.apply(flattenColumns, column.columns)\n } else {\n flattenColumns.push(column)\n }\n })\n\n return flattenColumns\n }\n\n updateElsHeight() {\n this.updateScrollY()\n this.notifyOb