@txdfe/at
Version:
一个设计体系组件库
230 lines (182 loc) • 11.4 kB
JavaScript
"use strict";
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); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames2 = _interopRequireDefault(require("classnames"));
var _row = _interopRequireDefault(require("./row"));
var _cell = _interopRequireDefault(require("./cell"));
var _excluded = ["prefix", "className", "children", "component", "colGroup", "loading", "emptyContent", "components", "getCellProps", "primaryKey", "getRowProps", "dataSource", "cellRef", "columns", "rowRef", "onRowClick", "onRowMouseEnter", "onRowMouseLeave", "locale", "pure", "expandedIndexSimulate", "rtl", "table"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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; }
var noop = function noop() {};
var Body = /*#__PURE__*/function (_React$Component) {
_inherits(Body, _React$Component);
var _super = _createSuper(Body);
function Body() {
var _this;
_classCallCheck(this, Body);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "getRowRef", function (i, row) {
_this.props.rowRef(i, row);
});
_defineProperty(_assertThisInitialized(_this), "onRowClick", function (record, index, e) {
_this.props.onRowClick(record, index, e);
});
_defineProperty(_assertThisInitialized(_this), "onRowMouseEnter", function (record, index, e) {
_this.props.onRowMouseEnter(record, index, e);
});
_defineProperty(_assertThisInitialized(_this), "onRowMouseLeave", function (record, index, e) {
_this.props.onRowMouseLeave(record, index, e);
});
return _this;
}
_createClass(Body, [{
key: "render",
value: function render() {
var _this2 = this;
/* eslint-disable no-unused-vars */
var _this$props = this.props,
prefix = _this$props.prefix,
className = _this$props.className,
children = _this$props.children,
Tag = _this$props.component,
colGroup = _this$props.colGroup,
loading = _this$props.loading,
emptyContent = _this$props.emptyContent,
components = _this$props.components,
getCellProps = _this$props.getCellProps,
primaryKey = _this$props.primaryKey,
getRowProps = _this$props.getRowProps,
dataSource = _this$props.dataSource,
cellRef = _this$props.cellRef,
columns = _this$props.columns,
rowRef = _this$props.rowRef,
onRowClick = _this$props.onRowClick,
onRowMouseEnter = _this$props.onRowMouseEnter,
onRowMouseLeave = _this$props.onRowMouseLeave,
locale = _this$props.locale,
pure = _this$props.pure,
expandedIndexSimulate = _this$props.expandedIndexSimulate,
rtl = _this$props.rtl,
table = _this$props.table,
others = _objectWithoutProperties(_this$props, _excluded);
delete others.table;
var _components$Row = components.Row,
Row = _components$Row === void 0 ? _row["default"] : _components$Row,
_components$Cell = components.Cell,
Cell = _components$Cell === void 0 ? _cell["default"] : _components$Cell;
var empty = loading ? /*#__PURE__*/_react["default"].createElement("span", null, "\xA0") : emptyContent || locale.empty;
var rows = /*#__PURE__*/_react["default"].createElement("tr", null, /*#__PURE__*/_react["default"].createElement("td", {
colSpan: columns.length
}, /*#__PURE__*/_react["default"].createElement("div", {
className: "".concat(prefix, "table-empty")
}, empty)));
if (Tag === 'div') {
rows = /*#__PURE__*/_react["default"].createElement("table", {
role: "table"
}, /*#__PURE__*/_react["default"].createElement("tbody", null, rows));
}
if (dataSource.length) {
rows = dataSource.map(function (record, index) {
var rowProps = {};
if (expandedIndexSimulate) {
rowProps = record.__expanded ? {} : getRowProps(record, index / 2);
} else {
rowProps = getRowProps(record, index);
}
rowProps = rowProps || {};
var rowClass = rowProps.className;
var rowClassName = (0, _classnames2["default"])(_defineProperty({
first: index === 0,
last: index === dataSource.length - 1
}, rowClass, rowClass));
var expanded = record.__expanded ? 'expanded' : '';
return /*#__PURE__*/_react["default"].createElement(Row, _extends({
key: "".concat(record[primaryKey] || index).concat(expanded)
}, rowProps, {
ref: _this2.getRowRef.bind(_this2, index),
colGroup: colGroup,
rtl: rtl,
columns: columns,
primaryKey: primaryKey,
record: record,
rowIndex: index,
prefix: prefix,
pure: pure,
cellRef: cellRef,
getCellProps: getCellProps,
className: rowClassName,
Cell: Cell,
onClick: _this2.onRowClick,
locale: locale,
onMouseEnter: _this2.onRowMouseEnter,
onMouseLeave: _this2.onRowMouseLeave,
table: table
}));
});
}
return /*#__PURE__*/_react["default"].createElement(Tag, _extends({
className: className
}, others), rows, children);
}
}]);
return Body;
}(_react["default"].Component);
exports["default"] = Body;
_defineProperty(Body, "propTypes", {
loading: _propTypes["default"].bool,
emptyContent: _propTypes["default"].any,
prefix: _propTypes["default"].string,
pure: _propTypes["default"].bool,
components: _propTypes["default"].object,
getCellProps: _propTypes["default"].func,
cellRef: _propTypes["default"].func,
primaryKey: _propTypes["default"].string,
getRowProps: _propTypes["default"].func,
rowRef: _propTypes["default"].func,
dataSource: _propTypes["default"].array,
children: _propTypes["default"].any,
className: _propTypes["default"].string,
component: _propTypes["default"].string,
colGroup: _propTypes["default"].object,
columns: _propTypes["default"].array,
onRowClick: _propTypes["default"].func,
onRowMouseEnter: _propTypes["default"].func,
onRowMouseLeave: _propTypes["default"].func,
locale: _propTypes["default"].object,
table: _propTypes["default"].object
});
_defineProperty(Body, "defaultProps", {
loading: false,
prefix: 'next-',
components: {},
getCellProps: noop,
cellRef: noop,
primaryKey: 'id',
getRowProps: noop,
rowRef: noop,
dataSource: [],
component: 'tbody',
columns: [],
table: null
});