Table.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  2. import _extends from "@babel/runtime/helpers/esm/extends";
  3. import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
  4. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  5. /**
  6. * Feature:
  7. * - fixed not need to set width
  8. * - support `rowExpandable` to config row expand logic
  9. * - add `summary` to support `() => ReactNode`
  10. *
  11. * Update:
  12. * - `dataIndex` is `array[]` now
  13. * - `expandable` wrap all the expand related props
  14. *
  15. * Removed:
  16. * - expandIconAsCell
  17. * - useFixedHeader
  18. * - rowRef
  19. * - columns[number].onCellClick
  20. * - onRowClick
  21. * - onRowDoubleClick
  22. * - onRowMouseEnter
  23. * - onRowMouseLeave
  24. * - getBodyWrapper
  25. * - bodyStyle
  26. *
  27. * Deprecated:
  28. * - All expanded props, move into expandable
  29. */
  30. import classNames from 'classnames';
  31. import ResizeObserver from 'rc-resize-observer';
  32. import { isStyleSupport } from "rc-util/es/Dom/styleChecker";
  33. import { getTargetScrollBarSize } from "rc-util/es/getScrollBarSize";
  34. import useEvent from "rc-util/es/hooks/useEvent";
  35. import pickAttrs from "rc-util/es/pickAttrs";
  36. import getValue from "rc-util/es/utils/get";
  37. import warning from "rc-util/es/warning";
  38. import * as React from 'react';
  39. import Body from "./Body";
  40. import ColGroup from "./ColGroup";
  41. import { EXPAND_COLUMN, INTERNAL_HOOKS } from "./constant";
  42. import TableContext, { makeImmutable } from "./context/TableContext";
  43. import FixedHolder from "./FixedHolder";
  44. import Footer, { FooterComponents } from "./Footer";
  45. import Summary from "./Footer/Summary";
  46. import Header from "./Header/Header";
  47. import useColumns from "./hooks/useColumns";
  48. import useExpand from "./hooks/useExpand";
  49. import useFixedInfo from "./hooks/useFixedInfo";
  50. import { useTimeoutLock } from "./hooks/useFrame";
  51. import useHover from "./hooks/useHover";
  52. import useSticky from "./hooks/useSticky";
  53. import useStickyOffsets from "./hooks/useStickyOffsets";
  54. import Panel from "./Panel";
  55. import StickyScrollBar from "./stickyScrollBar";
  56. import Column from "./sugar/Column";
  57. import ColumnGroup from "./sugar/ColumnGroup";
  58. import { getColumnsKey, validateValue, validNumberValue } from "./utils/valueUtil";
  59. import { getDOM } from "rc-util/es/Dom/findDOMNode";
  60. import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
  61. export var DEFAULT_PREFIX = 'rc-table';
  62. // Used for conditions cache
  63. var EMPTY_DATA = [];
  64. // Used for customize scroll
  65. var EMPTY_SCROLL_TARGET = {};
  66. function defaultEmpty() {
  67. return 'No Data';
  68. }
  69. function Table(tableProps, ref) {
  70. var props = _objectSpread({
  71. rowKey: 'key',
  72. prefixCls: DEFAULT_PREFIX,
  73. emptyText: defaultEmpty
  74. }, tableProps);
  75. var prefixCls = props.prefixCls,
  76. className = props.className,
  77. rowClassName = props.rowClassName,
  78. style = props.style,
  79. data = props.data,
  80. rowKey = props.rowKey,
  81. scroll = props.scroll,
  82. tableLayout = props.tableLayout,
  83. direction = props.direction,
  84. title = props.title,
  85. footer = props.footer,
  86. summary = props.summary,
  87. caption = props.caption,
  88. id = props.id,
  89. showHeader = props.showHeader,
  90. components = props.components,
  91. emptyText = props.emptyText,
  92. onRow = props.onRow,
  93. onHeaderRow = props.onHeaderRow,
  94. measureRowRender = props.measureRowRender,
  95. onScroll = props.onScroll,
  96. internalHooks = props.internalHooks,
  97. transformColumns = props.transformColumns,
  98. internalRefs = props.internalRefs,
  99. tailor = props.tailor,
  100. getContainerWidth = props.getContainerWidth,
  101. sticky = props.sticky,
  102. _props$rowHoverable = props.rowHoverable,
  103. rowHoverable = _props$rowHoverable === void 0 ? true : _props$rowHoverable;
  104. var mergedData = data || EMPTY_DATA;
  105. var hasData = !!mergedData.length;
  106. var useInternalHooks = internalHooks === INTERNAL_HOOKS;
  107. // ===================== Warning ======================
  108. if (process.env.NODE_ENV !== 'production') {
  109. ['onRowClick', 'onRowDoubleClick', 'onRowContextMenu', 'onRowMouseEnter', 'onRowMouseLeave'].forEach(function (name) {
  110. warning(props[name] === undefined, "`".concat(name, "` is removed, please use `onRow` instead."));
  111. });
  112. warning(!('getBodyWrapper' in props), '`getBodyWrapper` is deprecated, please use custom `components` instead.');
  113. }
  114. // ==================== Customize =====================
  115. var getComponent = React.useCallback(function (path, defaultComponent) {
  116. return getValue(components, path) || defaultComponent;
  117. }, [components]);
  118. var getRowKey = React.useMemo(function () {
  119. if (typeof rowKey === 'function') {
  120. return rowKey;
  121. }
  122. return function (record) {
  123. var key = record && record[rowKey];
  124. if (process.env.NODE_ENV !== 'production') {
  125. warning(key !== undefined, 'Each record in table should have a unique `key` prop, or set `rowKey` to an unique primary key.');
  126. }
  127. return key;
  128. };
  129. }, [rowKey]);
  130. var customizeScrollBody = getComponent(['body']);
  131. // ====================== Hover =======================
  132. var _useHover = useHover(),
  133. _useHover2 = _slicedToArray(_useHover, 3),
  134. startRow = _useHover2[0],
  135. endRow = _useHover2[1],
  136. onHover = _useHover2[2];
  137. // ====================== Expand ======================
  138. var _useExpand = useExpand(props, mergedData, getRowKey),
  139. _useExpand2 = _slicedToArray(_useExpand, 6),
  140. expandableConfig = _useExpand2[0],
  141. expandableType = _useExpand2[1],
  142. mergedExpandedKeys = _useExpand2[2],
  143. mergedExpandIcon = _useExpand2[3],
  144. mergedChildrenColumnName = _useExpand2[4],
  145. onTriggerExpand = _useExpand2[5];
  146. // ====================== Column ======================
  147. var scrollX = scroll === null || scroll === void 0 ? void 0 : scroll.x;
  148. var _React$useState = React.useState(0),
  149. _React$useState2 = _slicedToArray(_React$useState, 2),
  150. componentWidth = _React$useState2[0],
  151. setComponentWidth = _React$useState2[1];
  152. var _useColumns = useColumns(_objectSpread(_objectSpread(_objectSpread({}, props), expandableConfig), {}, {
  153. expandable: !!expandableConfig.expandedRowRender,
  154. columnTitle: expandableConfig.columnTitle,
  155. expandedKeys: mergedExpandedKeys,
  156. getRowKey: getRowKey,
  157. // https://github.com/ant-design/ant-design/issues/23894
  158. onTriggerExpand: onTriggerExpand,
  159. expandIcon: mergedExpandIcon,
  160. expandIconColumnIndex: expandableConfig.expandIconColumnIndex,
  161. direction: direction,
  162. scrollWidth: useInternalHooks && tailor && typeof scrollX === 'number' ? scrollX : null,
  163. clientWidth: componentWidth
  164. }), useInternalHooks ? transformColumns : null),
  165. _useColumns2 = _slicedToArray(_useColumns, 4),
  166. columns = _useColumns2[0],
  167. flattenColumns = _useColumns2[1],
  168. flattenScrollX = _useColumns2[2],
  169. hasGapFixed = _useColumns2[3];
  170. var mergedScrollX = flattenScrollX !== null && flattenScrollX !== void 0 ? flattenScrollX : scrollX;
  171. var columnContext = React.useMemo(function () {
  172. return {
  173. columns: columns,
  174. flattenColumns: flattenColumns
  175. };
  176. }, [columns, flattenColumns]);
  177. // ======================= Refs =======================
  178. var fullTableRef = React.useRef();
  179. var scrollHeaderRef = React.useRef();
  180. var scrollBodyRef = React.useRef();
  181. var scrollBodyContainerRef = React.useRef();
  182. React.useImperativeHandle(ref, function () {
  183. return {
  184. nativeElement: fullTableRef.current,
  185. scrollTo: function scrollTo(config) {
  186. var _scrollBodyRef$curren3;
  187. if (scrollBodyRef.current instanceof HTMLElement) {
  188. // Native scroll
  189. var index = config.index,
  190. top = config.top,
  191. key = config.key;
  192. if (validNumberValue(top)) {
  193. var _scrollBodyRef$curren;
  194. (_scrollBodyRef$curren = scrollBodyRef.current) === null || _scrollBodyRef$curren === void 0 || _scrollBodyRef$curren.scrollTo({
  195. top: top
  196. });
  197. } else {
  198. var _scrollBodyRef$curren2;
  199. var mergedKey = key !== null && key !== void 0 ? key : getRowKey(mergedData[index]);
  200. (_scrollBodyRef$curren2 = scrollBodyRef.current.querySelector("[data-row-key=\"".concat(mergedKey, "\"]"))) === null || _scrollBodyRef$curren2 === void 0 || _scrollBodyRef$curren2.scrollIntoView();
  201. }
  202. } else if ((_scrollBodyRef$curren3 = scrollBodyRef.current) !== null && _scrollBodyRef$curren3 !== void 0 && _scrollBodyRef$curren3.scrollTo) {
  203. // Pass to proxy
  204. scrollBodyRef.current.scrollTo(config);
  205. }
  206. }
  207. };
  208. });
  209. // ====================== Scroll ======================
  210. var scrollSummaryRef = React.useRef();
  211. var _React$useState3 = React.useState(false),
  212. _React$useState4 = _slicedToArray(_React$useState3, 2),
  213. pingedLeft = _React$useState4[0],
  214. setPingedLeft = _React$useState4[1];
  215. var _React$useState5 = React.useState(false),
  216. _React$useState6 = _slicedToArray(_React$useState5, 2),
  217. pingedRight = _React$useState6[0],
  218. setPingedRight = _React$useState6[1];
  219. var _React$useState7 = React.useState(new Map()),
  220. _React$useState8 = _slicedToArray(_React$useState7, 2),
  221. colsWidths = _React$useState8[0],
  222. updateColsWidths = _React$useState8[1];
  223. // Convert map to number width
  224. var colsKeys = getColumnsKey(flattenColumns);
  225. var pureColWidths = colsKeys.map(function (columnKey) {
  226. return colsWidths.get(columnKey);
  227. });
  228. var colWidths = React.useMemo(function () {
  229. return pureColWidths;
  230. }, [pureColWidths.join('_')]);
  231. var stickyOffsets = useStickyOffsets(colWidths, flattenColumns, direction);
  232. var fixHeader = scroll && validateValue(scroll.y);
  233. var horizonScroll = scroll && validateValue(mergedScrollX) || Boolean(expandableConfig.fixed);
  234. var fixColumn = horizonScroll && flattenColumns.some(function (_ref) {
  235. var fixed = _ref.fixed;
  236. return fixed;
  237. });
  238. // Sticky
  239. var stickyRef = React.useRef();
  240. var _useSticky = useSticky(sticky, prefixCls),
  241. isSticky = _useSticky.isSticky,
  242. offsetHeader = _useSticky.offsetHeader,
  243. offsetSummary = _useSticky.offsetSummary,
  244. offsetScroll = _useSticky.offsetScroll,
  245. stickyClassName = _useSticky.stickyClassName,
  246. container = _useSticky.container;
  247. // Footer (Fix footer must fixed header)
  248. var summaryNode = React.useMemo(function () {
  249. return summary === null || summary === void 0 ? void 0 : summary(mergedData);
  250. }, [summary, mergedData]);
  251. var fixFooter = (fixHeader || isSticky) && /*#__PURE__*/React.isValidElement(summaryNode) && summaryNode.type === Summary && summaryNode.props.fixed;
  252. // Scroll
  253. var scrollXStyle;
  254. var scrollYStyle;
  255. var scrollTableStyle;
  256. if (fixHeader) {
  257. scrollYStyle = {
  258. overflowY: hasData ? 'scroll' : 'auto',
  259. maxHeight: scroll.y
  260. };
  261. }
  262. if (horizonScroll) {
  263. scrollXStyle = {
  264. overflowX: 'auto'
  265. };
  266. // When no vertical scrollbar, should hide it
  267. // https://github.com/ant-design/ant-design/pull/20705
  268. // https://github.com/ant-design/ant-design/issues/21879
  269. if (!fixHeader) {
  270. scrollYStyle = {
  271. overflowY: 'hidden'
  272. };
  273. }
  274. scrollTableStyle = {
  275. width: mergedScrollX === true ? 'auto' : mergedScrollX,
  276. minWidth: '100%'
  277. };
  278. }
  279. var onColumnResize = React.useCallback(function (columnKey, width) {
  280. updateColsWidths(function (widths) {
  281. if (widths.get(columnKey) !== width) {
  282. var newWidths = new Map(widths);
  283. newWidths.set(columnKey, width);
  284. return newWidths;
  285. }
  286. return widths;
  287. });
  288. }, []);
  289. var _useTimeoutLock = useTimeoutLock(null),
  290. _useTimeoutLock2 = _slicedToArray(_useTimeoutLock, 2),
  291. setScrollTarget = _useTimeoutLock2[0],
  292. getScrollTarget = _useTimeoutLock2[1];
  293. function forceScroll(scrollLeft, target) {
  294. if (!target) {
  295. return;
  296. }
  297. if (typeof target === 'function') {
  298. target(scrollLeft);
  299. } else if (target.scrollLeft !== scrollLeft) {
  300. target.scrollLeft = scrollLeft;
  301. // Delay to force scroll position if not sync
  302. // ref: https://github.com/ant-design/ant-design/issues/37179
  303. if (target.scrollLeft !== scrollLeft) {
  304. setTimeout(function () {
  305. target.scrollLeft = scrollLeft;
  306. }, 0);
  307. }
  308. }
  309. }
  310. var onInternalScroll = useEvent(function (_ref2) {
  311. var currentTarget = _ref2.currentTarget,
  312. scrollLeft = _ref2.scrollLeft;
  313. var isRTL = direction === 'rtl';
  314. var mergedScrollLeft = typeof scrollLeft === 'number' ? scrollLeft : currentTarget.scrollLeft;
  315. var compareTarget = currentTarget || EMPTY_SCROLL_TARGET;
  316. if (!getScrollTarget() || getScrollTarget() === compareTarget) {
  317. var _stickyRef$current;
  318. setScrollTarget(compareTarget);
  319. forceScroll(mergedScrollLeft, scrollHeaderRef.current);
  320. forceScroll(mergedScrollLeft, scrollBodyRef.current);
  321. forceScroll(mergedScrollLeft, scrollSummaryRef.current);
  322. forceScroll(mergedScrollLeft, (_stickyRef$current = stickyRef.current) === null || _stickyRef$current === void 0 ? void 0 : _stickyRef$current.setScrollLeft);
  323. }
  324. var measureTarget = currentTarget || scrollHeaderRef.current;
  325. if (measureTarget) {
  326. var scrollWidth =
  327. // Should use mergedScrollX in virtual table(useInternalHooks && tailor === true)
  328. useInternalHooks && tailor && typeof mergedScrollX === 'number' ? mergedScrollX : measureTarget.scrollWidth;
  329. var clientWidth = measureTarget.clientWidth;
  330. // There is no space to scroll
  331. if (scrollWidth === clientWidth) {
  332. setPingedLeft(false);
  333. setPingedRight(false);
  334. return;
  335. }
  336. if (isRTL) {
  337. setPingedLeft(-mergedScrollLeft < scrollWidth - clientWidth);
  338. setPingedRight(-mergedScrollLeft > 0);
  339. } else {
  340. setPingedLeft(mergedScrollLeft > 0);
  341. setPingedRight(mergedScrollLeft < scrollWidth - clientWidth);
  342. }
  343. }
  344. });
  345. var onBodyScroll = useEvent(function (e) {
  346. onInternalScroll(e);
  347. onScroll === null || onScroll === void 0 || onScroll(e);
  348. });
  349. var triggerOnScroll = function triggerOnScroll() {
  350. if (horizonScroll && scrollBodyRef.current) {
  351. var _scrollBodyRef$curren4;
  352. onInternalScroll({
  353. currentTarget: getDOM(scrollBodyRef.current),
  354. scrollLeft: (_scrollBodyRef$curren4 = scrollBodyRef.current) === null || _scrollBodyRef$curren4 === void 0 ? void 0 : _scrollBodyRef$curren4.scrollLeft
  355. });
  356. } else {
  357. setPingedLeft(false);
  358. setPingedRight(false);
  359. }
  360. };
  361. var onFullTableResize = function onFullTableResize(_ref3) {
  362. var _stickyRef$current2;
  363. var width = _ref3.width;
  364. (_stickyRef$current2 = stickyRef.current) === null || _stickyRef$current2 === void 0 || _stickyRef$current2.checkScrollBarVisible();
  365. var mergedWidth = fullTableRef.current ? fullTableRef.current.offsetWidth : width;
  366. if (useInternalHooks && getContainerWidth && fullTableRef.current) {
  367. mergedWidth = getContainerWidth(fullTableRef.current, mergedWidth) || mergedWidth;
  368. }
  369. if (mergedWidth !== componentWidth) {
  370. triggerOnScroll();
  371. setComponentWidth(mergedWidth);
  372. }
  373. };
  374. // Sync scroll bar when init or `horizonScroll`, `data` and `columns.length` changed
  375. var mounted = React.useRef(false);
  376. React.useEffect(function () {
  377. // onFullTableResize will be trigger once when ResizeObserver is mounted
  378. // This will reduce one duplicated triggerOnScroll time
  379. if (mounted.current) {
  380. triggerOnScroll();
  381. }
  382. }, [horizonScroll, data, columns.length]);
  383. React.useEffect(function () {
  384. mounted.current = true;
  385. }, []);
  386. // ===================== Effects ======================
  387. var _React$useState9 = React.useState(0),
  388. _React$useState10 = _slicedToArray(_React$useState9, 2),
  389. scrollbarSize = _React$useState10[0],
  390. setScrollbarSize = _React$useState10[1];
  391. var _React$useState11 = React.useState(true),
  392. _React$useState12 = _slicedToArray(_React$useState11, 2),
  393. supportSticky = _React$useState12[0],
  394. setSupportSticky = _React$useState12[1]; // Only IE not support, we mark as support first
  395. useLayoutEffect(function () {
  396. if (!tailor || !useInternalHooks) {
  397. if (scrollBodyRef.current instanceof Element) {
  398. setScrollbarSize(getTargetScrollBarSize(scrollBodyRef.current).width);
  399. } else {
  400. setScrollbarSize(getTargetScrollBarSize(scrollBodyContainerRef.current).width);
  401. }
  402. }
  403. setSupportSticky(isStyleSupport('position', 'sticky'));
  404. }, []);
  405. // ================== INTERNAL HOOKS ==================
  406. React.useEffect(function () {
  407. if (useInternalHooks && internalRefs) {
  408. internalRefs.body.current = scrollBodyRef.current;
  409. }
  410. });
  411. // ========================================================================
  412. // == Render ==
  413. // ========================================================================
  414. // =================== Render: Func ===================
  415. var renderFixedHeaderTable = React.useCallback(function (fixedHolderPassProps) {
  416. return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, fixedHolderPassProps), fixFooter === 'top' && /*#__PURE__*/React.createElement(Footer, fixedHolderPassProps, summaryNode));
  417. }, [fixFooter, summaryNode]);
  418. var renderFixedFooterTable = React.useCallback(function (fixedHolderPassProps) {
  419. return /*#__PURE__*/React.createElement(Footer, fixedHolderPassProps, summaryNode);
  420. }, [summaryNode]);
  421. // =================== Render: Node ===================
  422. var TableComponent = getComponent(['table'], 'table');
  423. // Table layout
  424. var mergedTableLayout = React.useMemo(function () {
  425. if (tableLayout) {
  426. return tableLayout;
  427. }
  428. // https://github.com/ant-design/ant-design/issues/25227
  429. // When scroll.x is max-content, no need to fix table layout
  430. // it's width should stretch out to fit content
  431. if (fixColumn) {
  432. return mergedScrollX === 'max-content' ? 'auto' : 'fixed';
  433. }
  434. if (fixHeader || isSticky || flattenColumns.some(function (_ref4) {
  435. var ellipsis = _ref4.ellipsis;
  436. return ellipsis;
  437. })) {
  438. return 'fixed';
  439. }
  440. return 'auto';
  441. }, [fixHeader, fixColumn, flattenColumns, tableLayout, isSticky]);
  442. var groupTableNode;
  443. // Header props
  444. var headerProps = {
  445. colWidths: colWidths,
  446. columCount: flattenColumns.length,
  447. stickyOffsets: stickyOffsets,
  448. onHeaderRow: onHeaderRow,
  449. fixHeader: fixHeader,
  450. scroll: scroll
  451. };
  452. // Empty
  453. var emptyNode = React.useMemo(function () {
  454. if (hasData) {
  455. return null;
  456. }
  457. if (typeof emptyText === 'function') {
  458. return emptyText();
  459. }
  460. return emptyText;
  461. }, [hasData, emptyText]);
  462. // Body
  463. var bodyTable = /*#__PURE__*/React.createElement(Body, {
  464. data: mergedData,
  465. measureColumnWidth: fixHeader || horizonScroll || isSticky
  466. });
  467. var bodyColGroup = /*#__PURE__*/React.createElement(ColGroup, {
  468. colWidths: flattenColumns.map(function (_ref5) {
  469. var width = _ref5.width;
  470. return width;
  471. }),
  472. columns: flattenColumns
  473. });
  474. var captionElement = caption !== null && caption !== undefined ? /*#__PURE__*/React.createElement("caption", {
  475. className: "".concat(prefixCls, "-caption")
  476. }, caption) : undefined;
  477. var dataProps = pickAttrs(props, {
  478. data: true
  479. });
  480. var ariaProps = pickAttrs(props, {
  481. aria: true
  482. });
  483. if (fixHeader || isSticky) {
  484. // >>>>>> Fixed Header
  485. var bodyContent;
  486. if (typeof customizeScrollBody === 'function') {
  487. bodyContent = customizeScrollBody(mergedData, {
  488. scrollbarSize: scrollbarSize,
  489. ref: scrollBodyRef,
  490. onScroll: onInternalScroll
  491. });
  492. headerProps.colWidths = flattenColumns.map(function (_ref6, index) {
  493. var width = _ref6.width;
  494. var colWidth = index === flattenColumns.length - 1 ? width - scrollbarSize : width;
  495. if (typeof colWidth === 'number' && !Number.isNaN(colWidth)) {
  496. return colWidth;
  497. }
  498. if (process.env.NODE_ENV !== 'production') {
  499. warning(props.columns.length === 0, 'When use `components.body` with render props. Each column should have a fixed `width` value.');
  500. }
  501. return 0;
  502. });
  503. } else {
  504. bodyContent = /*#__PURE__*/React.createElement("div", {
  505. style: _objectSpread(_objectSpread({}, scrollXStyle), scrollYStyle),
  506. onScroll: onBodyScroll,
  507. ref: scrollBodyRef,
  508. className: classNames("".concat(prefixCls, "-body"))
  509. }, /*#__PURE__*/React.createElement(TableComponent, _extends({
  510. style: _objectSpread(_objectSpread({}, scrollTableStyle), {}, {
  511. tableLayout: mergedTableLayout
  512. })
  513. }, ariaProps), captionElement, bodyColGroup, bodyTable, !fixFooter && summaryNode && /*#__PURE__*/React.createElement(Footer, {
  514. stickyOffsets: stickyOffsets,
  515. flattenColumns: flattenColumns
  516. }, summaryNode)));
  517. }
  518. // Fixed holder share the props
  519. var fixedHolderProps = _objectSpread(_objectSpread(_objectSpread({
  520. noData: !mergedData.length
  521. }, headerProps), columnContext), {}, {
  522. direction: direction,
  523. stickyClassName: stickyClassName,
  524. scrollX: mergedScrollX,
  525. tableLayout: mergedTableLayout,
  526. onScroll: onInternalScroll
  527. });
  528. groupTableNode = /*#__PURE__*/React.createElement(React.Fragment, null, showHeader !== false && /*#__PURE__*/React.createElement(FixedHolder, _extends({}, fixedHolderProps, {
  529. stickyTopOffset: offsetHeader,
  530. className: "".concat(prefixCls, "-header"),
  531. ref: scrollHeaderRef,
  532. colGroup: bodyColGroup
  533. }), renderFixedHeaderTable), bodyContent, fixFooter && fixFooter !== 'top' && /*#__PURE__*/React.createElement(FixedHolder, _extends({}, fixedHolderProps, {
  534. stickyBottomOffset: offsetSummary,
  535. className: "".concat(prefixCls, "-summary"),
  536. ref: scrollSummaryRef,
  537. colGroup: bodyColGroup
  538. }), renderFixedFooterTable), isSticky && scrollBodyRef.current && scrollBodyRef.current instanceof Element && /*#__PURE__*/React.createElement(StickyScrollBar, {
  539. ref: stickyRef,
  540. offsetScroll: offsetScroll,
  541. scrollBodyRef: scrollBodyRef,
  542. onScroll: onInternalScroll,
  543. container: container,
  544. direction: direction
  545. }));
  546. } else {
  547. // >>>>>> Unique table
  548. groupTableNode = /*#__PURE__*/React.createElement("div", {
  549. style: _objectSpread(_objectSpread({}, scrollXStyle), scrollYStyle),
  550. className: classNames("".concat(prefixCls, "-content")),
  551. onScroll: onInternalScroll,
  552. ref: scrollBodyRef
  553. }, /*#__PURE__*/React.createElement(TableComponent, _extends({
  554. style: _objectSpread(_objectSpread({}, scrollTableStyle), {}, {
  555. tableLayout: mergedTableLayout
  556. })
  557. }, ariaProps), captionElement, bodyColGroup, showHeader !== false && /*#__PURE__*/React.createElement(Header, _extends({}, headerProps, columnContext)), bodyTable, summaryNode && /*#__PURE__*/React.createElement(Footer, {
  558. stickyOffsets: stickyOffsets,
  559. flattenColumns: flattenColumns
  560. }, summaryNode)));
  561. }
  562. var fullTable = /*#__PURE__*/React.createElement("div", _extends({
  563. className: classNames(prefixCls, className, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-rtl"), direction === 'rtl'), "".concat(prefixCls, "-ping-left"), pingedLeft), "".concat(prefixCls, "-ping-right"), pingedRight), "".concat(prefixCls, "-layout-fixed"), tableLayout === 'fixed'), "".concat(prefixCls, "-fixed-header"), fixHeader), "".concat(prefixCls, "-fixed-column"), fixColumn), "".concat(prefixCls, "-fixed-column-gapped"), fixColumn && hasGapFixed), "".concat(prefixCls, "-scroll-horizontal"), horizonScroll), "".concat(prefixCls, "-has-fix-left"), flattenColumns[0] && flattenColumns[0].fixed), "".concat(prefixCls, "-has-fix-right"), flattenColumns[flattenColumns.length - 1] && flattenColumns[flattenColumns.length - 1].fixed === 'right')),
  564. style: style,
  565. id: id,
  566. ref: fullTableRef
  567. }, dataProps), title && /*#__PURE__*/React.createElement(Panel, {
  568. className: "".concat(prefixCls, "-title")
  569. }, title(mergedData)), /*#__PURE__*/React.createElement("div", {
  570. ref: scrollBodyContainerRef,
  571. className: "".concat(prefixCls, "-container")
  572. }, groupTableNode), footer && /*#__PURE__*/React.createElement(Panel, {
  573. className: "".concat(prefixCls, "-footer")
  574. }, footer(mergedData)));
  575. if (horizonScroll) {
  576. fullTable = /*#__PURE__*/React.createElement(ResizeObserver, {
  577. onResize: onFullTableResize
  578. }, fullTable);
  579. }
  580. var fixedInfoList = useFixedInfo(flattenColumns, stickyOffsets, direction);
  581. var TableContextValue = React.useMemo(function () {
  582. return {
  583. // Scroll
  584. scrollX: mergedScrollX,
  585. // Table
  586. prefixCls: prefixCls,
  587. getComponent: getComponent,
  588. scrollbarSize: scrollbarSize,
  589. direction: direction,
  590. fixedInfoList: fixedInfoList,
  591. isSticky: isSticky,
  592. supportSticky: supportSticky,
  593. componentWidth: componentWidth,
  594. fixHeader: fixHeader,
  595. fixColumn: fixColumn,
  596. horizonScroll: horizonScroll,
  597. // Body
  598. tableLayout: mergedTableLayout,
  599. rowClassName: rowClassName,
  600. expandedRowClassName: expandableConfig.expandedRowClassName,
  601. expandIcon: mergedExpandIcon,
  602. expandableType: expandableType,
  603. expandRowByClick: expandableConfig.expandRowByClick,
  604. expandedRowRender: expandableConfig.expandedRowRender,
  605. expandedRowOffset: expandableConfig.expandedRowOffset,
  606. onTriggerExpand: onTriggerExpand,
  607. expandIconColumnIndex: expandableConfig.expandIconColumnIndex,
  608. indentSize: expandableConfig.indentSize,
  609. allColumnsFixedLeft: flattenColumns.every(function (col) {
  610. return col.fixed === 'left';
  611. }),
  612. emptyNode: emptyNode,
  613. // Column
  614. columns: columns,
  615. flattenColumns: flattenColumns,
  616. onColumnResize: onColumnResize,
  617. colWidths: colWidths,
  618. // Row
  619. hoverStartRow: startRow,
  620. hoverEndRow: endRow,
  621. onHover: onHover,
  622. rowExpandable: expandableConfig.rowExpandable,
  623. onRow: onRow,
  624. getRowKey: getRowKey,
  625. expandedKeys: mergedExpandedKeys,
  626. childrenColumnName: mergedChildrenColumnName,
  627. rowHoverable: rowHoverable,
  628. // Measure Row
  629. measureRowRender: measureRowRender
  630. };
  631. }, [
  632. // Scroll
  633. mergedScrollX,
  634. // Table
  635. prefixCls, getComponent, scrollbarSize, direction, fixedInfoList, isSticky, supportSticky, componentWidth, fixHeader, fixColumn, horizonScroll,
  636. // Body
  637. mergedTableLayout, rowClassName, expandableConfig.expandedRowClassName, mergedExpandIcon, expandableType, expandableConfig.expandRowByClick, expandableConfig.expandedRowRender, expandableConfig.expandedRowOffset, onTriggerExpand, expandableConfig.expandIconColumnIndex, expandableConfig.indentSize, emptyNode,
  638. // Column
  639. columns, flattenColumns, onColumnResize, colWidths,
  640. // Row
  641. startRow, endRow, onHover, expandableConfig.rowExpandable, onRow, getRowKey, mergedExpandedKeys, mergedChildrenColumnName, rowHoverable, measureRowRender]);
  642. return /*#__PURE__*/React.createElement(TableContext.Provider, {
  643. value: TableContextValue
  644. }, fullTable);
  645. }
  646. var RefTable = /*#__PURE__*/React.forwardRef(Table);
  647. if (process.env.NODE_ENV !== 'production') {
  648. RefTable.displayName = 'Table';
  649. }
  650. export function genTable(shouldTriggerRender) {
  651. return makeImmutable(RefTable, shouldTriggerRender);
  652. }
  653. var ImmutableTable = genTable();
  654. ImmutableTable.EXPAND_COLUMN = EXPAND_COLUMN;
  655. ImmutableTable.INTERNAL_HOOKS = INTERNAL_HOOKS;
  656. ImmutableTable.Column = Column;
  657. ImmutableTable.ColumnGroup = ColumnGroup;
  658. ImmutableTable.Summary = FooterComponents;
  659. export default ImmutableTable;