UNPKG

tdesign-vue

Version:
241 lines (237 loc) 11 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import { h as helper } from '../_chunks/dep-323b993c.js'; import _typeof from '@babel/runtime/helpers/typeof'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, ref, computed } from '@vue/composition-api'; import { isFunction } from 'lodash-es'; import { getColumnFixedStyles } from './hooks/useFixed.js'; import useClassName from './hooks/useClassName.js'; import { renderTitle } from './hooks/useTableHeader.js'; import TEllipsis from './ellipsis.js'; import { formatClassNames } from './utils.js'; import '@babel/runtime/helpers/slicedToArray'; import '../_common/js/log/index.js'; import '../_common/js/log/log.js'; import '../_common/js/utils/getScrollbarWidth.js'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../utils/dom.js'; import 'vue'; import 'raf'; import '../utils/easing.js'; import '../config-provider/useConfig.js'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-c44a474d.js'; import '../_chunks/dep-d639fbd7.js'; import 'dayjs'; import '../_chunks/dep-3c66615e.js'; import '../config-provider/type.js'; import '../_common/js/global-config/t.js'; import './hooks/useMultiHeader.js'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '../tooltip/index.js'; import '../tooltip/tooltip.js'; import '../tooltip/props.js'; import '../popup/props.js'; import '../popup/popup.js'; import '@popperjs/core'; import '../utils/helper.js'; import '../_common/js/utils/setStyle.js'; import '../popup/container.js'; import '../config-provider/config-receiver.js'; import '../utils/mixins.js'; import '../utils/event.js'; import '../popup/utils.js'; import '../utils/map-props.js'; import '../utils/withInstall.js'; import './style/css.js'; import '../tooltip/type.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var THead = defineComponent({ name: "THead", props: { ellipsisOverlayClassName: String, isFixedHeader: Boolean, thDraggable: Boolean, maxHeight: [String, Number], height: [String, Number], rowAndColFixedPosition: Map, thWidthList: Object, bordered: Boolean, isMultipleHeader: Boolean, resizable: Boolean, spansAndLeafNodes: Object, thList: Array, columnResizeParams: Object, attach: [String, Function], showColumnShadow: Object }, setup: function setup(props, _ref) { var slots = _ref.slots; var theadRef = ref(); var classnames = useClassName(); var tableHeaderClasses = classnames.tableHeaderClasses, tableBaseClass = classnames.tableBaseClass; var theadClasses = computed(function () { return [tableHeaderClasses.header, _defineProperty(_defineProperty(_defineProperty({}, tableHeaderClasses.fixed, Boolean(props.maxHeight || props.height)), tableBaseClass.bordered, props.bordered && props.isMultipleHeader), tableHeaderClasses.multipleHeader, props.isMultipleHeader)]; }); var colspanSkipMap = computed(function () { var map = {}; var _processColumns = function processColumns(columns) { for (var i = 0, len = columns.length; i < len; i++) { var item = columns[i]; if (item.colspan > 1) { for (var j = i + 1; j < i + item.colspan; j++) { if (columns[j]) { map[columns[j].colKey] = true; } } } if (item.children) { _processColumns(item.children); } } }; var list = props.thList[0]; _processColumns(list); return map; }); var getTableNode = function getTableNode(thead) { var parent = thead; while (parent) { var _parent; parent = parent.parentNode; if ((_parent = parent) !== null && _parent !== void 0 && (_parent = _parent.classList) !== null && _parent !== void 0 && _parent.contains("".concat(props.classPrefix, "-table"))) { break; } } return parent; }; return _objectSpread(_objectSpread({}, classnames), {}, { colspanSkipMap: colspanSkipMap, theadRef: theadRef, theadClasses: theadClasses, slots: slots, getTableNode: getTableNode }); }, render: function render(h) { var _this = this; var renderThNodeList = function renderThNodeList(h2, rowAndColFixedPosition, thWidthList) { var thBorderMap = /* @__PURE__ */new Map(); var thRowspanAndColspan = _this.spansAndLeafNodes.rowspanAndColspanMap; return _this.thList.map(function (row, rowIndex) { var thRow = row.map(function (col, index) { var _col$children; if (_this.colspanSkipMap[col.colKey]) return null; var rowspanAndColspan = thRowspanAndColspan.get(col); if (index === 0 && rowspanAndColspan.rowspan > 1) { for (var j = rowIndex + 1; j < rowIndex + rowspanAndColspan.rowspan; j++) { thBorderMap.set(_this.thList[j][0], true); } } var thStyles = getColumnFixedStyles(col, index, rowAndColFixedPosition, _this.tableColFixedClasses); var colParams = { col: col, colIndex: index, row: {}, rowIndex: -1 }; var customClasses = formatClassNames(col.className, _objectSpread(_objectSpread({}, colParams), {}, { type: "th" })); var thCustomClasses = formatClassNames(col.thClassName, _objectSpread(_objectSpread({}, colParams), {}, { type: "th" })); var isLeftFixedActive = _this.showColumnShadow.left && col.fixed === "left"; var isRightFixedActive = _this.showColumnShadow.right && col.fixed === "right"; var canDragSort = _this.thDraggable && !(isLeftFixedActive || isRightFixedActive); var thClasses = [thStyles.classes, customClasses, thCustomClasses, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _this.tableHeaderClasses.thBordered, thBorderMap.get(col)), "".concat(_this.classPrefix, "-table__th-").concat(col.colKey), col.colKey), _this.tdAlignClasses[col.align], col.align && col.align !== "left"), _this.tableDraggableClasses.dragSortTh, canDragSort)]; var withoutChildren = !((_col$children = col.children) !== null && _col$children !== void 0 && _col$children.length); var width = withoutChildren && thWidthList !== null && thWidthList !== void 0 && thWidthList[col.colKey] ? "".concat(thWidthList === null || thWidthList === void 0 ? void 0 : thWidthList[col.colKey], "px") : void 0; var styles = _objectSpread(_objectSpread({}, thStyles.style || {}), {}, { width: width }); var innerTh = renderTitle(h2, _this.slots, col, index); var resizeColumnListener = _this.resizable || !canDragSort ? { mousedown: function mousedown(e) { e.stopPropagation(); if (_this.resizable) { var _this$columnResizePar, _this$columnResizePar2; (_this$columnResizePar = _this.columnResizeParams) === null || _this$columnResizePar === void 0 || (_this$columnResizePar2 = _this$columnResizePar.onColumnMousedown) === null || _this$columnResizePar2 === void 0 || _this$columnResizePar2.call(_this$columnResizePar, e, col, index); } if (!canDragSort) { var timer = setTimeout(function () { var _thList$index; var thList = _this.theadRef.querySelectorAll("th"); (_thList$index = thList[index]) === null || _thList$index === void 0 || _thList$index.removeAttribute("draggable"); clearTimeout(timer); }, 10); } }, mousemove: function mousemove(e) { var _this$columnResizePar3, _this$columnResizePar4; _this.resizable && ((_this$columnResizePar3 = _this.columnResizeParams) === null || _this$columnResizePar3 === void 0 || (_this$columnResizePar4 = _this$columnResizePar3.onColumnMouseover) === null || _this$columnResizePar4 === void 0 ? void 0 : _this$columnResizePar4.call(_this$columnResizePar3, e, col)); } } : {}; var content = isFunction(col.ellipsisTitle) ? col.ellipsisTitle(h2, { col: col, colIndex: index }) : void 0; var isEllipsis = col.ellipsisTitle !== void 0 ? Boolean(col.ellipsisTitle) : Boolean(col.ellipsis); var attrs = (isFunction(col.attrs) ? col.attrs(_objectSpread(_objectSpread({}, colParams), {}, { type: "th" })) : col.attrs) || {}; if (col.colspan > 1) { attrs.colspan = col.colspan; } return h("th", helper([{ "key": col.colKey, "attrs": { "data-colkey": col.colKey }, "class": thClasses, "style": styles }, { "attrs": _objectSpread(_objectSpread({}, attrs), rowspanAndColspan) }, {}, { "on": resizeColumnListener }]), [h("div", { "class": _this.tableBaseClass.thCellInner }, [isEllipsis ? h(TEllipsis, { "attrs": { "placement": "bottom", "attach": _this.attach || (_this.theadRef ? function () { return _this.getTableNode(_this.theadRef); } : void 0), "tooltipContent": content && function () { return content; }, "tooltipProps": _typeof(col.ellipsisTitle) === "object" ? col.ellipsisTitle : void 0, "overlayClassName": _this.ellipsisOverlayClassName, "classPrefix": _this.classPrefix } }, [innerTh]) : innerTh])]); }); return h("tr", { "key": rowIndex }, [thRow]); }); }; return h("thead", { "ref": "theadRef", "class": this.theadClasses }, [renderThNodeList(h, this.rowAndColFixedPosition, this.thWidthList)]); } }); export { THead as default }; //# sourceMappingURL=thead.js.map