UNPKG

tdesign-vue

Version:
239 lines (235 loc) 10.4 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import { h as helper } from '../_chunks/dep-6a4dc7bb.js'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, toRefs, computed } from '@vue/composition-api'; import { pick, get, camelCase } from 'lodash-es'; import TrElement, { TABLE_PROPS, ROW_LISTENERS } from './tr.js'; import { useConfig } from '../config-provider/useConfig.js'; import { useTNodeJSX } from '../hooks/tnode.js'; import useClassName from './hooks/useClassName.js'; import baseTableProps from './base-table-props.js'; import useRowspanAndColspan from './hooks/useRowspanAndColspan.js'; import '@babel/runtime/helpers/typeof'; import './utils.js'; import './hooks/useFixed.js'; import '@babel/runtime/helpers/slicedToArray'; 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 './ellipsis.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 '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-ba613a02.js'; import '../_chunks/dep-fdb1b253.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; import '../utils/mixins.js'; import '../utils/event.js'; import '../popup/utils.js'; import '../utils/map-props.js'; import '../utils/withInstall.js'; import '../hooks/useLazyLoad.js'; import '../_common/js/utils/observe.js'; import '../hooks/render-tnode.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 ROW_AND_TD_LISTENERS = ROW_LISTENERS.concat("cell-click"); var extendTableProps = ["bordered", "rowKey", "rowClassName", "rowAttributes", "loading", "empty", "fixedRows", "firstFullRow", "lastFullRow", "rowspanAndColspan", "scroll", "cellEmptyContent", "pagination", "attach", "onCellClick", "onPageChange", "onRowClick", "onRowDblclick", "onRowMouseover", "onRowMousedown", "onRowMouseenter", "onRowMouseleave", "onRowMouseup", "onScroll", "onScrollX", "onScrollY"]; var TBody = defineComponent({ name: "TBody", props: _objectSpread({ classPrefix: String, ellipsisOverlayClassName: String, data: Array, columns: Array, rowAndColFixedPosition: Map, showColumnShadow: Object, tableElm: {}, tableWidth: Number, isWidthOverflow: Boolean, virtualConfig: Object, tableContentElm: {}, handleRowMounted: Function, renderExpandedRow: Function, firstFullRow: [String, Function], lastFullRow: [String, Function], activeRow: Array, hoverRow: [String, Number] }, pick(baseTableProps, extendTableProps)), setup: function setup(props, _ref) { var emit = _ref.emit; var renderTNode = useTNodeJSX(); var _toRefs = toRefs(props), data = _toRefs.data, columns = _toRefs.columns, rowKey = _toRefs.rowKey, rowspanAndColspan = _toRefs.rowspanAndColspan; var _useConfig = useConfig("table", props.locale), t = _useConfig.t, global = _useConfig.global; var _useClassName = useClassName(), tableFullRowClasses = _useClassName.tableFullRowClasses, tableBaseClass = _useClassName.tableBaseClass; var _useRowspanAndColspan = useRowspanAndColspan(data, columns, rowKey, rowspanAndColspan), skipSpansMap = _useRowspanAndColspan.skipSpansMap; var tbodyClasses = computed(function () { return [tableBaseClass.body]; }); var isFixedLeftColumn = computed(function () { return props.isWidthOverflow && !!props.columns.find(function (col) { return col.fixed === "left"; }); }); var getTrListeners = function getTrListeners() { var trListeners = {}; ROW_AND_TD_LISTENERS.forEach(function (eventName) { var name = ["cell-click"].includes(eventName) ? eventName : "row-".concat(eventName); trListeners[name] = function (context) { emit(name, context); }; }); return trListeners; }; return { t: t, global: global, tableFullRowClasses: tableFullRowClasses, tbodyClasses: tbodyClasses, tableBaseClass: tableBaseClass, isFixedLeftColumn: isFixedLeftColumn, skipSpansMap: skipSpansMap, renderTNode: renderTNode, getTrListeners: getTrListeners }; }, render: function render(h) { var _this = this, _this$data, _this$data2, _this$data3, _this$virtualConfig, _this$virtualConfig2; var renderEmpty = function renderEmpty(h2, columns) { var showEmptyText = Boolean(_this.tableWidth && _this.tableWidth > 100) || "production" === "test"; var tableWidth = _this.bordered ? _this.tableWidth - 2 : _this.tableWidth; return h("tr", { "class": [_this.tableBaseClass.emptyRow, _defineProperty({}, _this.tableFullRowClasses.base, _this.isWidthOverflow)] }, [h("td", { "attrs": { "colspan": columns.length } }, [h("div", { "class": [_this.tableBaseClass.empty, _defineProperty({}, _this.tableFullRowClasses.innerFullRow, _this.isWidthOverflow)], "style": _this.isWidthOverflow ? { width: "".concat(tableWidth, "px") } : {} }, [showEmptyText ? _this.renderTNode("empty") || _this.t(_this.global.empty) : ""])])]); }; var getFullRow = function getFullRow(h2, columnLength2, type) { var tType = camelCase(type); var fullRowNode = _this.renderTNode(tType); if (["", null, void 0, false].includes(fullRowNode)) return null; var classes = [_this.tableFullRowClasses.base, _this.tableFullRowClasses[tType]]; var tableWidth = _this.bordered ? _this.tableWidth - 2 : _this.tableWidth; return h("tr", { "class": classes }, [h("td", { "attrs": { "colspan": columnLength2 } }, [h("div", { "class": _defineProperty({}, _this.tableFullRowClasses.innerFullRow, _this.isFixedToLeft), "style": _this.isFixedToLeft ? { width: "".concat(tableWidth, "px") } : {} }, [h("div", { "class": _this.tableFullRowClasses.innerFullElement }, [fullRowNode])])])]); }; var columnLength = this.columns.length; var dataLength = (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.length; var trNodeList = []; var properties = ["classPrefix", "ellipsisOverlayClassName", "rowAndColFixedPosition", "scroll", "tableElm", "tableContentElm", "pagination", "attach"]; (_this$data2 = this.data) === null || _this$data2 === void 0 || _this$data2.forEach(function (row, rowIndex) { var _this$activeRow; var rowKey = _this.rowKey || "id"; var rowValue = get(row, rowKey); var trProps = _objectSpread(_objectSpread({}, pick(_this.$props, TABLE_PROPS)), {}, { rowKey: rowKey, row: row, columns: _this.columns, rowIndex: (row === null || row === void 0 ? void 0 : row.__VIRTUAL_SCROLL_INDEX) || rowIndex, dataLength: dataLength, skipSpansMap: _this.skipSpansMap, virtualConfig: _this.virtualConfig, active: (_this$activeRow = _this.activeRow) === null || _this$activeRow === void 0 ? void 0 : _this$activeRow.includes(rowValue), isHover: _this.hoverRow === rowValue }, pick(_this.$props, properties)); if (_this.onCellClick) { trProps.onCellClick = _this.onCellClick; } var on = _this.getTrListeners(); if (_this.handleRowMounted) { on["row-mounted"] = _this.handleRowMounted; } var trNode = h(TrElement, helper([{ "scopedSlots": _this.$scopedSlots, "key": get(row, _this.rowKey || "id") }, { "on": on }, {}, { "props": trProps }])); trNodeList.push(trNode); if (_this.renderExpandedRow) { var p = { row: row, index: rowIndex, columns: _this.columns, tableWidth: _this.tableWidth, isWidthOverflow: _this.isWidthOverflow }; var expandedContent = _this.renderExpandedRow(h, p); expandedContent && trNodeList.push(expandedContent); } }); var list = [getFullRow(h, columnLength, "first-full-row"), trNodeList, getFullRow(h, columnLength, "last-full-row")]; var isEmpty = !((_this$data3 = this.data) !== null && _this$data3 !== void 0 && _this$data3.length) && !this.loading && !this.firstFullRow && !this.lastFullRow; var translate = "translateY(".concat((_this$virtualConfig = this.virtualConfig) === null || _this$virtualConfig === void 0 ? void 0 : _this$virtualConfig.translateY.value, "px)"); var posStyle = (_this$virtualConfig2 = this.virtualConfig) !== null && _this$virtualConfig2 !== void 0 && _this$virtualConfig2.isVirtualScroll.value ? { transform: translate, "-ms-transform": translate, "-moz-transform": translate, "-webkit-transform": translate } : void 0; return h("tbody", { "class": this.tbodyClasses, "style": _objectSpread({}, posStyle) }, [isEmpty ? renderEmpty(h, this.columns) : list]); } }); export { ROW_AND_TD_LISTENERS, TBody as default, extendTableProps }; //# sourceMappingURL=tbody.js.map