tdesign-vue-next
Version:
TDesign Component for vue-next
321 lines (317 loc) • 14.2 kB
JavaScript
/**
* tdesign v1.15.2
* (c) 2025 tdesign
* @license MIT
*/
import { defineComponent, toRefs, ref, computed, reactive, onMounted, nextTick, onUpdated, createVNode, mergeProps, h, isVNode } from 'vue';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { pick, get, isFunction, isString, upperFirst } from 'lodash-es';
import { formatRowAttributes, formatRowClassNames, formatClassNames } from '../utils/index.js';
import { getRowFixedStyles, getColumnFixedStyles } from '../hooks/useFixed.js';
import useClassName from '../hooks/useClassName.js';
import TEllipsis from './ellipsis.js';
import baseTableProps from '../base-table-props.js';
import useLazyLoad from '../hooks/useLazyLoad.js';
import { getCellKey } from '../hooks/useRowspanAndColspan.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../_chunks/dep-0ffe4637.js';
import '../../_chunks/dep-dbde60fa.js';
import '../../_chunks/dep-a72765fe.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../_chunks/dep-1f7ad104.js';
import '../../_chunks/dep-e604a5ce.js';
import '../../_chunks/dep-7fac49fa.js';
import '../../_chunks/dep-79c44a11.js';
import '../../config-provider/hooks/useConfig.js';
import '../../config-provider/utils/context.js';
import '../../_chunks/dep-3b49fbbe.js';
import 'dayjs';
import '../../_chunks/dep-7324137b.js';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/classCallCheck';
import '../../_chunks/dep-1d44782f.js';
import '../../_chunks/dep-6c13cc0e.js';
import '../../tooltip/index.js';
import '../../tooltip/tooltip.js';
import '../../tooltip/props.js';
import '../../popup/props.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../_chunks/dep-b9ab7399.js';
import '../../_chunks/dep-3ba91e12.js';
import '../../_chunks/dep-34e44a4e.js';
import '../../popup/container.js';
import '../../_chunks/dep-82e44120.js';
import '../../_chunks/dep-37a2e7c8.js';
import 'tdesign-vue-next/esm/common/style/web/components/popup/_index.less';
import '../../tooltip/utils/index.js';
import 'tdesign-vue-next/esm/common/style/web/components/tooltip/_index.less';
import '../../_chunks/dep-6f34ddfa.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; }
function _isSlot(s) {
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var TABLE_PROPS = ["rowKey", "rowClassName", "columns", "fixedRows", "footData", "rowAttributes", "rowspanAndColspan", "scroll", "cellEmptyContent", "pagination", "attach", "onCellClick", "onRowClick", "onRowDblclick", "onRowMouseover", "onRowMousedown", "onRowMouseenter", "onRowMouseleave", "onRowMouseup"];
var ROW_LISTENERS = ["click", "dblclick", "mouseover", "mousedown", "mouseenter", "mouseleave", "mouseup"];
function renderCell(params, slots, extra) {
var col = params.col,
row = params.row,
rowIndex = params.rowIndex;
if (col.colKey === "serial-number") {
var _ref = (extra === null || extra === void 0 ? void 0 : extra.pagination) || {},
current = _ref.current,
pageSize = _ref.pageSize,
defaultCurrent = _ref.defaultCurrent,
defaultPageSize = _ref.defaultPageSize;
var tCurrent = current || defaultCurrent;
var tPageSize = pageSize || defaultPageSize;
if (tPageSize && tCurrent) {
return tPageSize * (tCurrent - 1) + rowIndex + 1;
}
return rowIndex + 1;
}
if (isFunction(col.cell)) {
return col.cell(h, params);
}
if (slots[col.colKey]) {
return slots[col.colKey](params);
}
if (isString(col.cell) && slots[col.cell]) {
return slots[col.cell](params);
}
if (isFunction(col.render)) {
return col.render(h, _objectSpread(_objectSpread({}, params), {}, {
type: "cell"
}));
}
var r = get(row, col.colKey);
if (![void 0, "", null].includes(r)) return r;
if (extra !== null && extra !== void 0 && extra.cellEmptyContent) {
return isFunction(extra.cellEmptyContent) ? extra.cellEmptyContent(h, params) : extra.cellEmptyContent;
}
if (slots.cellEmptyContent) return slots.cellEmptyContent(params);
if (slots["cell-empty-content"]) return slots["cell-empty-content"](params);
return r;
}
var TrElement = defineComponent({
name: "TR",
props: _objectSpread(_objectSpread({
row: Object,
rowIndex: Number,
dataLength: Number,
ellipsisOverlayClassName: String,
classPrefix: String,
rowAndColFixedPosition: Map,
skipSpansMap: Map,
virtualConfig: Object,
active: Boolean,
isHover: Boolean
}, pick(baseTableProps, TABLE_PROPS)), {}, {
tableElm: {},
tableContentElm: {}
}),
emits: ["row-mounted"],
setup: function setup(props, context) {
var _toRefs = toRefs(props),
tableContentElm = _toRefs.tableContentElm,
active = _toRefs.active,
isHover = _toRefs.isHover;
var trRef = ref(null);
var _useClassName = useClassName(),
tdEllipsisClass = _useClassName.tdEllipsisClass,
tableBaseClass = _useClassName.tableBaseClass,
tableColFixedClasses = _useClassName.tableColFixedClasses,
tableRowFixedClasses = _useClassName.tableRowFixedClasses,
tdAlignClasses = _useClassName.tdAlignClasses,
tableDraggableClasses = _useClassName.tableDraggableClasses;
var trStyles = computed(function () {
return getRowFixedStyles(get(props.row, props.rowKey || "id"), props.rowIndex, props.dataLength, props.fixedRows, props.rowAndColFixedPosition, tableRowFixedClasses, props.virtualConfig.isVirtualScroll.value ? props.virtualConfig.translateY.value : 0);
});
var trAttributes = computed(function () {
return formatRowAttributes(props.rowAttributes, {
row: props.row,
rowIndex: props.rowIndex,
type: "body"
}) || {};
});
var classes = computed(function () {
var _trStyles$value;
var customClasses = formatRowClassNames(props.rowClassName, {
row: props.row,
rowKey: props.rowKey,
rowIndex: props.rowIndex,
type: "body"
}, props.rowKey || "id");
return [(_trStyles$value = trStyles.value) === null || _trStyles$value === void 0 ? void 0 : _trStyles$value.classes, customClasses, _defineProperty(_defineProperty({}, "".concat(props.classPrefix, "-table__row--active"), active.value), "".concat(props.classPrefix, "-table__row--hover"), isHover.value)].filter(function (v) {
return v;
});
});
var _useLazyLoad = useLazyLoad(tableContentElm, trRef, reactive(_objectSpread(_objectSpread({}, props.scroll), {}, {
rowIndex: props.rowIndex
}))),
hasLazyLoadHolder = _useLazyLoad.hasLazyLoadHolder,
tRowHeight = _useLazyLoad.tRowHeight;
var getTrListeners = function getTrListeners(row, rowIndex) {
var trListeners = {};
ROW_LISTENERS.forEach(function (eventName) {
trListeners["on".concat(upperFirst(eventName))] = function (e) {
var _props;
var p = {
e: e,
row: row,
index: rowIndex
};
(_props = props["onRow".concat(upperFirst(eventName))]) === null || _props === void 0 || _props.call(props, p);
};
});
return trListeners;
};
var notifyVirtualSizeUpdate = function notifyVirtualSizeUpdate() {
var _props$virtualConfig;
if ((_props$virtualConfig = props.virtualConfig) !== null && _props$virtualConfig !== void 0 && _props$virtualConfig.isVirtualScroll.value) {
context.emit("row-mounted", {
ref: trRef,
data: props.row
});
}
};
onMounted(function () {
nextTick(function () {
notifyVirtualSizeUpdate();
});
});
onUpdated(function () {
nextTick(function () {
notifyVirtualSizeUpdate();
});
});
function renderEllipsisCell(cellParams, params) {
var cellNode = params.cellNode;
var col = cellParams.col,
colIndex = cellParams.colIndex;
var content;
if (isFunction(col.ellipsis)) {
content = col.ellipsis(h, cellParams);
} else if (_typeof(col.ellipsis) === "object" && isFunction(col.ellipsis.content)) {
content = col.ellipsis.content(h, cellParams);
} else if (context.slots["ellipsis-".concat(col.colKey)]) {
content = context.slots["ellipsis-".concat(col.colKey)](cellParams);
} else if (context.slots.ellipsis) {
content = context.slots.ellipsis(cellParams);
}
var tooltipProps = {};
if (_typeof(col.ellipsis) === "object") {
tooltipProps = "props" in col.ellipsis ? col.ellipsis.props : col.ellipsis || void 0;
}
var tableElement = props.tableElm;
var placement = colIndex === 0 ? "top-left" : "top";
placement = colIndex === props.columns.length - 1 ? "top-right" : placement;
return createVNode(TEllipsis, {
"placement": placement,
"attach": tableElement ? function () {
return tableElement;
} : void 0,
"tooltipContent": content && function () {
return content;
},
"tooltipProps": tooltipProps,
"overlayClassName": props.ellipsisOverlayClassName,
"classPrefix": props.classPrefix
}, _isSlot(cellNode) ? cellNode : {
"default": function _default() {
return [cellNode];
}
});
}
function renderTd(params, extra) {
var col = params.col,
colIndex = params.colIndex,
rowIndex = params.rowIndex;
var cellSpans = extra.cellSpans,
dataLength = extra.dataLength,
rowAndColFixedPosition = extra.rowAndColFixedPosition;
var cellNode = renderCell(params, context.slots, {
cellEmptyContent: extra.cellEmptyContent,
pagination: props.pagination
});
var tdStyles = getColumnFixedStyles(col, colIndex, rowAndColFixedPosition, tableColFixedClasses);
var customClasses = formatClassNames(col.className, _objectSpread(_objectSpread({}, params), {}, {
type: "td"
}));
var classes2 = [tdStyles.classes, customClasses, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, tdEllipsisClass, col.ellipsis), tableBaseClass.tdLastRow, rowIndex + cellSpans.rowspan === dataLength), tableBaseClass.tdFirstCol, colIndex === 0 && props.rowspanAndColspan), tdAlignClasses[col.align], col.align && col.align !== "left"), tableDraggableClasses.handle, col.colKey === "drag")];
var onClick = function onClick(e) {
var _props$onCellClick;
var p = _objectSpread(_objectSpread({}, params), {}, {
e: e
});
if (col.stopPropagation) {
e.stopPropagation();
}
(_props$onCellClick = props.onCellClick) === null || _props$onCellClick === void 0 || _props$onCellClick.call(props, p);
};
var normalAttrs = isFunction(col.attrs) ? col.attrs(_objectSpread(_objectSpread({}, params), {}, {
type: "td"
})) : col.attrs;
var attrs = _objectSpread(_objectSpread({}, normalAttrs), cellSpans);
return createVNode("td", mergeProps({
"key": col.colKey || colIndex,
"class": classes2,
"style": tdStyles.style
}, attrs, {
"onClick": onClick
}), [col.ellipsis ? renderEllipsisCell(params, {
cellNode: cellNode
}) : cellNode]);
}
return function () {
var _trStyles$value2;
var columns = props.columns,
skipSpansMap = props.skipSpansMap,
row = props.row,
dataLength = props.dataLength,
rowAndColFixedPosition = props.rowAndColFixedPosition;
var columnVNodeList = columns === null || columns === void 0 ? void 0 : columns.map(function (col, colIndex) {
var cellSpans = {};
var params = {
row: row,
col: col,
rowIndex: props.rowIndex,
colIndex: colIndex
};
var spanState = null;
if (props.skipSpansMap.size) {
var _spanState, _spanState2;
var cellKey = getCellKey(row, props.rowKey, col.colKey, colIndex);
spanState = skipSpansMap.get(cellKey) || {};
((_spanState = spanState) === null || _spanState === void 0 ? void 0 : _spanState.rowspan) > 1 && (cellSpans.rowspan = spanState.rowspan);
((_spanState2 = spanState) === null || _spanState2 === void 0 ? void 0 : _spanState2.colspan) > 1 && (cellSpans.colspan = spanState.colspan);
if (spanState.skipped) return null;
}
return renderTd(params, {
dataLength: dataLength,
rowAndColFixedPosition: rowAndColFixedPosition,
columnLength: columns.length,
cellSpans: cellSpans,
cellEmptyContent: props.cellEmptyContent
});
});
return createVNode("tr", mergeProps({
"ref": trRef
}, trAttributes.value, {
"style": (_trStyles$value2 = trStyles.value) === null || _trStyles$value2 === void 0 ? void 0 : _trStyles$value2.style,
"class": classes.value
}, getTrListeners(row, props.rowIndex)), [hasLazyLoadHolder.value ? [createVNode("td", {
"style": {
height: "".concat(tRowHeight.value, "px"),
border: "none"
}
}, null)] : columnVNodeList]);
};
}
});
export { ROW_LISTENERS, TABLE_PROPS, TrElement as default, renderCell };
//# sourceMappingURL=tr.js.map