1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 | var _context = require("@rc-component/context");
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | var _PerfContext = _interopRequireDefault(require("../context/PerfContext"));
|
12 | var _TableContext = _interopRequireWildcard(require("../context/TableContext"));
|
13 | var _useFlattenRecords = _interopRequireDefault(require("../hooks/useFlattenRecords"));
|
14 | var _useRenderTimes = _interopRequireDefault(require("../hooks/useRenderTimes"));
|
15 | var _valueUtil = require("../utils/valueUtil");
|
16 | var _BodyRow = _interopRequireDefault(require("./BodyRow"));
|
17 | var _ExpandedRow = _interopRequireDefault(require("./ExpandedRow"));
|
18 | var _MeasureRow = _interopRequireDefault(require("./MeasureRow"));
|
19 | function _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); }
|
20 | function _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; }
|
21 | function 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 |
|
39 | var perfRef = React.useRef({
|
40 | renderWithProps: false
|
41 | });
|
42 |
|
43 |
|
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 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 = 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 React.createElement(_PerfContext.default.Provider, {
|
81 | value: perfRef.current
|
82 | }, React.createElement(WrapperComponent, {
|
83 | className: "".concat(prefixCls, "-tbody")
|
84 | }, measureColumnWidth && React.createElement(_MeasureRow.default, {
|
85 | prefixCls: prefixCls,
|
86 | columnsKey: columnsKey,
|
87 | onColumnResize: onColumnResize
|
88 | }), rows));
|
89 | }
|
90 | if (process.env.NODE_ENV !== 'production') {
|
91 | Body.displayName = 'Body';
|
92 | }
|
93 | var _default = exports.default = (0, _TableContext.responseImmutable)(Body); |
\ | No newline at end of file |