UNPKG

4.56 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4var _typeof = require("@babel/runtime/helpers/typeof");
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = void 0;
9var _context = require("@rc-component/context");
10var React = _interopRequireWildcard(require("react"));
11var _PerfContext = _interopRequireDefault(require("../context/PerfContext"));
12var _TableContext = _interopRequireWildcard(require("../context/TableContext"));
13var _useFlattenRecords = _interopRequireDefault(require("../hooks/useFlattenRecords"));
14var _useRenderTimes = _interopRequireDefault(require("../hooks/useRenderTimes"));
15var _valueUtil = require("../utils/valueUtil");
16var _BodyRow = _interopRequireDefault(require("./BodyRow"));
17var _ExpandedRow = _interopRequireDefault(require("./ExpandedRow"));
18var _MeasureRow = _interopRequireDefault(require("./MeasureRow"));
19function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
20function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21function Body(props) {
22 if (process.env.NODE_ENV !== 'production') {
23 (0, _useRenderTimes.default)(props);
24 }
25 var data = props.data,
26 measureColumnWidth = props.measureColumnWidth;
27 var _useContext = (0, _context.useContext)(_TableContext.default, ['prefixCls', 'getComponent', 'onColumnResize', 'flattenColumns', 'getRowKey', 'expandedKeys', 'childrenColumnName', 'emptyNode']),
28 prefixCls = _useContext.prefixCls,
29 getComponent = _useContext.getComponent,
30 onColumnResize = _useContext.onColumnResize,
31 flattenColumns = _useContext.flattenColumns,
32 getRowKey = _useContext.getRowKey,
33 expandedKeys = _useContext.expandedKeys,
34 childrenColumnName = _useContext.childrenColumnName,
35 emptyNode = _useContext.emptyNode;
36 var flattenData = (0, _useFlattenRecords.default)(data, childrenColumnName, expandedKeys, getRowKey);
37
38 // =================== Performance ====================
39 var perfRef = React.useRef({
40 renderWithProps: false
41 });
42
43 // ====================== Render ======================
44 var WrapperComponent = getComponent(['body', 'wrapper'], 'tbody');
45 var trComponent = getComponent(['body', 'row'], 'tr');
46 var tdComponent = getComponent(['body', 'cell'], 'td');
47 var thComponent = getComponent(['body', 'cell'], 'th');
48 var rows;
49 if (data.length) {
50 rows = flattenData.map(function (item, idx) {
51 var record = item.record,
52 indent = item.indent,
53 renderIndex = item.index;
54 var key = getRowKey(record, idx);
55 return /*#__PURE__*/React.createElement(_BodyRow.default, {
56 key: key,
57 rowKey: key,
58 record: record,
59 index: idx,
60 renderIndex: renderIndex,
61 rowComponent: trComponent,
62 cellComponent: tdComponent,
63 scopeCellComponent: thComponent,
64 getRowKey: getRowKey,
65 indent: indent
66 });
67 });
68 } else {
69 rows = /*#__PURE__*/React.createElement(_ExpandedRow.default, {
70 expanded: true,
71 className: "".concat(prefixCls, "-placeholder"),
72 prefixCls: prefixCls,
73 component: trComponent,
74 cellComponent: tdComponent,
75 colSpan: flattenColumns.length,
76 isEmpty: true
77 }, emptyNode);
78 }
79 var columnsKey = (0, _valueUtil.getColumnsKey)(flattenColumns);
80 return /*#__PURE__*/React.createElement(_PerfContext.default.Provider, {
81 value: perfRef.current
82 }, /*#__PURE__*/React.createElement(WrapperComponent, {
83 className: "".concat(prefixCls, "-tbody")
84 }, measureColumnWidth && /*#__PURE__*/React.createElement(_MeasureRow.default, {
85 prefixCls: prefixCls,
86 columnsKey: columnsKey,
87 onColumnResize: onColumnResize
88 }), rows));
89}
90if (process.env.NODE_ENV !== 'production') {
91 Body.displayName = 'Body';
92}
93var _default = exports.default = (0, _TableContext.responseImmutable)(Body);
\No newline at end of file