UNPKG

react-bootstrap-table-next

Version:
134 lines (99 loc) 6.63 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _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; }; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _cellEventDelegater = require('./cell-event-delegater'); var _cellEventDelegater2 = _interopRequireDefault(_cellEventDelegater); var _utils = require('./utils'); var _utils2 = _interopRequireDefault(_utils); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint react/prop-types: 0 */ var Cell = function (_eventDelegater) { _inherits(Cell, _eventDelegater); function Cell(props) { _classCallCheck(this, Cell); var _this = _possibleConstructorReturn(this, (Cell.__proto__ || Object.getPrototypeOf(Cell)).call(this, props)); _this.createHandleEditingCell = function (originFunc) { return function (e) { var _this$props = _this.props, onStart = _this$props.onStart, rowIndex = _this$props.rowIndex, columnIndex = _this$props.columnIndex, clickToEdit = _this$props.clickToEdit, dbclickToEdit = _this$props.dbclickToEdit; if ((clickToEdit || dbclickToEdit) && _utils2.default.isFunction(originFunc)) { originFunc(e); } if (onStart) { onStart(rowIndex, columnIndex); } }; }; _this.createHandleEditingCell = _this.createHandleEditingCell.bind(_this); return _this; } _createClass(Cell, [{ key: 'shouldComponentUpdate', value: function shouldComponentUpdate(nextProps) { var shouldUpdate = false; if (nextProps.column.isDummyField) { shouldUpdate = !_utils2.default.isEqual(this.props.row, nextProps.row); } else { shouldUpdate = _utils2.default.get(this.props.row, this.props.column.dataField) !== _utils2.default.get(nextProps.row, nextProps.column.dataField); } if (shouldUpdate) return true; // if (nextProps.formatter) shouldUpdate = (nextProps.column.formatter ? !_utils2.default.isEqual(this.props.row, nextProps.row) : false) || this.props.column.hidden !== nextProps.column.hidden || this.props.column.isDummyField !== nextProps.column.isDummyField || this.props.rowIndex !== nextProps.rowIndex || this.props.columnIndex !== nextProps.columnIndex || this.props.className !== nextProps.className || this.props.title !== nextProps.title || this.props.editable !== nextProps.editable || this.props.clickToEdit !== nextProps.clickToEdit || this.props.dbclickToEdit !== nextProps.dbclickToEdit || !_utils2.default.isEqual(this.props.style, nextProps.style) || !_utils2.default.isEqual(this.props.column.formatExtraData, nextProps.column.formatExtraData) || !_utils2.default.isEqual(this.props.column.events, nextProps.column.events) || !_utils2.default.isEqual(this.props.column.attrs, nextProps.column.attrs) || this.props.tabIndex !== nextProps.tabIndex; return shouldUpdate; } }, { key: 'render', value: function render() { var _props = this.props, row = _props.row, rowIndex = _props.rowIndex, column = _props.column, columnIndex = _props.columnIndex, onStart = _props.onStart, editable = _props.editable, clickToEdit = _props.clickToEdit, dbclickToEdit = _props.dbclickToEdit, rest = _objectWithoutProperties(_props, ['row', 'rowIndex', 'column', 'columnIndex', 'onStart', 'editable', 'clickToEdit', 'dbclickToEdit']); var dataField = column.dataField, formatter = column.formatter, formatExtraData = column.formatExtraData; var attrs = this.delegate(_extends({}, rest)); var content = column.isDummyField ? null : _utils2.default.get(row, dataField); if (formatter) { content = column.formatter(content, row, rowIndex, formatExtraData); } if (clickToEdit && editable) { attrs.onClick = this.createHandleEditingCell(attrs.onClick); } else if (dbclickToEdit && editable) { attrs.onDoubleClick = this.createHandleEditingCell(attrs.onDoubleClick); } return _react2.default.createElement( 'td', attrs, typeof content === 'boolean' ? '' + content : content ); } }]); return Cell; }((0, _cellEventDelegater2.default)(_react.Component)); Cell.propTypes = { row: _propTypes2.default.object.isRequired, rowIndex: _propTypes2.default.number.isRequired, column: _propTypes2.default.object.isRequired, columnIndex: _propTypes2.default.number.isRequired }; exports.default = Cell;