UNPKG

@txdfe/at

Version:

一个设计体系组件库

211 lines (168 loc) 11.9 kB
"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 _util = require("../../util"); 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 _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 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; } 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 = _util.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["default"].isValidElement(content)) { content = /*#__PURE__*/_react["default"].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 = (0, _classnames2["default"])((_classnames = {}, _defineProperty(_classnames, "".concat(prefix, "table-cell"), true), _defineProperty(_classnames, className, className), _classnames)); return /*#__PURE__*/_react["default"].createElement(Tag, _extends({}, _util.obj.pickAttrs(others), { className: cls, style: tagStyle, role: "gridcell" }), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(prefix, "table-cell-wrapper"), style: innerStyle }, type === 'body' ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children, children ? /*#__PURE__*/_react["default"].createElement("span", { style: { verticalAlign: 'middle' } }, content) : content) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children ? /*#__PURE__*/_react["default"].createElement("span", { style: { verticalAlign: 'middle' } }, content) : content, children), table && table.AutoWidth && table.AutoWidth.renderCalculator(columnId, isInHeader, content, children))); } }]); return Cell; }(_react["default"].Component); exports["default"] = Cell; _defineProperty(Cell, "propTypes", { prefix: _propTypes["default"].string, pure: _propTypes["default"].bool, primaryKey: _propTypes["default"].string, className: _propTypes["default"].string, record: _propTypes["default"].any, value: _propTypes["default"].any, colIndex: _propTypes["default"].number, rowIndex: _propTypes["default"].number, title: _propTypes["default"].any, width: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string]), context: _propTypes["default"].any, cell: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].node, _propTypes["default"].func]), align: _propTypes["default"].oneOf(['left', 'center', 'right']), component: _propTypes["default"].oneOf(['td', 'th', 'div']), children: _propTypes["default"].any, style: _propTypes["default"].object, innerStyle: _propTypes["default"].object, filterMode: _propTypes["default"].oneOf(['single', 'multiple']), filterMenuProps: _propTypes["default"].object, filters: _propTypes["default"].array, sortable: _propTypes["default"].bool, lock: _propTypes["default"].any, type: _propTypes["default"].oneOf(['header', 'body']), resizable: _propTypes["default"].bool, __normalized: _propTypes["default"].bool, columnId: _propTypes["default"].string, table: _propTypes["default"].object, isInHeader: _propTypes["default"].bool }); _defineProperty(Cell, "defaultProps", { component: 'td', type: 'body', cell: function cell(value) { return value; }, prefix: 'next-', columnId: null, table: null, isInHeader: false });