@txdfe/at
Version:
一个设计体系组件库
198 lines (162 loc) • 11 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 = ["prefix", "className", "cell", "value", "resizable", "colIndex", "rowIndex", "record", "context", "align", "style", "component", "children", "title", "width", "innerStyle", "primaryKey", "__normalized", "filterMode", "filterMenuProps", "filters", "sortable", "lock", "pure", "locale", "expandedIndexSimulate", "rtl", "columnId", "table", "isInHeader", "type"];
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 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 _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 classnames from 'classnames';
import { obj } from '../../util';
var Cell = /*#__PURE__*/function (_React$Component) {
_inherits(Cell, _React$Component);
var _super = _createSuper(Cell);
function Cell() {
_classCallCheck(this, Cell);
return _super.apply(this, arguments);
}
_createClass(Cell, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate(nextProps) {
if (nextProps.pure) {
var isEqual = obj.shallowEqual(this.props, nextProps);
return !isEqual;
}
return true;
}
}, {
key: "render",
value: function render() {
var _classnames;
/* eslint-disable no-unused-vars */
var _this$props = this.props,
prefix = _this$props.prefix,
className = _this$props.className,
cell = _this$props.cell,
value = _this$props.value,
resizable = _this$props.resizable,
colIndex = _this$props.colIndex,
rowIndex = _this$props.rowIndex,
record = _this$props.record,
context = _this$props.context,
align = _this$props.align,
_this$props$style = _this$props.style,
style = _this$props$style === void 0 ? {} : _this$props$style,
Tag = _this$props.component,
children = _this$props.children,
title = _this$props.title,
width = _this$props.width,
innerStyle = _this$props.innerStyle,
primaryKey = _this$props.primaryKey,
__normalized = _this$props.__normalized,
filterMode = _this$props.filterMode,
filterMenuProps = _this$props.filterMenuProps,
filters = _this$props.filters,
sortable = _this$props.sortable,
lock = _this$props.lock,
pure = _this$props.pure,
locale = _this$props.locale,
expandedIndexSimulate = _this$props.expandedIndexSimulate,
rtl = _this$props.rtl,
columnId = _this$props.columnId,
table = _this$props.table,
isInHeader = _this$props.isInHeader,
type = _this$props.type,
others = _objectWithoutProperties(_this$props, _excluded);
delete others.columnId;
delete others.table;
delete others.isInHeader;
var tagStyle = _objectSpread({}, style);
var cellProps = {
value: value,
index: rowIndex,
record: record,
context: context
};
var content = cell;
if ( /*#__PURE__*/React.isValidElement(content)) {
content = /*#__PURE__*/React.cloneElement(content, cellProps);
} else if (typeof content === 'function') {
content = content(value, rowIndex, record, context);
}
if (align) {
tagStyle.textAlign = align;
if (rtl) {
tagStyle.textAlign = align === 'left' ? 'right' : align === 'right' ? 'left' : align;
}
}
var cls = classnames((_classnames = {}, _defineProperty(_classnames, "".concat(prefix, "table-cell"), true), _defineProperty(_classnames, className, className), _classnames));
return /*#__PURE__*/React.createElement(Tag, _extends({}, obj.pickAttrs(others), {
className: cls,
style: tagStyle,
role: "gridcell"
}), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefix, "table-cell-wrapper"),
style: innerStyle
}, type === 'body' ? /*#__PURE__*/React.createElement(React.Fragment, null, children, children ? /*#__PURE__*/React.createElement("span", {
style: {
verticalAlign: 'middle'
}
}, content) : content) : /*#__PURE__*/React.createElement(React.Fragment, null, children ? /*#__PURE__*/React.createElement("span", {
style: {
verticalAlign: 'middle'
}
}, content) : content, children), table && table.AutoWidth && table.AutoWidth.renderCalculator(columnId, isInHeader, content, children)));
}
}]);
return Cell;
}(React.Component);
_defineProperty(Cell, "propTypes", {
prefix: PropTypes.string,
pure: PropTypes.bool,
primaryKey: PropTypes.string,
className: PropTypes.string,
record: PropTypes.any,
value: PropTypes.any,
colIndex: PropTypes.number,
rowIndex: PropTypes.number,
title: PropTypes.any,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
context: PropTypes.any,
cell: PropTypes.oneOfType([PropTypes.element, PropTypes.node, PropTypes.func]),
align: PropTypes.oneOf(['left', 'center', 'right']),
component: PropTypes.oneOf(['td', 'th', 'div']),
children: PropTypes.any,
style: PropTypes.object,
innerStyle: PropTypes.object,
filterMode: PropTypes.oneOf(['single', 'multiple']),
filterMenuProps: PropTypes.object,
filters: PropTypes.array,
sortable: PropTypes.bool,
lock: PropTypes.any,
type: PropTypes.oneOf(['header', 'body']),
resizable: PropTypes.bool,
__normalized: PropTypes.bool,
columnId: PropTypes.string,
table: PropTypes.object,
isInHeader: PropTypes.bool
});
_defineProperty(Cell, "defaultProps", {
component: 'td',
type: 'body',
cell: function cell(value) {
return value;
},
prefix: 'next-',
columnId: null,
table: null,
isInHeader: false
});
export { Cell as default };