@txdfe/at
Version:
一个设计体系组件库
176 lines (133 loc) • 10.1 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["record", "rowIndex", "columns"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React from 'react';
import PropTypes from 'prop-types';
import { log } from '../../util';
import Row from '../lock/row';
var ExpandedRow = /*#__PURE__*/function (_React$Component) {
_inherits(ExpandedRow, _React$Component);
var _super = _createSuper(ExpandedRow);
function ExpandedRow() {
_classCallCheck(this, ExpandedRow);
return _super.apply(this, arguments);
}
_createClass(ExpandedRow, [{
key: "renderExpandedRow",
value: function renderExpandedRow(record, index, colSpan) {
var _this$context = this.context,
expandedRowRender = _this$context.expandedRowRender,
expandedRowIndent = _this$context.expandedRowIndent,
openRowKeys = _this$context.openRowKeys,
lockType = _this$context.lockType;
var _this$props = this.props,
columns = _this$props.columns,
cellRef = _this$props.cellRef;
if (expandedRowRender) {
var _this$props2 = this.props,
primaryKey = _this$props2.primaryKey,
prefix = _this$props2.prefix,
leftIndent = expandedRowIndent[0],
rightIndent = expandedRowIndent[1],
totalIndent = leftIndent + rightIndent,
renderCols = function renderCols(number) {
var ret = [];
var _loop = function _loop(i) {
ret.push( /*#__PURE__*/React.createElement("td", {
key: i,
ref: function ref(cell) {
return cellRef(index, i, cell);
}
}, "\xA0"));
};
for (var i = 0; i < number; i++) {
_loop(i);
}
return ret;
};
var content;
if (totalIndent > colSpan && !lockType) {
log.warning("It's not allowed expandedRowIndent is more than the number of columns.");
}
if (leftIndent < columns.length && lockType === 'left') {
log.warning('expandedRowIndent left is less than the number of left lock columns.');
}
if (rightIndent < columns.length && lockType === 'right') {
log.warning('expandedRowIndent right is less than the number of right lock columns.');
}
if (lockType) {
return openRowKeys.indexOf(record[primaryKey]) > -1 ? /*#__PURE__*/React.createElement("tr", {
className: "".concat(prefix, "table-expanded-row"),
key: "expanded-".concat(index)
}, /*#__PURE__*/React.createElement("td", {
colSpan: colSpan,
ref: function ref(cell) {
return cellRef(index, 0, cell);
}
}, "\xA0")) : null;
}
content = expandedRowRender(record, index);
if (! /*#__PURE__*/React.isValidElement(content)) {
content = /*#__PURE__*/React.createElement("div", {
className: "".concat(prefix, "table-cell-wrapper")
}, content);
}
return openRowKeys.indexOf(record[primaryKey]) > -1 ? /*#__PURE__*/React.createElement("tr", {
className: "".concat(prefix, "table-expanded-row"),
key: "expanded-".concat(record[primaryKey] || index)
}, renderCols(leftIndent), /*#__PURE__*/React.createElement("td", {
colSpan: colSpan - totalIndent
}, content), renderCols(rightIndent)) : null;
} else {
return null;
}
}
}, {
key: "render",
value: function render() {
/* eslint-disable no-unused-vars*/
var _this$props3 = this.props,
record = _this$props3.record,
rowIndex = _this$props3.rowIndex,
columns = _this$props3.columns,
others = _objectWithoutProperties(_this$props3, _excluded);
var expandedIndexSimulate = this.context.expandedIndexSimulate;
if (record.__expanded) {
var expandedIndex = expandedIndexSimulate ? (rowIndex - 1) / 2 : rowIndex;
return this.renderExpandedRow(record, expandedIndex, columns.length);
}
var newRowIndex = expandedIndexSimulate ? rowIndex / 2 : rowIndex;
return /*#__PURE__*/React.createElement(Row, _extends({}, others, {
record: record,
columns: columns,
rowIndex: newRowIndex
}));
}
}]);
return ExpandedRow;
}(React.Component);
_defineProperty(ExpandedRow, "propTypes", _objectSpread({}, Row.propTypes));
_defineProperty(ExpandedRow, "defaultProps", _objectSpread({}, Row.defaultProps));
_defineProperty(ExpandedRow, "contextTypes", {
openRowKeys: PropTypes.array,
expandedRowRender: PropTypes.func,
expandedRowIndent: PropTypes.array,
expandedIndexSimulate: PropTypes.bool,
lockType: PropTypes.oneOf(['left', 'right'])
});
export { ExpandedRow as default };