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.
|
|
{"ast":null,"code":"import { ref, isRef, nextTick } from 'vue';\nimport { isNull } from 'lodash-unified';\nimport { parseHeight } from './util.mjs';\nimport { hasOwn, isString } from '@vue/shared';\nimport { isClient } from '@vueuse/core';\nimport { isNumber } from '../../../utils/types.mjs';\nclass TableLayout {\n constructor(options) {\n this.observers = [];\n this.table = null;\n this.store = null;\n this.columns = [];\n this.fit = true;\n this.showHeader = true;\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].value = options[name];\n } else {\n this[name] = 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 updateScrollY() {\n const height = this.height.value;\n if (isNull(height)) return false;\n const scrollBarRef = this.table.refs.scrollBarRef;\n if (this.table.vnode.el && (scrollBarRef == null ? void 0 : scrollBarRef.wrapRef)) {\n let scrollY = true;\n const prevScrollY = this.scrollY.value;\n scrollY = scrollBarRef.wrapRef.scrollHeight > scrollBarRef.wrapRef.clientHeight;\n this.scrollY.value = scrollY;\n return prevScrollY !== scrollY;\n }\n return false;\n }\n setHeight(value, prop = \"height\") {\n if (!isClient) return;\n const el = this.table.vnode.el;\n value = parseHeight(value);\n this.height.value = Number(value);\n if (!el && (value || value === 0)) return nextTick(() => this.setHeight(value, prop));\n if (isNumber(value)) {\n el.style[prop] = `${value}px`;\n this.updateElsHeight();\n } else if (isString(value)) {\n el.style[prop] = value;\n this.updateElsHeight();\n }\n }\n setMaxHeight(value) {\n this.setHeight(value, \"max-height\");\n }\n getFlattenColumns() {\n const flattenColumns = [];\n const columns = this.table.store.states.columns.value;\n columns.forEach(column => {\n if (column.isColumnGroup) {\n flattenColumns.push.apply(flattenColumns, column.columns);\n } else {\n flattenColumns.push(column);\n }\n });\n return flattenColumns;\n }\n updateElsHeight() {\n this.updateScrollY();\n this.notifyObservers(\"scrollable\");\n }\n headerDisplayNone(elm) {\n if (!elm) return true;\n let headerChild = elm;\n while (headerChild.tagName !== \"DIV\") {\n if (getComputedStyle(headerChild).display === \"none\") {\n return true;\n }\n headerChild = headerChild.parentElement;\n }\n return false;\n }\n updateColumnsWidth() {\n if (!isClient) return;\n const fit = this.fit;\n const bodyWidth = this.table.vnode.el.clientWidth;\n let bodyMinWidth = 0;\n const flattenColumns = this.getFlattenColumns();\n const flexColumns = flattenColumns.filter(column => !isNumber(column.width));\n flattenColumns.forEach(column => {\n if (isNumber(column.width) && column.realWidth) column.realWidth = null;\n });\n if (flexColumns.length > 0 && fit) {\n flattenColumns.forEach(column => {\n bodyMinWidth += Number(column.width || column.minWidth || 80);\n });\n if (bodyMinWidth <= bodyWidth) {\n this.scrollX.value = false;\n const totalFlexWidth = bodyWidth - bodyMinWidth;\n if (flexColumns.length === 1) {\n flexColumns[0].realWidth = Number(flexColumns[0].minWidth || 80) + totalFlexWidth;\n } else {\n const allColumnsWidth = flexColumns.reduce((prev, column) => prev + Number(column.minWidth || 80), 0);\n const flexWidthPerPixel = totalFlexWidth / allColumnsWidth;\n let noneFirstWidth = 0;\n flexCo
|