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 | exports.getCellProps = getCellProps;
|
10 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
12 | var _classnames = _interopRequireDefault(require("classnames"));
|
13 | var React = _interopRequireWildcard(require("react"));
|
14 | var _Cell = _interopRequireDefault(require("../Cell"));
|
15 | var _TableContext = require("../context/TableContext");
|
16 | var _useRenderTimes = _interopRequireDefault(require("../hooks/useRenderTimes"));
|
17 | var _useRowInfo = _interopRequireDefault(require("../hooks/useRowInfo"));
|
18 | var _ExpandedRow = _interopRequireDefault(require("./ExpandedRow"));
|
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 |
|
22 |
|
23 |
|
24 | function getCellProps(rowInfo, column, colIndex, indent, index) {
|
25 | var record = rowInfo.record,
|
26 | prefixCls = rowInfo.prefixCls,
|
27 | columnsKey = rowInfo.columnsKey,
|
28 | fixedInfoList = rowInfo.fixedInfoList,
|
29 | expandIconColumnIndex = rowInfo.expandIconColumnIndex,
|
30 | nestExpandable = rowInfo.nestExpandable,
|
31 | indentSize = rowInfo.indentSize,
|
32 | expandIcon = rowInfo.expandIcon,
|
33 | expanded = rowInfo.expanded,
|
34 | hasNestChildren = rowInfo.hasNestChildren,
|
35 | onTriggerExpand = rowInfo.onTriggerExpand;
|
36 | var key = columnsKey[colIndex];
|
37 | var fixedInfo = fixedInfoList[colIndex];
|
38 |
|
39 |
|
40 | var appendCellNode;
|
41 | if (colIndex === (expandIconColumnIndex || 0) && nestExpandable) {
|
42 | appendCellNode = React.createElement(React.Fragment, null, React.createElement("span", {
|
43 | style: {
|
44 | paddingLeft: "".concat(indentSize * indent, "px")
|
45 | },
|
46 | className: "".concat(prefixCls, "-row-indent indent-level-").concat(indent)
|
47 | }), expandIcon({
|
48 | prefixCls: prefixCls,
|
49 | expanded: expanded,
|
50 | expandable: hasNestChildren,
|
51 | record: record,
|
52 | onExpand: onTriggerExpand
|
53 | }));
|
54 | }
|
55 | var additionalCellProps;
|
56 | if (column.onCell) {
|
57 | additionalCellProps = column.onCell(record, index);
|
58 | }
|
59 | return {
|
60 | key: key,
|
61 | fixedInfo: fixedInfo,
|
62 | appendCellNode: appendCellNode,
|
63 | additionalCellProps: additionalCellProps || {}
|
64 | };
|
65 | }
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | function BodyRow(props) {
|
71 | if (process.env.NODE_ENV !== 'production') {
|
72 | (0, _useRenderTimes.default)(props);
|
73 | }
|
74 | var className = props.className,
|
75 | style = props.style,
|
76 | record = props.record,
|
77 | index = props.index,
|
78 | renderIndex = props.renderIndex,
|
79 | rowKey = props.rowKey,
|
80 | _props$indent = props.indent,
|
81 | indent = _props$indent === void 0 ? 0 : _props$indent,
|
82 | RowComponent = props.rowComponent,
|
83 | cellComponent = props.cellComponent,
|
84 | scopeCellComponent = props.scopeCellComponent;
|
85 | var rowInfo = (0, _useRowInfo.default)(record, rowKey, index, indent);
|
86 | var prefixCls = rowInfo.prefixCls,
|
87 | flattenColumns = rowInfo.flattenColumns,
|
88 | expandedRowClassName = rowInfo.expandedRowClassName,
|
89 | expandedRowRender = rowInfo.expandedRowRender,
|
90 | rowProps = rowInfo.rowProps,
|
91 | expanded = rowInfo.expanded,
|
92 | rowSupportExpand = rowInfo.rowSupportExpand;
|
93 |
|
94 |
|
95 | var expandedRef = React.useRef(false);
|
96 | expandedRef.current || (expandedRef.current = expanded);
|
97 | if (process.env.NODE_ENV !== 'production') {
|
98 | (0, _useRenderTimes.default)(props);
|
99 | }
|
100 |
|
101 |
|
102 |
|
103 | var computedExpandedRowClassName = expandedRowClassName && expandedRowClassName(record, index, indent);
|
104 |
|
105 |
|
106 | var baseRowNode = React.createElement(RowComponent, (0, _extends2.default)({}, rowProps, {
|
107 | "data-row-key": rowKey,
|
108 | className: (0, _classnames.default)(className, "".concat(prefixCls, "-row"), "".concat(prefixCls, "-row-level-").concat(indent), rowProps === null || rowProps === void 0 ? void 0 : rowProps.className, indent >= 1 ? computedExpandedRowClassName : ''),
|
109 | style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, style), rowProps === null || rowProps === void 0 ? void 0 : rowProps.style)
|
110 | }), flattenColumns.map(function (column, colIndex) {
|
111 | var render = column.render,
|
112 | dataIndex = column.dataIndex,
|
113 | columnClassName = column.className;
|
114 | var _getCellProps = getCellProps(rowInfo, column, colIndex, indent, index),
|
115 | key = _getCellProps.key,
|
116 | fixedInfo = _getCellProps.fixedInfo,
|
117 | appendCellNode = _getCellProps.appendCellNode,
|
118 | additionalCellProps = _getCellProps.additionalCellProps;
|
119 | return React.createElement(_Cell.default, (0, _extends2.default)({
|
120 | className: columnClassName,
|
121 | ellipsis: column.ellipsis,
|
122 | align: column.align,
|
123 | scope: column.rowScope,
|
124 | component: column.rowScope ? scopeCellComponent : cellComponent,
|
125 | prefixCls: prefixCls,
|
126 | key: key,
|
127 | record: record,
|
128 | index: index,
|
129 | renderIndex: renderIndex,
|
130 | dataIndex: dataIndex,
|
131 | render: render,
|
132 | shouldCellUpdate: column.shouldCellUpdate
|
133 | }, fixedInfo, {
|
134 | appendNode: appendCellNode,
|
135 | additionalProps: additionalCellProps
|
136 | }));
|
137 | }));
|
138 |
|
139 |
|
140 | var expandRowNode;
|
141 | if (rowSupportExpand && (expandedRef.current || expanded)) {
|
142 | var expandContent = expandedRowRender(record, index, indent + 1, expanded);
|
143 | expandRowNode = React.createElement(_ExpandedRow.default, {
|
144 | expanded: expanded,
|
145 | className: (0, _classnames.default)("".concat(prefixCls, "-expanded-row"), "".concat(prefixCls, "-expanded-row-level-").concat(indent + 1), computedExpandedRowClassName),
|
146 | prefixCls: prefixCls,
|
147 | component: RowComponent,
|
148 | cellComponent: cellComponent,
|
149 | colSpan: flattenColumns.length,
|
150 | isEmpty: false
|
151 | }, expandContent);
|
152 | }
|
153 | return React.createElement(React.Fragment, null, baseRowNode, expandRowNode);
|
154 | }
|
155 | if (process.env.NODE_ENV !== 'production') {
|
156 | BodyRow.displayName = 'BodyRow';
|
157 | }
|
158 | var _default = exports.default = (0, _TableContext.responseImmutable)(BodyRow); |
\ | No newline at end of file |