amis-rpc-design/node_modules/rc-table/lib/VirtualTable/BodyLine.js

109 lines
6.0 KiB
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _context = require("@rc-component/context");
var _classnames = _interopRequireDefault(require("classnames"));
var React = _interopRequireWildcard(require("react"));
var _Cell = _interopRequireDefault(require("../Cell"));
var _TableContext = _interopRequireWildcard(require("../context/TableContext"));
var _useRowInfo = _interopRequireDefault(require("../hooks/useRowInfo"));
var _VirtualCell = _interopRequireDefault(require("./VirtualCell"));
var _excluded = ["data", "index", "className", "rowKey", "style", "extra", "getHeight"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var BodyLine = /*#__PURE__*/React.forwardRef(function (props, ref) {
var data = props.data,
index = props.index,
className = props.className,
rowKey = props.rowKey,
style = props.style,
extra = props.extra,
getHeight = props.getHeight,
restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
var record = data.record,
indent = data.indent,
renderIndex = data.index;
var _useContext = (0, _context.useContext)(_TableContext.default, ['prefixCls', 'flattenColumns', 'fixColumn', 'componentWidth', 'scrollX']),
scrollX = _useContext.scrollX,
flattenColumns = _useContext.flattenColumns,
prefixCls = _useContext.prefixCls,
fixColumn = _useContext.fixColumn,
componentWidth = _useContext.componentWidth;
var rowInfo = (0, _useRowInfo.default)(record, rowKey, index, indent);
// ========================== Expand ==========================
var rowSupportExpand = rowInfo.rowSupportExpand,
expanded = rowInfo.expanded,
rowProps = rowInfo.rowProps,
expandedRowRender = rowInfo.expandedRowRender,
expandedRowClassName = rowInfo.expandedRowClassName;
var expandRowNode;
if (rowSupportExpand && expanded) {
var expandContent = expandedRowRender(record, index, indent + 1, expanded);
var computedExpandedRowClassName = expandedRowClassName === null || expandedRowClassName === void 0 ? void 0 : expandedRowClassName(record, index, indent);
var additionalProps = {};
if (fixColumn) {
additionalProps = {
style: (0, _defineProperty2.default)({}, '--virtual-width', "".concat(componentWidth, "px"))
};
}
var rowCellCls = "".concat(prefixCls, "-expanded-row-cell");
expandRowNode = /*#__PURE__*/React.createElement("div", {
className: (0, _classnames.default)("".concat(prefixCls, "-expanded-row"), "".concat(prefixCls, "-expanded-row-level-").concat(indent + 1), computedExpandedRowClassName)
}, /*#__PURE__*/React.createElement(_Cell.default, {
component: "div",
prefixCls: prefixCls,
className: (0, _classnames.default)(rowCellCls, (0, _defineProperty2.default)({}, "".concat(rowCellCls, "-fixed"), fixColumn)),
additionalProps: additionalProps
}, expandContent));
}
// ========================== Render ==========================
var rowStyle = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, style), {}, {
width: scrollX
});
if (extra) {
rowStyle.position = 'absolute';
rowStyle.pointerEvents = 'none';
}
var rowNode = /*#__PURE__*/React.createElement("div", (0, _extends2.default)({}, rowProps, restProps, {
ref: rowSupportExpand ? null : ref,
className: (0, _classnames.default)(className, "".concat(prefixCls, "-row"), rowProps === null || rowProps === void 0 ? void 0 : rowProps.className, (0, _defineProperty2.default)({}, "".concat(prefixCls, "-row-extra"), extra)),
style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, rowStyle), rowProps === null || rowProps === void 0 ? void 0 : rowProps.style)
}), flattenColumns.map(function (column, colIndex) {
return /*#__PURE__*/React.createElement(_VirtualCell.default, {
key: colIndex,
rowInfo: rowInfo,
column: column,
colIndex: colIndex,
indent: indent,
index: index,
renderIndex: renderIndex,
record: record,
inverse: extra,
getHeight: getHeight
});
}));
if (rowSupportExpand) {
return /*#__PURE__*/React.createElement("div", {
ref: ref
}, rowNode, expandRowNode);
}
return rowNode;
});
var ResponseBodyLine = (0, _TableContext.responseImmutable)(BodyLine);
if (process.env.NODE_ENV !== 'production') {
ResponseBodyLine.displayName = 'BodyLine';
}
var _default = ResponseBodyLine;
exports.default = _default;