tdesign-react
Version:
TDesign Component for React
218 lines (214 loc) • 10.2 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _typeof } from '../_chunks/dep-eca3a3de.js';
import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js';
import React, { useRef, useMemo } from 'react';
import { isFunction } from 'lodash-es';
import classNames from 'classnames';
import { getColumnFixedStyles } from './hooks/useFixed.js';
import useClassName from './hooks/useClassName.js';
import { renderTitle } from './hooks/useTableHeader.js';
import Ellipsis from './Ellipsis.js';
import { formatClassNames } from './utils.js';
import '../_chunks/dep-48805ab8.js';
import '../_chunks/dep-026a4c6b.js';
import '../_chunks/dep-1630b9b4.js';
import '../_chunks/dep-87d110df.js';
import '../_chunks/dep-6b660ef0.js';
import '../_chunks/dep-f53c91cd.js';
import '../_chunks/dep-b908e1fe.js';
import '../_chunks/dep-a3bde62f.js';
import '../hooks/useDebounce.js';
import '../hooks/usePersistFn.js';
import '../hooks/usePrevious.js';
import '../_util/listener.js';
import '../_chunks/dep-3a09424a.js';
import '../hooks/useConfig.js';
import '../config-provider/ConfigContext.js';
import '../locale/zh_CN.js';
import '../_chunks/dep-e29214cb.js';
import 'dayjs';
import '../_chunks/dep-3c9ab31a.js';
import './hooks/useMultiHeader.js';
import '../_util/scroll.js';
import 'raf';
import '../_util/easing.js';
import '../tooltip/index.js';
import '../tooltip/Tooltip.js';
import '../popup/index.js';
import '../popup/Popup.js';
import 'react-transition-group';
import '../_util/ref.js';
import 'react-is';
import '../_util/isFragment.js';
import '../common/Portal.js';
import 'react-dom';
import '../hooks/useLayoutEffect.js';
import '../hooks/useAnimation.js';
import '../hooks/useAttach.js';
import '../hooks/useControlled.js';
import '../_util/noop.js';
import '../hooks/useDefaultProps.js';
import '../hooks/useMutationObserver.js';
import '../hooks/useLatest.js';
import '../hooks/usePopper.js';
import '@popperjs/core';
import 'react-fast-compare';
import '../hooks/useWindowSize.js';
import '../popup/defaultProps.js';
import '../popup/hooks/useTrigger.js';
import '../_util/composeRefs.js';
import '../popup/utils/transition.js';
import '../popup/PopupPlugin.js';
import '../_chunks/dep-a74cc5e4.js';
import '../_util/react-render.js';
import '../common/PluginContainer.js';
import '../config-provider/index.js';
import '../config-provider/ConfigProvider.js';
import '../config-provider/type.js';
import '../popup/style/index.js';
import '../popup/type.js';
import '../tooltip/defaultProps.js';
import '../tooltip/TooltipLite.js';
import '../hooks/useSwitch.js';
import '../tooltip/style/index.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; }
function THead(props) {
var columnResizeParams = props.columnResizeParams,
classPrefix = props.classPrefix,
showColumnShadow = props.showColumnShadow;
var theadRef = useRef(null);
var classnames = useClassName();
var tableHeaderClasses = classnames.tableHeaderClasses,
tableBaseClass = classnames.tableBaseClass;
var theadClasses = [tableHeaderClasses.header, _defineProperty(_defineProperty(_defineProperty({}, tableHeaderClasses.fixed, Boolean(props.maxHeight || props.height)), tableBaseClass.bordered, props.bordered && props.isMultipleHeader), tableHeaderClasses.multipleHeader, props.isMultipleHeader)];
var colspanSkipMap = useMemo(function () {
var map = {};
var list = props.thList[0];
for (var i = 0, len = list.length; i < len; i++) {
var item = list[i];
if (item.colspan > 1) {
for (var j = i + 1; j < i + item.colspan; j++) {
if (list[j]) {
map[list[j].colKey] = true;
}
}
}
}
return map;
}, [props.thList]);
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;
};
var renderThNodeList = function renderThNodeList(rowAndColFixedPosition, thWidthList) {
var thBorderMap = /* @__PURE__ */new Map();
var thRowspanAndColspan = props.spansAndLeafNodes.rowspanAndColspanMap;
return props.thList.map(function (row, rowIndex) {
var thRow = row.map(function (col, index) {
var _col$children;
if (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(props.thList[j][0], true);
}
}
var thStyles = getColumnFixedStyles(col, index, rowAndColFixedPosition, classnames.tableColFixedClasses);
var colParams = {
col: col,
colIndex: index,
row: {},
rowIndex: -1
};
var isLeftFixedActive = showColumnShadow.left && col.fixed === "left";
var isRightFixedActive = showColumnShadow.right && col.fixed === "right";
var canDragSort = props.thDraggable && !(isLeftFixedActive || isRightFixedActive);
var customClasses = formatClassNames(col.className, _objectSpread(_objectSpread({}, colParams), {}, {
type: "th"
}));
var thCustomClasses = formatClassNames(col.thClassName, colParams);
var thClasses = [thStyles.classes, customClasses, thCustomClasses, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, tableHeaderClasses.thBordered, thBorderMap.get(col)), "".concat(classPrefix, "-table__th-").concat(col.colKey), col.colKey), classnames.tdAlignClasses[col.align], col.align && col.align !== "left"), classnames.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(col, index);
if (!col.colKey) return null;
var resizeColumnListener = props.resizable || !canDragSort ? {
onMouseDown: function onMouseDown(e) {
if (props.resizable) {
var _columnResizeParams$o;
columnResizeParams === null || columnResizeParams === void 0 || (_columnResizeParams$o = columnResizeParams.onColumnMousedown) === null || _columnResizeParams$o === void 0 || _columnResizeParams$o.call(columnResizeParams, e, col, index);
}
if (!canDragSort) {
var timer = setTimeout(function () {
var _thList$index;
var thList = theadRef.current.querySelectorAll("th");
(_thList$index = thList[index]) === null || _thList$index === void 0 || _thList$index.removeAttribute("draggable");
clearTimeout(timer);
}, 10);
}
},
onMouseMove: function onMouseMove(e) {
var _columnResizeParams$o2;
props.resizable && (columnResizeParams === null || columnResizeParams === void 0 || (_columnResizeParams$o2 = columnResizeParams.onColumnMouseover) === null || _columnResizeParams$o2 === void 0 ? void 0 : _columnResizeParams$o2.call(columnResizeParams, e, col));
}
} : {};
var content = isFunction(col.ellipsisTitle) ? col.ellipsisTitle({
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 /* @__PURE__ */React.createElement("th", _objectSpread(_objectSpread(_objectSpread({
key: col.colKey,
"data-colkey": col.colKey,
className: classNames(thClasses),
style: styles
}, {
rowSpan: rowspanAndColspan.rowspan,
colSpan: rowspanAndColspan.colspan
}), attrs), resizeColumnListener), /* @__PURE__ */React.createElement("div", {
className: tableBaseClass.thCellInner
}, isEllipsis ? /* @__PURE__ */React.createElement(Ellipsis, {
placement: "bottom",
attach: theadRef.current ? function () {
return getTableNode(theadRef.current);
} : void 0,
popupContent: content,
tooltipProps: _typeof(col.ellipsisTitle) === "object" ? col.ellipsisTitle : void 0,
overlayClassName: props.ellipsisOverlayClassName,
classPrefix: props.classPrefix
}, innerTh) : innerTh));
});
return /* @__PURE__ */React.createElement("tr", {
key: rowIndex
}, thRow);
});
};
return /* @__PURE__ */React.createElement("thead", {
ref: theadRef,
className: classNames(theadClasses)
}, renderThNodeList(props.rowAndColFixedPosition, props.thWidthList));
}
export { THead as default };
//# sourceMappingURL=THead.js.map