tdesign-react
Version:
TDesign Component for React
708 lines (704 loc) • 33.6 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js';
import { _ as _slicedToArray } from '../_chunks/dep-48805ab8.js';
import React, { forwardRef, useRef, useState, useMemo, useEffect, useImperativeHandle } from 'react';
import classNames from 'classnames';
import { pick } from 'lodash-es';
import '../_chunks/dep-f53c91cd.js';
import { g as getIEVersion } from '../_chunks/dep-1630b9b4.js';
import { Affix } from '../affix/index.js';
import useDefaultProps from '../hooks/useDefaultProps.js';
import { useElementLazyRender } from '../hooks/useElementLazyRender.js';
import useVirtualScroll from '../hooks/useVirtualScroll.js';
import { Loading } from '../loading/index.js';
import TBody, { extendTableProps } from './TBody.js';
import TFoot from './TFoot.js';
import THead from './THead.js';
import { ROW_LISTENERS } from './TR.js';
import { baseTableDefaultProps } from './defaultProps.js';
import useAffix from './hooks/useAffix.js';
import useClassName from './hooks/useClassName.js';
import useColumnResize from './hooks/useColumnResize.js';
import useFixed from './hooks/useFixed.js';
import usePagination from './hooks/usePagination.js';
import useStyle, { formatCSSUnit } from './hooks/useStyle.js';
import useTableHeader from './hooks/useTableHeader.js';
import { getAffixProps } from './utils.js';
import { l as log } from '../_chunks/dep-b908e1fe.js';
import '../_chunks/dep-eca3a3de.js';
import '../_chunks/dep-026a4c6b.js';
import '../_chunks/dep-87d110df.js';
import '../_chunks/dep-6b660ef0.js';
import '../affix/Affix.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 '../affix/defaultProps.js';
import '../_util/scroll.js';
import 'raf';
import '../_chunks/dep-3a09424a.js';
import '../_util/easing.js';
import '../affix/style/index.js';
import '../affix/type.js';
import '../_chunks/dep-4450afc0.js';
import '../loading/Loading.js';
import '../common/Portal.js';
import 'react-dom';
import '../hooks/useLayoutEffect.js';
import '../loading/gradient.js';
import '../_chunks/dep-c48e2ca1.js';
import '../hooks/useDomRefCallback.js';
import '../loading/defaultProps.js';
import '../loading/plugin.js';
import '../_util/react-render.js';
import '../_chunks/dep-a74cc5e4.js';
import '../common/PluginContainer.js';
import '../config-provider/index.js';
import '../config-provider/ConfigProvider.js';
import '../config-provider/type.js';
import '../loading/style/index.js';
import '../loading/type.js';
import '../locale/LocalReceiver.js';
import './hooks/useRowspanAndColspan.js';
import './Ellipsis.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 '../hooks/useAnimation.js';
import '../hooks/useAttach.js';
import '../hooks/useControlled.js';
import '../_util/noop.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 '../_util/listener.js';
import '../popup/utils/transition.js';
import '../popup/PopupPlugin.js';
import '../popup/style/index.js';
import '../popup/type.js';
import '../tooltip/defaultProps.js';
import '../tooltip/TooltipLite.js';
import '../hooks/useSwitch.js';
import '../hooks/usePersistFn.js';
import '../tooltip/style/index.js';
import '../tooltip/type.js';
import '../hooks/useDebounce.js';
import './hooks/useLazyLoad.js';
import './Cell.js';
import '../_chunks/dep-a3bde62f.js';
import '../hooks/usePrevious.js';
import '../pagination/index.js';
import '../pagination/Pagination.js';
import '../select/index.js';
import '../select/base/Select.js';
import '../_util/forwardRefWithStatics.js';
import 'hoist-non-react-statics';
import '../_util/helper.js';
import '../_util/parseTNode.js';
import '../common/FakeArrow.js';
import '../select-input/index.js';
import '../select-input/SelectInput.js';
import '../select-input/useSingle.js';
import '../input/index.js';
import '../input/Input.js';
import 'tdesign-icons-react';
import '../hooks/useGlobalIcon.js';
import '../input/InputGroup.js';
import '../input/defaultProps.js';
import '../input/useLengthLimit.js';
import '../input/style/index.js';
import '../input/type.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/TagInput.js';
import '../hooks/useDragSorter.js';
import '../hooks/useEventCallback.js';
import '../tag-input/defaultProps.js';
import '../tag-input/useHover.js';
import '../tag-input/useTagList.js';
import '../tag/index.js';
import '../tag/Tag.js';
import '../_chunks/dep-3c3d29db.js';
import '../tag/defaultProps.js';
import '../tag/CheckTag.js';
import '../_chunks/dep-55732ade.js';
import '../tag/CheckTagGroup.js';
import '../tag/style/index.js';
import '../tag/type.js';
import '../tag-input/useTagScroll.js';
import '../tag-input/style/index.js';
import '../tag-input/type.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/defaultProps.js';
import '../select-input/style/index.js';
import '../select-input/type.js';
import '../select/defaultProps.js';
import '../_chunks/dep-c7ed701c.js';
import '../select/base/OptionGroup.js';
import '../select/base/Option.js';
import '../hooks/useRipple.js';
import '../select/base/PopupContent.js';
import '../select/hooks/usePanelVirtualScroll.js';
import '../select/style/index.js';
import '../select/type.js';
import '../input-number/index.js';
import '../input-number/InputNumber.js';
import '../button/index.js';
import '../button/Button.js';
import '../button/defaultProps.js';
import '../button/style/index.js';
import '../button/type.js';
import '../input-number/useInputNumber.js';
import '../_chunks/dep-46c9e4f5.js';
import '../hooks/useCommonClassName.js';
import '../input-number/defaultProps.js';
import '../input-number/style/index.js';
import '../input-number/type.js';
import '../input-adornment/index.js';
import '../input-adornment/InputAdornment.js';
import '../input-adornment/style/index.js';
import '../input-adornment/type.js';
import '../pagination/hooks/useBoundaryJumper.js';
import '../pagination/hooks/usePrevNextJumper.js';
import '../pagination/hooks/usePageNumber.js';
import '../pagination/hooks/useTotal.js';
import '../pagination/validators.js';
import '../pagination/defaultProps.js';
import '../pagination/PaginationMini.js';
import '../pagination/style/index.js';
import '../pagination/type.js';
import './hooks/useMultiHeader.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 BASE_TABLE_EVENTS = ["page-change", "cell-click", "scroll", "scrollX", "scrollY"];
var BASE_TABLE_ALL_EVENTS = ROW_LISTENERS.map(function (t) {
return "row-".concat(t);
}).concat(BASE_TABLE_EVENTS);
var BaseTable = /*#__PURE__*/forwardRef(function (originalProps, ref) {
var _affixHeaderRef$curre;
var props = useDefaultProps(originalProps, baseTableDefaultProps);
var _props$showHeader = props.showHeader,
showHeader = _props$showHeader === void 0 ? true : _props$showHeader,
tableLayout = props.tableLayout,
height = props.height,
data = props.data,
columns = props.columns,
style = props.style,
headerAffixedTop = props.headerAffixedTop,
bordered = props.bordered,
resizable = props.resizable,
lazyLoad = props.lazyLoad,
pagination = props.pagination;
var tableRef = useRef(null);
var tableElmRef = useRef(null);
var bottomContentRef = useRef(null);
var _useState = useState(0),
_useState2 = _slicedToArray(_useState, 2),
tableFootHeight = _useState2[0],
setTableFootHeight = _useState2[1];
var _useState3 = useState(0),
_useState4 = _slicedToArray(_useState3, 2),
lastTrHeight = _useState4[0],
setLastTrHeight = _useState4[1];
var allTableClasses = useClassName();
var classPrefix = allTableClasses.classPrefix,
virtualScrollClasses = allTableClasses.virtualScrollClasses,
tableLayoutClasses = allTableClasses.tableLayoutClasses,
tableBaseClass = allTableClasses.tableBaseClass,
tableColFixedClasses = allTableClasses.tableColFixedClasses;
var _useStyle = useStyle(props),
tableClasses = _useStyle.tableClasses,
sizeClassNames = _useStyle.sizeClassNames,
tableContentStyles = _useStyle.tableContentStyles,
tableElementStyles = _useStyle.tableElementStyles;
var _useTableHeader = useTableHeader({
columns: props.columns
}),
isMultipleHeader = _useTableHeader.isMultipleHeader,
spansAndLeafNodes = _useTableHeader.spansAndLeafNodes,
thList = _useTableHeader.thList;
var finalColumns = useMemo(function () {
return (spansAndLeafNodes === null || spansAndLeafNodes === void 0 ? void 0 : spansAndLeafNodes.leafColumns) || columns;
}, [spansAndLeafNodes === null || spansAndLeafNodes === void 0 ? void 0 : spansAndLeafNodes.leafColumns, columns]);
var _useElementLazyRender = useElementLazyRender(tableRef, lazyLoad),
showElement = _useElementLazyRender.showElement;
var paginationAffixRef = useRef(null);
var horizontalScrollAffixRef = useRef(null);
var headerTopAffixRef = useRef(null);
var footerBottomAffixRef = useRef(null);
var _useAffix = useAffix(props, {
showElement: showElement
}),
affixHeaderRef = _useAffix.affixHeaderRef,
affixFooterRef = _useAffix.affixFooterRef,
horizontalScrollbarRef = _useAffix.horizontalScrollbarRef,
paginationRef = _useAffix.paginationRef,
showAffixHeader = _useAffix.showAffixHeader,
showAffixFooter = _useAffix.showAffixFooter,
showAffixPagination = _useAffix.showAffixPagination,
onHorizontalScroll = _useAffix.onHorizontalScroll,
setTableContentRef = _useAffix.setTableContentRef,
updateAffixHeaderOrFooter = _useAffix.updateAffixHeaderOrFooter;
var _useFixed = useFixed(props, finalColumns, {
paginationAffixRef: paginationAffixRef,
horizontalScrollAffixRef: horizontalScrollAffixRef,
headerTopAffixRef: headerTopAffixRef,
footerBottomAffixRef: footerBottomAffixRef
}),
scrollbarWidth = _useFixed.scrollbarWidth,
tableWidth = _useFixed.tableWidth,
tableElmWidth = _useFixed.tableElmWidth,
tableContentRef = _useFixed.tableContentRef,
isFixedHeader = _useFixed.isFixedHeader,
isWidthOverflow = _useFixed.isWidthOverflow,
isFixedColumn = _useFixed.isFixedColumn,
thWidthList = _useFixed.thWidthList,
showColumnShadow = _useFixed.showColumnShadow,
rowAndColFixedPosition = _useFixed.rowAndColFixedPosition,
setData = _useFixed.setData,
refreshTable = _useFixed.refreshTable,
setTableElmWidth = _useFixed.setTableElmWidth,
emitScrollEvent = _useFixed.emitScrollEvent,
setUseFixedTableElmRef = _useFixed.setUseFixedTableElmRef,
updateColumnFixedShadow = _useFixed.updateColumnFixedShadow,
getThWidthList = _useFixed.getThWidthList,
updateThWidthList = _useFixed.updateThWidthList,
addTableResizeObserver = _useFixed.addTableResizeObserver,
updateTableAfterColumnResize = _useFixed.updateTableAfterColumnResize;
var _usePagination = usePagination(props, tableContentRef),
dataSource = _usePagination.dataSource,
innerPagination = _usePagination.innerPagination,
isPaginateData = _usePagination.isPaginateData,
renderPagination = _usePagination.renderPagination;
var columnResizeParams = useColumnResize({
isWidthOverflow: isWidthOverflow,
tableContentRef: tableContentRef,
showColumnShadow: showColumnShadow,
getThWidthList: getThWidthList,
updateThWidthList: updateThWidthList,
setTableElmWidth: setTableElmWidth,
updateTableAfterColumnResize: updateTableAfterColumnResize,
onColumnResizeChange: props.onColumnResizeChange
});
var resizeLineRef = columnResizeParams.resizeLineRef,
resizeLineStyle = columnResizeParams.resizeLineStyle,
setEffectColMap = columnResizeParams.setEffectColMap,
updateTableWidthOnColumnChange = columnResizeParams.updateTableWidthOnColumnChange;
var dynamicBaseTableClasses = classNames(tableClasses.concat(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, tableBaseClass.headerFixed, isFixedHeader), tableBaseClass.columnFixed, isFixedColumn), tableBaseClass.widthOverflow, isWidthOverflow), tableBaseClass.multipleHeader, isMultipleHeader), tableColFixedClasses.leftShadow, showColumnShadow.left), tableColFixedClasses.rightShadow, showColumnShadow.right), tableBaseClass.columnResizableTable, props.resizable)));
var tableElmClasses = classNames([[tableLayoutClasses[tableLayout || "fixed"]], _defineProperty({}, tableBaseClass.fullHeight, height)]);
var showRightDivider = useMemo(function () {
return props.bordered && isFixedHeader && (isMultipleHeader && isWidthOverflow || !isMultipleHeader);
}, [isFixedHeader, isMultipleHeader, isWidthOverflow, props.bordered]);
var _useState5 = useState(0),
_useState6 = _slicedToArray(_useState5, 2),
dividerBottom = _useState6[0],
setDividerBottom = _useState6[1];
useEffect(function () {
var _bottomContentRef$cur, _paginationRef$curren;
if (!bordered) return;
var bottomRect = (_bottomContentRef$cur = bottomContentRef.current) === null || _bottomContentRef$cur === void 0 ? void 0 : _bottomContentRef$cur.getBoundingClientRect();
var paginationRect = (_paginationRef$curren = paginationRef.current) === null || _paginationRef$curren === void 0 ? void 0 : _paginationRef$curren.getBoundingClientRect();
var bottom2 = ((bottomRect === null || bottomRect === void 0 ? void 0 : bottomRect.height) || 0) + ((paginationRect === null || paginationRect === void 0 ? void 0 : paginationRect.height) || 0);
setDividerBottom(bottom2);
}, [bottomContentRef, paginationRef, bordered]);
useEffect(function () {
setUseFixedTableElmRef(tableElmRef.current);
}, [tableElmRef]);
useEffect(function () {
setData(isPaginateData ? dataSource : props.data);
}, [props.data, dataSource, isPaginateData]);
var _useState7 = useState(props.columns || []),
_useState8 = _slicedToArray(_useState7, 2),
lastLeafColumns = _useState8[0],
setLastLeafColumns = _useState8[1];
useEffect(function () {
if (lastLeafColumns.map(function (t) {
return t.colKey;
}).join() !== spansAndLeafNodes.leafColumns.map(function (t) {
return t.colKey;
}).join()) {
var _props$onLeafColumnsC;
(_props$onLeafColumnsC = props.onLeafColumnsChange) === null || _props$onLeafColumnsC === void 0 || _props$onLeafColumnsC.call(props, spansAndLeafNodes.leafColumns);
setLastLeafColumns(spansAndLeafNodes.leafColumns);
}
setEffectColMap(spansAndLeafNodes.leafColumns, null);
}, [spansAndLeafNodes.leafColumns]);
var onFixedChange = function onFixedChange() {
var timer = setTimeout(function () {
onHorizontalScroll();
updateAffixHeaderOrFooter();
clearTimeout(timer);
}, 0);
};
var virtualScrollParams = useMemo(function () {
return {
data: data,
scroll: _objectSpread(_objectSpread({}, props.scroll), {}, {
fixedRows: props.fixedRows
})
};
}, [data, props.scroll, props.fixedRows]);
var virtualConfig = useVirtualScroll(tableContentRef, virtualScrollParams);
var lastScrollY = -1;
var onInnerVirtualScroll = function onInnerVirtualScroll(e) {
var target = e.target;
var top = target.scrollTop;
if (lastScrollY !== top) {
virtualConfig.isVirtualScroll && virtualConfig.handleScroll();
} else {
lastScrollY = -1;
updateColumnFixedShadow(target);
}
lastScrollY = top;
onHorizontalScroll(target);
emitScrollEvent(e);
};
var scrollColumnIntoView = function scrollColumnIntoView(colKey) {
if (!tableContentRef.current) return;
var thDom = tableContentRef.current.querySelector("th[data-colkey=\"".concat(colKey, "\"]"));
var fixedThDom = tableContentRef.current.querySelectorAll("th.t-table__cell--fixed-left");
var totalWidth = 0;
for (var i = 0, len = fixedThDom.length; i < len; i++) {
totalWidth += fixedThDom[i].getBoundingClientRect().width;
}
var domRect = thDom.getBoundingClientRect();
var contentRect = tableContentRef.current.getBoundingClientRect();
var distance = domRect.left - contentRect.left - totalWidth;
tableContentRef.current.scrollTo({
left: distance,
behavior: "smooth"
});
};
useImperativeHandle(ref, function () {
return {
showColumnShadow: showColumnShadow,
tableElement: tableRef.current,
tableHtmlElement: tableElmRef.current,
tableContentElement: tableContentRef.current,
affixHeaderElement: affixHeaderRef.current,
refreshTable: refreshTable,
scrollToElement: virtualConfig.scrollToElement,
scrollColumnIntoView: scrollColumnIntoView,
updateTableWidthOnColumnChange: updateTableWidthOnColumnChange
};
});
var getTFootHeight = function getTFootHeight() {
requestAnimationFrame(function () {
var _tableElmRef$current$;
if (!tableElmRef.current) return;
var height2 = (_tableElmRef$current$ = tableElmRef.current.querySelector("tfoot")) === null || _tableElmRef$current$ === void 0 ? void 0 : _tableElmRef$current$.offsetHeight;
setTableFootHeight(height2 || 0);
});
};
var getLastTrHeight = function getLastTrHeight() {
requestAnimationFrame(function () {
if (!tableElmRef.current || !props.firstFullRow) return;
var tbody = tableElmRef.current.querySelector("tbody");
var allTr = tbody === null || tbody === void 0 ? void 0 : tbody.querySelectorAll("tr");
var lastTr = allTr === null || allTr === void 0 ? void 0 : allTr[allTr.length - 1];
var height2 = lastTr === null || lastTr === void 0 ? void 0 : lastTr.offsetHeight;
setLastTrHeight(height2 || 0);
});
};
useEffect(getTFootHeight, [tableElmRef, props.footData, props.footerSummary]);
useEffect(getLastTrHeight, [tableElmRef, props.firstFullRow]);
useEffect(function () {
setTableContentRef(tableContentRef.current);
}, [tableContentRef]);
useEffect(function () {
return addTableResizeObserver(tableRef.current);
}, [tableRef]);
var newData = isPaginateData ? dataSource : data;
var renderColGroup = function renderColGroup() {
var isFixedHeader2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
return /* @__PURE__ */React.createElement("colgroup", null, finalColumns.map(function (col, index) {
var style2 = {
width: formatCSSUnit((isFixedHeader2 || resizable ? thWidthList.current[col.colKey] : void 0) || col.width)
};
if (col.minWidth) {
style2.minWidth = formatCSSUnit(col.minWidth);
}
if (!style2.width && !col.minWidth && props.tableLayout === "fixed") {
style2.minWidth = "80px";
}
return /* @__PURE__ */React.createElement("col", {
key: col.colKey || index,
style: style2
});
}));
};
var headProps = {
isFixedHeader: isFixedHeader,
rowAndColFixedPosition: rowAndColFixedPosition,
isMultipleHeader: isMultipleHeader,
bordered: props.bordered,
maxHeight: props.maxHeight,
height: props.height,
spansAndLeafNodes: spansAndLeafNodes,
thList: thList,
thWidthList: thWidthList.current,
resizable: props.resizable,
columnResizeParams: columnResizeParams,
classPrefix: classPrefix,
ellipsisOverlayClassName: props.size !== "medium" ? sizeClassNames[props.size] : "",
attach: props.attach,
thDraggable: props.thDraggable,
showColumnShadow: showColumnShadow
};
var headUseMemoDependencies = [resizable, thWidthList, isFixedHeader, rowAndColFixedPosition, isMultipleHeader, spansAndLeafNodes, thList, columnResizeParams, classPrefix, props.bordered, props.resizable, props.size];
var affixedLeftBorder = props.bordered ? 1 : 0;
var IEHeaderWrap = getIEVersion() <= 11 ? 4 : 0;
var affixHeaderHeight = (((_affixHeaderRef$curre = affixHeaderRef.current) === null || _affixHeaderRef$curre === void 0 ? void 0 : _affixHeaderRef$curre.getBoundingClientRect().height) || 0) - IEHeaderWrap;
var renderFixedHeader = function renderFixedHeader() {
if (!showHeader) return null;
var headerOpacity = headerAffixedTop ? Number(showAffixHeader) : 1;
var barWidth = isWidthOverflow ? scrollbarWidth : 0;
var affixHeaderWrapHeight = affixHeaderHeight - barWidth;
var affixHeaderWrapHeightStyle = {
width: "".concat(tableWidth.current, "px"),
height: "".concat(affixHeaderWrapHeight, "px"),
opacity: headerOpacity
};
var affixedHeader = Boolean((headerAffixedTop || virtualConfig.isVirtualScroll) && tableWidth.current) && /* @__PURE__ */React.createElement("div", {
ref: affixHeaderRef,
style: {
width: "".concat(tableWidth.current - affixedLeftBorder, "px"),
opacity: headerOpacity
},
className: classNames(["scrollbar", _defineProperty({}, tableBaseClass.affixedHeaderElm, props.headerAffixedTop || virtualConfig.isVirtualScroll)])
}, /* @__PURE__ */React.createElement("table", {
className: classNames(tableElmClasses),
style: _objectSpread(_objectSpread({}, tableElementStyles), {}, {
width: tableElmWidth.current ? "".concat(tableElmWidth.current, "px") : void 0
})
}, renderColGroup(true), showHeader && /* @__PURE__ */React.createElement(THead, _objectSpread({}, headProps))));
var affixHeaderWithWrap = /* @__PURE__ */React.createElement("div", {
className: tableBaseClass.affixedHeaderWrap,
style: affixHeaderWrapHeightStyle
}, affixedHeader);
return affixHeaderWithWrap;
};
var renderAffixedHeader = function renderAffixedHeader() {
if (!showHeader) return null;
return !!(virtualConfig.isVirtualScroll || props.headerAffixedTop) && (props.headerAffixedTop ? /* @__PURE__ */React.createElement(Affix, _objectSpread(_objectSpread({
offsetTop: 0
}, getAffixProps(props.headerAffixedTop, props.headerAffixProps)), {}, {
ref: headerTopAffixRef,
onFixedChange: onFixedChange
}), renderFixedHeader()) : isFixedHeader && renderFixedHeader());
};
var renderAffixedFooter = function renderAffixedFooter() {
var _props$footData;
var marginScrollbarWidth = isWidthOverflow ? scrollbarWidth : 0;
if (bordered) {
marginScrollbarWidth += 1;
}
var totalMarginTop = tableFootHeight - lastTrHeight + marginScrollbarWidth;
var affixedFooter = Boolean((virtualConfig.isVirtualScroll || props.footerAffixedBottom) && ((_props$footData = props.footData) === null || _props$footData === void 0 ? void 0 : _props$footData.length) && tableWidth.current) && /* @__PURE__ */React.createElement(Affix, _objectSpread(_objectSpread({
className: tableBaseClass.affixedFooterWrap,
onFixedChange: onFixedChange,
offsetBottom: marginScrollbarWidth || 0
}, getAffixProps(props.footerAffixedBottom)), {}, {
ref: footerBottomAffixRef,
style: {
marginTop: "".concat(-1 * totalMarginTop, "px")
}
}), /* @__PURE__ */React.createElement("div", {
ref: affixFooterRef,
style: {
width: "".concat(tableWidth.current - affixedLeftBorder, "px"),
opacity: Number(showAffixFooter)
},
className: classNames(["scrollbar", _defineProperty({}, tableBaseClass.affixedFooterElm, props.footerAffixedBottom || virtualConfig.isVirtualScroll)])
}, /* @__PURE__ */React.createElement("table", {
className: tableElmClasses,
style: _objectSpread(_objectSpread({}, tableElementStyles), {}, {
width: tableElmWidth.current ? "".concat(tableElmWidth.current, "px") : void 0
})
}, renderColGroup(true), /* @__PURE__ */React.createElement(TFoot, {
rowKey: props.rowKey,
isFixedHeader: isFixedHeader,
rowAndColFixedPosition: rowAndColFixedPosition,
footData: props.footData,
columns: (spansAndLeafNodes === null || spansAndLeafNodes === void 0 ? void 0 : spansAndLeafNodes.leafColumns) || columns,
rowAttributes: props.rowAttributes,
rowClassName: props.rowClassName,
thWidthList: thWidthList.current,
footerSummary: props.footerSummary,
rowspanAndColspanInFooter: props.rowspanAndColspanInFooter
}))));
return affixedFooter;
};
var tableBodyProps = _objectSpread(_objectSpread({
classPrefix: classPrefix,
ellipsisOverlayClassName: props.size !== "medium" ? sizeClassNames[props.size] : "",
rowAndColFixedPosition: rowAndColFixedPosition,
showColumnShadow: showColumnShadow,
data: newData,
virtualConfig: virtualConfig,
handleRowMounted: virtualConfig.handleRowMounted,
columns: (spansAndLeafNodes === null || spansAndLeafNodes === void 0 ? void 0 : spansAndLeafNodes.leafColumns) || columns,
tableRef: tableRef,
tableContentRef: tableContentRef,
tableWidth: tableWidth,
isWidthOverflow: isWidthOverflow,
allTableClasses: allTableClasses,
rowKey: props.rowKey || "id",
scroll: props.scroll,
cellEmptyContent: props.cellEmptyContent,
renderExpandedRow: props.renderExpandedRow
}, pick(props, extendTableProps)), {}, {
pagination: innerPagination
});
var translate = "translate(0, ".concat(virtualConfig.scrollHeight + (affixHeaderHeight || 0) + (tableFootHeight || 0), "px)");
var virtualStyle = {
transform: translate,
msTransform: translate,
MozTransform: translate,
WebkitTransform: translate
};
var tableContent = /* @__PURE__ */React.createElement("div", {
ref: tableContentRef,
className: tableBaseClass.content,
style: tableContentStyles,
onScroll: onInnerVirtualScroll
}, virtualConfig.isVirtualScroll && /* @__PURE__ */React.createElement("div", {
className: virtualScrollClasses.cursor,
style: virtualStyle
}), /* @__PURE__ */React.createElement("table", {
ref: tableElmRef,
className: classNames(tableElmClasses),
style: _objectSpread(_objectSpread({}, tableElementStyles), {}, {
width: resizable && isWidthOverflow && tableElmWidth.current ? "".concat(tableElmWidth.current, "px") : tableElementStyles.width
})
}, renderColGroup(false), useMemo(function () {
if (!showHeader) return null;
return /* @__PURE__ */React.createElement(THead, _objectSpread({}, _objectSpread(_objectSpread({}, headProps), {}, {
thWidthList: resizable ? thWidthList.current : {}
})));
}, headUseMemoDependencies), useMemo(function () {
return /* @__PURE__ */React.createElement(TBody, _objectSpread({}, tableBodyProps));
}, [allTableClasses, tableBodyProps.ellipsisOverlayClassName, tableBodyProps.rowAndColFixedPosition, tableBodyProps.showColumnShadow, tableBodyProps.data, tableBodyProps.columns, tableRef, tableContentRef, tableWidth, isWidthOverflow, virtualConfig, props.rowKey, props.rowClassName, props.rowAttributes, props.loading, props.empty, props.fixedRows, props.firstFullRow, props.lastFullRow, props.rowspanAndColspan, props.scroll, props.cellEmptyContent]), useMemo(function () {
return /* @__PURE__ */React.createElement(TFoot, {
rowKey: props.rowKey,
isFixedHeader: isFixedHeader,
rowAndColFixedPosition: rowAndColFixedPosition,
footData: props.footData,
columns: (spansAndLeafNodes === null || spansAndLeafNodes === void 0 ? void 0 : spansAndLeafNodes.leafColumns) || columns,
rowAttributes: props.rowAttributes,
rowClassName: props.rowClassName,
thWidthList: thWidthList.current,
footerSummary: props.footerSummary,
rowspanAndColspanInFooter: props.rowspanAndColspanInFooter,
virtualScroll: virtualConfig.isVirtualScroll
});
}, [isFixedHeader, rowAndColFixedPosition, spansAndLeafNodes, columns, thWidthList, props.rowKey, props.footData, props.rowAttributes, props.rowClassName, props.footerSummary, virtualConfig.isVirtualScroll])));
var loading = props.loading,
loadingProps = props.loadingProps;
var customLoadingText = loading;
var loadingContent = tableRef.current && loading !== void 0 && /* @__PURE__ */React.createElement(Loading, _objectSpread({
loading: !!loading,
text: customLoadingText,
attach: function attach() {
return tableRef.current;
},
showOverlay: true,
size: "small"
}, loadingProps));
var topContent = props.topContent,
bottomContent = props.bottomContent;
var paginationNode = pagination ? /* @__PURE__ */React.createElement("div", {
ref: paginationRef,
className: tableBaseClass.paginationWrap,
style: {
opacity: Number(showAffixPagination)
}
}, renderPagination()) : null;
var bottom = !!bottomContent && /* @__PURE__ */React.createElement("div", {
ref: bottomContentRef,
className: tableBaseClass.bottomContent
}, bottomContent);
var affixedHeaderContent = useMemo(renderAffixedHeader, [].concat(headUseMemoDependencies, [showAffixHeader, tableWidth, tableElmWidth, affixHeaderRef, affixedLeftBorder, tableElmClasses, tableElementStyles, columns, spansAndLeafNodes, showHeader, props.headerAffixedTop]));
var affixedFooterContent = useMemo(renderAffixedFooter, [showAffixFooter, isFixedHeader, rowAndColFixedPosition, spansAndLeafNodes, columns, thWidthList, tableBaseClass, tableElementStyles, tableElmWidth, affixFooterRef, affixedLeftBorder, bordered, isWidthOverflow, scrollbarWidth, tableElmClasses, tableFootHeight, lastTrHeight, tableWidth, virtualConfig.isVirtualScroll, props.rowKey, props.footData, props.rowAttributes, props.rowClassName, props.footerSummary, props.footerAffixedBottom, props.rowspanAndColspanInFooter, tableWidth.current]);
var scrollbarDivider = useMemo(function () {
var _tableContentRef$curr;
if (!showRightDivider) return null;
return /* @__PURE__ */React.createElement("div", {
className: tableBaseClass.scrollbarDivider,
style: {
right: "".concat(scrollbarWidth, "px"),
bottom: dividerBottom ? "".concat(dividerBottom, "px") : void 0,
height: "".concat((_tableContentRef$curr = tableContentRef.current) === null || _tableContentRef$curr === void 0 ? void 0 : _tableContentRef$curr.getBoundingClientRect().height, "px")
}
});
}, [tableBaseClass, showRightDivider, scrollbarWidth, dividerBottom, tableContentRef]);
var affixedScrollbar = props.horizontalScrollAffixedBottom && /* @__PURE__ */React.createElement(Affix, _objectSpread(_objectSpread({
offsetBottom: 0
}, getAffixProps(props.horizontalScrollAffixedBottom)), {}, {
ref: horizontalScrollAffixRef,
style: {
marginTop: "-".concat(scrollbarWidth * 2, "px")
}
}), /* @__PURE__ */React.createElement("div", {
ref: horizontalScrollbarRef,
className: classNames(["scrollbar", tableBaseClass.obviousScrollbar]),
style: {
width: "".concat(tableWidth.current, "px"),
overflow: "auto",
opacity: Number(showAffixFooter)
}
}, /* @__PURE__ */React.createElement("div", {
style: {
width: "".concat(tableElmWidth.current, "px"),
height: "5px"
}
})));
var affixedPaginationContent = props.paginationAffixedBottom ? /* @__PURE__ */React.createElement(Affix, _objectSpread(_objectSpread({
offsetBottom: 0
}, getAffixProps(props.paginationAffixedBottom)), {}, {
ref: paginationAffixRef
}), paginationNode) : paginationNode;
var tableElements = /* @__PURE__ */React.createElement(React.Fragment, null, !!topContent && /* @__PURE__ */React.createElement("div", {
className: tableBaseClass.topContent
}, topContent), affixedHeaderContent, tableContent, affixedFooterContent, loadingContent, scrollbarDivider, bottom, affixedScrollbar, affixedPaginationContent, resizable && /* @__PURE__ */React.createElement("div", {
ref: resizeLineRef,
className: tableBaseClass.resizeLine,
style: resizeLineStyle
}));
if (resizable && tableLayout === "auto") {
log.warn("Table", "table-layout can not be `auto`, cause you are using column resizable, set `table-layout: fixed` please.");
}
if (!showElement) {
/* @__PURE__ */ /*#__PURE__*/React.createElement("div", {
ref: tableRef
});
}
return /* @__PURE__ */React.createElement("div", {
ref: tableRef,
className: classNames(dynamicBaseTableClasses),
style: _objectSpread({
position: "relative"
}, style)
}, tableElements);
});
BaseTable.displayName = "BaseTable";
export { BASE_TABLE_ALL_EVENTS, BASE_TABLE_EVENTS, BaseTable as default };
//# sourceMappingURL=BaseTable.js.map