UNPKG

@txdfe/at

Version:

一个设计体系组件库

167 lines (166 loc) 10.8 kB
"use strict"; 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(e) { return e && e.__esModule ? e : { "default": e }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var Cell = exports["default"] = /*#__PURE__*/function (_React$Component) { function Cell() { _classCallCheck(this, Cell); return _callSuper(this, Cell, arguments); } _inherits(Cell, _React$Component); return _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() { /* 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"])(_defineProperty(_defineProperty({}, "".concat(prefix, "table-cell"), true), className, className)); 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))); } }]); }(_react["default"].Component); _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 });