react-bootstrap-table2-editor
Version:
it's the editor addon for react-bootstrap-table2
1,395 lines (1,120 loc) • 142 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["ReactBootstrapTable2Editor"] = factory(require("react"));
else
root["ReactBootstrapTable2Editor"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_0__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
if (false) {
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
var isValidElement = function(object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
};
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = require('./factoryWithTypeCheckers')(isValidElement, throwOnDirectAccess);
} else {
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = __webpack_require__(6)();
}
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
Copyright (c) 2016 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/* global define */
(function () {
'use strict';
var hasOwn = {}.hasOwnProperty;
function classNames () {
var classes = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (!arg) continue;
var argType = typeof arg;
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg)) {
classes.push(classNames.apply(null, arg));
} else if (argType === 'object') {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
return classes.join(' ');
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = classNames;
} else if (true) {
// register as 'classnames', consistent with npm package name
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {
return classNames;
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
} else {
window.classNames = classNames;
}
}());
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var TIME_TO_CLOSE_MESSAGE = exports.TIME_TO_CLOSE_MESSAGE = 3000;
var DELAY_FOR_DBCLICK = exports.DELAY_FOR_DBCLICK = 200;
var CLICK_TO_CELL_EDIT = exports.CLICK_TO_CELL_EDIT = 'click';
var DBCLICK_TO_CELL_EDIT = exports.DBCLICK_TO_CELL_EDIT = 'dbclick';
var EDITTYPE = exports.EDITTYPE = {
TEXT: 'text',
SELECT: 'select',
TEXTAREA: 'textarea',
CHECKBOX: 'checkbox',
DATE: 'date'
};
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Consumer = undefined;
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 = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(1);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _const = __webpack_require__(3);
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 disable-next-line: 0 */
/* eslint react/prop-types: 0 */
/* eslint react/require-default-props: 0 */
/* eslint camelcase: 0 */
/* eslint react/no-unused-prop-types: 0 */
var CellEditContext = _react2.default.createContext();
exports.default = function (_, dataOperator, isRemoteCellEdit, handleCellChange) {
var CellEditProvider = function (_React$Component) {
_inherits(CellEditProvider, _React$Component);
function CellEditProvider(props) {
_classCallCheck(this, CellEditProvider);
var _this = _possibleConstructorReturn(this, (CellEditProvider.__proto__ || Object.getPrototypeOf(CellEditProvider)).call(this, props));
_this.doUpdate = _this.doUpdate.bind(_this);
_this.startEditing = _this.startEditing.bind(_this);
_this.escapeEditing = _this.escapeEditing.bind(_this);
_this.completeEditing = _this.completeEditing.bind(_this);
_this.handleCellUpdate = _this.handleCellUpdate.bind(_this);
_this.state = {
ridx: null,
cidx: null,
message: null
};
return _this;
}
_createClass(CellEditProvider, [{
key: 'UNSAFE_componentWillReceiveProps',
value: function UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.cellEdit && isRemoteCellEdit()) {
if (nextProps.cellEdit.options.errorMessage) {
this.setState(function () {
return {
message: nextProps.cellEdit.options.errorMessage
};
});
} else {
this.escapeEditing();
}
}
}
}, {
key: 'handleCellUpdate',
value: function handleCellUpdate(row, column, newValue) {
var _this2 = this;
var newValueWithType = dataOperator.typeConvert(column.type, newValue);
var cellEdit = this.props.cellEdit;
var beforeSaveCell = cellEdit.options.beforeSaveCell;
var oldValue = _.get(row, column.dataField);
var beforeSaveCellDone = function beforeSaveCellDone() {
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (result) {
_this2.doUpdate(row, column, newValueWithType);
} else {
_this2.escapeEditing();
}
};
if (_.isFunction(beforeSaveCell)) {
var result = beforeSaveCell(oldValue, newValueWithType, row, column, beforeSaveCellDone);
if (_.isObject(result) && result.async) {
return;
}
}
this.doUpdate(row, column, newValueWithType);
}
}, {
key: 'doUpdate',
value: function doUpdate(row, column, newValue) {
var _props = this.props,
keyField = _props.keyField,
cellEdit = _props.cellEdit,
data = _props.data;
var afterSaveCell = cellEdit.options.afterSaveCell;
var rowId = _.get(row, keyField);
var oldValue = _.get(row, column.dataField);
if (isRemoteCellEdit()) {
handleCellChange(rowId, column.dataField, newValue);
} else {
dataOperator.editCell(data, keyField, rowId, column.dataField, newValue);
if (_.isFunction(afterSaveCell)) afterSaveCell(oldValue, newValue, row, column);
this.completeEditing();
}
}
}, {
key: 'completeEditing',
value: function completeEditing() {
this.setState(function () {
return {
ridx: null,
cidx: null,
message: null
};
});
}
}, {
key: 'startEditing',
value: function startEditing(ridx, cidx) {
var _this3 = this;
var editing = function editing() {
_this3.setState(function () {
return {
ridx: ridx,
cidx: cidx
};
});
};
var selectRow = this.props.selectRow;
if (!selectRow || selectRow.clickToEdit || !selectRow.clickToSelect) editing();
}
}, {
key: 'escapeEditing',
value: function escapeEditing() {
this.setState(function () {
return {
ridx: null,
cidx: null
};
});
}
}, {
key: 'render',
value: function render() {
var _props$cellEdit = this.props.cellEdit,
_props$cellEdit$optio = _props$cellEdit.options,
nonEditableRows = _props$cellEdit$optio.nonEditableRows,
errorMessage = _props$cellEdit$optio.errorMessage,
optionsRest = _objectWithoutProperties(_props$cellEdit$optio, ['nonEditableRows', 'errorMessage']),
cellEditRest = _objectWithoutProperties(_props$cellEdit, ['options']);
var newCellEdit = _extends({}, optionsRest, cellEditRest, this.state, {
nonEditableRows: _.isDefined(nonEditableRows) ? nonEditableRows() : [],
onStart: this.startEditing,
onEscape: this.escapeEditing,
onUpdate: this.handleCellUpdate
});
return _react2.default.createElement(
CellEditContext.Provider,
{
value: _extends({}, newCellEdit)
},
this.props.children
);
}
}]);
return CellEditProvider;
}(_react2.default.Component);
CellEditProvider.propTypes = {
data: _propTypes2.default.array.isRequired,
selectRow: _propTypes2.default.object,
options: _propTypes2.default.shape({
mode: _propTypes2.default.oneOf([_const.CLICK_TO_CELL_EDIT, _const.DBCLICK_TO_CELL_EDIT]).isRequired,
onErrorMessageDisappear: _propTypes2.default.func,
blurToSave: _propTypes2.default.bool,
beforeSaveCell: _propTypes2.default.func,
afterSaveCell: _propTypes2.default.func,
onStartEdit: _propTypes2.default.func,
nonEditableRows: _propTypes2.default.func,
timeToCloseMessage: _propTypes2.default.number,
errorMessage: _propTypes2.default.any
})
};
return {
Provider: CellEditProvider
};
};
var Consumer = exports.Consumer = CellEditContext.Consumer;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Type = undefined;
var _context = __webpack_require__(4);
var _context2 = _interopRequireDefault(_context);
var _rowConsumer = __webpack_require__(10);
var _rowConsumer2 = _interopRequireDefault(_rowConsumer);
var _editingCellConsumer = __webpack_require__(11);
var _editingCellConsumer2 = _interopRequireDefault(_editingCellConsumer);
var _const = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return {
createContext: _context2.default,
createEditingCell: _editingCellConsumer2.default,
withRowLevelCellEdit: _rowConsumer2.default,
DBCLICK_TO_CELL_EDIT: _const.DBCLICK_TO_CELL_EDIT,
DELAY_FOR_DBCLICK: _const.DELAY_FOR_DBCLICK,
options: options
};
};
var Type = exports.Type = _const.EDITTYPE;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var emptyFunction = __webpack_require__(7);
var invariant = __webpack_require__(8);
var ReactPropTypesSecret = __webpack_require__(9);
module.exports = function() {
function shim(props, propName, componentName, location, propFullName, secret) {
if (secret === ReactPropTypesSecret) {
// It is still safe when called from React.
return;
}
invariant(
false,
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use PropTypes.checkPropTypes() to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
};
shim.isRequired = shim;
function getShim() {
return shim;
};
// Important!
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
var ReactPropTypes = {
array: shim,
bool: shim,
func: shim,
number: shim,
object: shim,
string: shim,
symbol: shim,
any: shim,
arrayOf: getShim,
element: shim,
instanceOf: getShim,
node: shim,
objectOf: getShim,
oneOf: getShim,
oneOfType: getShim,
shape: getShim
};
ReactPropTypes.checkPropTypes = emptyFunction;
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (false) {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"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; }; /* eslint react/prop-types: 0 */
var _react = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _const = __webpack_require__(3);
var _context = __webpack_require__(4);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (Component, selectRowEnabled) {
var renderWithCellEdit = function renderWithCellEdit(props, cellEdit) {
var key = props.value;
var editableRow = !(cellEdit.nonEditableRows.length > 0 && cellEdit.nonEditableRows.indexOf(key) > -1);
var attrs = {};
if (selectRowEnabled && cellEdit.mode === _const.DBCLICK_TO_CELL_EDIT) {
attrs.DELAY_FOR_DBCLICK = _const.DELAY_FOR_DBCLICK;
}
return _react2.default.createElement(Component, _extends({}, props, attrs, {
editingRowIdx: cellEdit.ridx,
editingColIdx: cellEdit.cidx,
editable: editableRow,
onStart: cellEdit.onStart,
clickToEdit: cellEdit.mode === _const.CLICK_TO_CELL_EDIT,
dbclickToEdit: cellEdit.mode === _const.DBCLICK_TO_CELL_EDIT
}));
};
function withConsumer(props) {
return _react2.default.createElement(
_context.Consumer,
null,
function (cellEdit) {
return renderWithCellEdit(props, cellEdit);
}
);
}
withConsumer.displayName = 'WithCellEditingRowConsumer';
return withConsumer;
};
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
"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; }; /* eslint react/prop-types: 0 */
var _react = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _context = __webpack_require__(4);
var _editingCell = __webpack_require__(12);
var _editingCell2 = _interopRequireDefault(_editingCell);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (_, onStartEdit) {
var EditingCell = (0, _editingCell2.default)(_, onStartEdit);
var renderWithEditingCell = function renderWithEditingCell(props, cellEdit) {
var content = _.get(props.row, props.column.dataField);
var editCellstyle = props.column.editCellStyle || {};
var editCellclasses = props.column.editCellClasses;
if (_.isFunction(props.column.editCellStyle)) {
editCellstyle = props.column.editCellStyle(content, props.row, props.rowIndex, props.columnIndex);
}
if (_.isFunction(props.column.editCellClasses)) {
editCellclasses = props.column.editCellClasses(content, props.row, props.rowIndex, props.columnIndex);
}
return _react2.default.createElement(EditingCell, _extends({}, props, {
className: editCellclasses,
style: editCellstyle
}, cellEdit));
};
return function (props) {
return _react2.default.createElement(
_context.Consumer,
null,
function (cellEdit) {
return renderWithEditingCell(props, cellEdit);
}
);
};
};
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"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 = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _classnames = __webpack_require__(2);
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = __webpack_require__(1);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _dropdownEditor = __webpack_require__(13);
var _dropdownEditor2 = _interopRequireDefault(_dropdownEditor);
var _textareaEditor = __webpack_require__(14);
var _textareaEditor2 = _interopRequireDefault(_textareaEditor);
var _checkboxEditor = __webpack_require__(15);
var _checkboxEditor2 = _interopRequireDefault(_checkboxEditor);
var _dateEditor = __webpack_require__(16);
var _dateEditor2 = _interopRequireDefault(_dateEditor);
var _textEditor = __webpack_require__(17);
var _textEditor2 = _interopRequireDefault(_textEditor);
var _editorIndicator = __webpack_require__(18);
var _editorIndicator2 = _interopRequireDefault(_editorIndicator);
var _const = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 */
/* eslint no-return-assign: 0 */
/* eslint class-methods-use-this: 0 */
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
/* eslint camelcase: 0 */
exports.default = function (_, onStartEdit) {
var _class, _temp;
return _temp = _class = function (_Component) {
_inherits(EditingCell, _Component);
function EditingCell(props) {
_classCallCheck(this, EditingCell);
var _this = _possibleConstructorReturn(this, (EditingCell.__proto__ || Object.getPrototypeOf(EditingCell)).call(this, props));
_this.indicatorTimer = null;
_this.clearTimer = _this.clearTimer.bind(_this);
_this.handleBlur = _this.handleBlur.bind(_this);
_this.handleClick = _this.handleClick.bind(_this);
_this.handleKeyDown = _this.handleKeyDown.bind(_this);
_this.beforeComplete = _this.beforeComplete.bind(_this);
_this.asyncbeforeCompete = _this.asyncbeforeCompete.bind(_this);
_this.displayErrorMessage = _this.displayErrorMessage.bind(_this);
_this.state = {
invalidMessage: null
};
return _this;
}
_createClass(EditingCell, [{
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.clearTimer();
}
}, {
key: 'UNSAFE_componentWillReceiveProps',
value: function UNSAFE_componentWillReceiveProps(_ref) {
var message = _ref.message;
if (_.isDefined(message)) {
this.createTimer();
this.setState(function () {
return {
invalidMessage: message
};
});
}
}
}, {
key: 'clearTimer',
value: function clearTimer() {
if (this.indicatorTimer) {
clearTimeout(this.indicatorTimer);
}
}
}, {
key: 'createTimer',
value: function createTimer() {
var _this2 = this;
this.clearTimer();
var _props = this.props,
timeToCloseMessage = _props.timeToCloseMessage,
onErrorMessageDisappear = _props.onErrorMessageDisappear;
this.indicatorTimer = _.sleep(function () {
_this2.setState(function () {
return {
invalidMessage: null
};
});
if (_.isFunction(onErrorMessageDisappear)) onErrorMessageDisappear();
}, timeToCloseMessage);
}
}, {
key: 'displayErrorMessage',
value: function displayErrorMessage(message) {
this.setState(function () {
return {
invalidMessage: message
};
});
this.createTimer();
}
}, {
key: 'asyncbeforeCompete',
value: function asyncbeforeCompete(newValue) {
var _this3 = this;
return function () {
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { valid: true };
var valid = result.valid,
message = result.message;
var _props2 = _this3.props,
onUpdate = _props2.onUpdate,
row = _props2.row,
column = _props2.column;
if (!valid) {
_this3.displayErrorMessage(message);
return;
}
onUpdate(row, column, newValue);
};
}
}, {
key: 'beforeComplete',
value: function beforeComplete(newValue) {
var _props3 = this.props,
onUpdate = _props3.onUpdate,
row = _props3.row,
column = _props3.column;
if (_.isFunction(column.validator)) {
var validateForm = column.validator(newValue, row, column, this.asyncbeforeCompete(newValue));
if (_.isObject(validateForm)) {
if (validateForm.async) {
return;
} else if (!validateForm.valid) {
this.displayErrorMessage(validateForm.message);
return;
}
}
}
onUpdate(row, column, newValue);
}
}, {
key: 'handleBlur',
value: function handleBlur() {
var _props4 = this.props,
onEscape = _props4.onEscape,
blurToSave = _props4.blurToSave;
if (blurToSave) {
this.beforeComplete(this.editor.getValue());
} else {
onEscape();
}
}
}, {
key: 'handleKeyDown',
value: function handleKeyDown(e) {
var onEscape = this.props.onEscape;
if (e.keyCode === 27) {
// ESC
onEscape();
} else if (e.keyCode === 13) {
// ENTER
this.beforeComplete(this.editor.getValue());
}
}
}, {
key: 'handleClick',
value: function handleClick(e) {
if (e.target.tagName !== 'TD') {
// To avoid the row selection event be triggered,
// When user define selectRow.clickToSelect and selectRow.clickToEdit
// We shouldn't trigger selection event even if user click on the cell editor(input)
e.stopPropagation();
}
}
}, {
key: 'render',
value: function render() {
var _this4 = this;
var editor = void 0;
var _props5 = this.props,
row = _props5.row,
column = _props5.column,
className = _props5.className,
style = _props5.style,
rowIndex = _props5.rowIndex,
columnIndex = _props5.columnIndex,
autoSelectText = _props5.autoSelectText;
var dataField = column.dataField;
var value = _.get(row, dataField);
var hasError = _.isDefined(this.state.invalidMessage);
var customEditorClass = column.editorClasses || '';
if (_.isFunction(column.editorClasses)) {
customEditorClass = column.editorClasses(value, row, rowIndex, columnIndex);
}
var editorStyle = column.editorStyle || {};
if (_.isFunction(column.editorStyle)) {
editorStyle = column.editorStyle(value, row, rowIndex, columnIndex);
}
var editorClass = (0, _classnames2.default)({
animated: hasError,
shake: hasError
}, customEditorClass);
var editorProps = {
ref: function ref(node) {
return _this4.editor = node;
},
defaultValue: value,
style: editorStyle,
className: editorClass,
onKeyDown: this.handleKeyDown,
onBlur: this.handleBlur
};
if (onStartEdit) {
editorProps.didMount = function () {
return onStartEdit(row, column, rowIndex, columnIndex);
};
}
var isDefaultEditorDefined = _.isObject(column.editor);
if (isDefaultEditorDefined) {
editorProps = _extends({}, editorProps, column.editor);
} else if (_.isFunction(column.editorRenderer)) {
editorProps = _extends({}, editorProps, {
onUpdate: this.beforeComplete
});
}
if (_.isFunction(column.editorRenderer)) {
editor = column.editorRenderer(editorProps, value, row, column, rowIndex, columnIndex);
} else if (isDefaultEditorDefined && column.editor.type === _const.EDITTYPE.SELECT) {
editor = _react2.default.createElement(_dropdownEditor2.default, _extends({}, editorProps, { row: row, column: column }));
} else if (isDefaultEditorDefined && column.editor.type === _const.EDITTYPE.TEXTAREA) {
editor = _react2.default.createElement(_textareaEditor2.default, _extends({}, editorProps, { autoSelectText: autoSelectText }));
} else if (isDefaultEditorDefined && column.editor.type === _const.EDITTYPE.CHECKBOX) {
editor = _react2.default.createElement(_checkboxEditor2.default, editorProps);
} else if (isDefaultEditorDefined && column.editor.type === _const.EDITTYPE.DATE) {
editor = _react2.default.createElement(_dateEditor2.default, editorProps);
} else {
editor = _react2.default.createElement(_textEditor2.default, _extends({}, editorProps, { autoSelectText: autoSelectText }));
}
return _react2.default.createElement(
'td',
{
className: (0, _classnames2.default)('react-bootstrap-table-editing-cell', className),
style: style,
onClick: this.handleClick
},
editor,
hasError ? _react2.default.createElement(_editorIndicator2.default, { invalidMessage: this.state.invalidMessage }) : null
);
}
}]);
return EditingCell;
}(_react.Component), _class.propTypes = {
row: _propTypes2.default.object.isRequired,
rowIndex: _propTypes2.default.number.isRequired,
column: _propTypes2.default.object.isRequired,
columnIndex: _propTypes2.default.number.isRequired,
onUpdate: _propTypes2.default.func.isRequired,
onEscape: _propTypes2.default.func.isRequired,
timeToCloseMessage: _propTypes2.default.number,
autoSelectText: _propTypes2.default.bool,
className: _propTypes2.default.string,
style: _propTypes2.default.object
}, _class.defaultProps = {
timeToCloseMessage: _const.TIME_TO_CLOSE_MESSAGE,
className: null,
autoSelectText: false,
style: {}
}, _temp;
};
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"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 = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _classnames = __webpack_require__(2);
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = __webpack_require__(1);
var _propTypes2 = _interopRequireDefault(_propTypes);
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 no-return-assign: 0 */
var DropDownEditor = function (_Component) {
_inherits(DropDownEditor, _Component);
function DropDownEditor(props) {
_classCallCheck(this, DropDownEditor);
var _this = _possibleConstructorReturn(this, (DropDownEditor.__proto__ || Object.getPrototypeOf(DropDownEditor)).call(this, props));
var options = props.options;
if (props.getOptions) {
options = props.getOptions(_this.setOptions.bind(_this), {
row: props.row,
column: props.column
}) || [];
}
_this.state = { options: options };
return _this;
}
_createClass(DropDownEditor, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _props = this.props,
defaultValue = _props.defaultValue,
didMount = _props.didMount;
this.select.value = defaultValue;
this.select.focus();
if (didMount) didMount();
}
}, {
key: 'setOptions',
value: function setOptions(options) {
this.setState({ options: options });
}
}, {
key: 'getValue',
value: function getValue() {
return this.select.value;
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var _props2 = this.props,
defaultValue = _props2.defaultValue,
didMount = _props2.didMount,
getOptions = _props2.getOptions,
className = _props2.className,
rest = _objectWithoutProperties(_props2, ['defaultValue', 'didMount', 'getOptions', 'className']);
var editorClass = (0, _classnames2.default)('form-control editor edit-select', className);
var attr = _extends({}, rest, {
className: editorClass
});
return _react2.default.createElement(
'select',
_extends({}, attr, {
ref: function ref(node) {
return _this2.select = node;
},
defaultValue: defaultValue
}),
this.state.options.map(function (_ref) {
var label = _ref.label,
value = _ref.value;
return _react2.default.createElement(
'option',
{ key: value, value: value },
label
);
})
);
}
}]);
return DropDownEditor;
}(_react.Component);
DropDownEditor.propTypes = {
row: _propTypes2.default.object.isRequired,
column: _propTypes2.default.object.isRequired,
defaultValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]),
className: _propTypes2.default.string,
style: _propTypes2.default.object,
options: _propTypes2.default.oneOfType([_propTypes2.default.arrayOf(_propTypes2.default.shape({
label: _propTypes2.default.string,
value: _propTypes2.default.any
}))]),
didMount: _propTypes2.default.func,
getOptions: _propTypes2.default.func
};
DropDownEditor.defaultProps = {
className: '',
defaultValue: '',
style: {},
options: [],
didMount: undefined,
getOptions: undefined
};
exports.default = DropDownEditor;
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
"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 = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _classnames = __webpack_require__(2);
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = __webpack_require__(1);
var _propTypes2 = _interopRequireDefault(_propTypes);
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 no-return-assign: 0 */
var TextAreaEditor = function (_Component) {
_inherits(TextAreaEditor, _Component);
function TextAreaEditor(props) {
_classCallCheck(this, TextAreaEditor);
var _this = _possibleConstructorReturn(this, (TextAreaEditor.__proto__ || Object.getPrototypeOf(TextAreaEditor)).call(this, props));
_this.handleKeyDown = _this.handleKeyDown.bind(_this);
return _this;
}
_createClass(TextAreaEditor, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _props = this.props,
defaultValue = _props.defaultValue,
didMount = _props.didMount,
autoSelectText = _props.autoSelectText;
this.text.value = defaultValue;
this.text.focus();
if (autoSelectText) this.text.select();
if (didMount) didMount();
}
}, {
key: 'getValue',
value: function getValue() {
return this.text.value;
}
}, {
key: 'handleKeyDown',
value: function handleKeyDown(e) {
if (e.keyCode === 13 && !e.shiftKey) return;
if (this.props.onKeyDown) {
this.props.onKeyDown(e);
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var _props2 = this.props,
defaultValue = _props2.defaultValue,
didMount = _props2.didMount,
className = _props2.className,
autoSelectText = _props2.autoSelectText,
rest = _objectWithoutProperties(_props2, ['defaultValue', 'didMount', 'className', 'autoSelectText']);
var editorClass = (0, _classnames2.default)('form-control editor edit-textarea', className);
return _react2.default.createElement('textarea', _extends({
ref: function ref(node) {
return _this2.text = node;
},
type: 'textarea',
className: editorClass
}, rest, {
onKeyDown: this.handleKeyDown
}));
}
}]);
return TextAreaEditor;
}(_react.Component);
TextAreaEditor.propTypes = {
className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]),
defaultValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]),
onKeyDown: _propTypes2.default.func,
autoSelectText: _propTypes2.default.bool,
didMount: _propTypes2.default.func
};
TextAreaEditor.defaultProps = {
className: '',
defaultValue: '',
autoSelectText: false,
onKeyDown: undefined,
didMount: undefined
};
exports.default = TextAreaEditor;
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
"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 _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
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 = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _classnames = __webpack_require__(2);
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = __webpack_require__(1);
var _propTypes2 = _interopRequireDefault(_propTypes);
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 no-return-assign: 0 */
var CheckBoxEditor = function (_Component) {
_inherits(CheckBo