Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -202,11 +202,19 @@ var BootstrapTable = function (_Component) {
_this._adjustHeaderWidth = _this._adjustHeaderWidth.bind(_this);
_this._adjustHeight = _this._adjustHeight.bind(_this);
_this._adjustTable = _this._adjustTable.bind(_this);
_this.toggleExpandAllChilds = _this.toggleExpandAllChilds.bind(_this);
var expandedKeys = [];
if (_this.props.options.expandAllChilds !== null && _this.props.options.expandAllChilds !== undefined && _this.props.options.expandAllChilds) {
expandedKeys = _this.store.getAllRowkey();
} else if (_this.props.options.expanding !== undefined && _this.props.options.expanding !== null) {
expandedKeys = _this.props.options.expanding;
}
_this.state = {
data: _this.getTableData(),
currPage: currPage,
expanding: _this.props.options.expanding || [],
expanding: expandedKeys,
sizePerPage: _this.props.options.sizePerPage || _Const2.default.SIZE_PER_PAGE_LIST[0],
selectedRowKeys: _this.store.getSelectedRowKeys(),
reset: false,
@@ -524,7 +532,7 @@ var BootstrapTable = function (_Component) {
var pageStartIndex = this.props.options.pageStartIndex;
this.store.clean();
this.refs.body.setState({ currEditCell: null });
this.body.setState({ currEditCell: null });
this.setState(function () {
return {
data: _this4.getTableData(),
@@ -577,8 +585,16 @@ var BootstrapTable = function (_Component) {
} else {
if (!this.allowRemote(_Const2.default.REMOTE_SORT)) {
data = this.store.sort().get();
newState.data = data;
} else {
var currentOptions = this.props.options;
var sortName = options.sortName;
var sortOrder = options.sortOrder;
if (currentOptions.sortName !== sortName || currentOptions.sortOrder !== sortOrder) {
this.store.setSortInfo(sortOrder, options.sortName);
}
}
newState.data = data;
}
this.setState(function () {
return newState;
@@ -591,9 +607,9 @@ var BootstrapTable = function (_Component) {
}
var sortList = this.store.getSortInfo();
var sortField = options.sortName;
var sortOrder = options.sortOrder;
if (sortField && sortOrder) {
this.store.setSortInfo(sortOrder, sortField);
var _sortOrder = options.sortOrder;
if (sortField && _sortOrder) {
this.store.setSortInfo(_sortOrder, sortField);
this.store.sort();
} else if (sortList.length > 0) {
this.store.sort();
@@ -647,9 +663,9 @@ var BootstrapTable = function (_Component) {
value: function componentDidMount() {
this._adjustTable();
window.addEventListener('resize', this._adjustTable);
this.refs.body.refs.container.addEventListener('scroll', this._scrollHeader);
this.body.container.addEventListener('scroll', this._scrollHeader);
if (this.props.footer) {
this.refs.body.refs.container.addEventListener('scroll', this._scrollFooter);
this.body.container.addEventListener('scroll', this._scrollFooter);
}
if (this.props.scrollTop) {
this._scrollTop();
@@ -659,10 +675,10 @@ var BootstrapTable = function (_Component) {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
window.removeEventListener('resize', this._adjustTable);
if (this.refs && this.refs.body && this.refs.body.refs) {
this.refs.body.refs.container.removeEventListener('scroll', this._scrollHeader);
if (this.body && this.body.container) {
this.body.container.removeEventListener('scroll', this._scrollHeader);
if (this.props.footer) {
this.refs.body.refs.container.removeEventListener('scroll', this._scrollFooter);
this.body.container.removeEventListener('scroll', this._scrollFooter);
}
}
if (this.filter) {
@@ -720,6 +736,8 @@ var BootstrapTable = function (_Component) {
}, {
key: 'render',
value: function render() {
var _this5 = this;
var style = {
height: this.props.height,
maxHeight: this.props.maxHeight
@@ -755,6 +773,8 @@ var BootstrapTable = function (_Component) {
var showToolbarOnTop = toolbarPosition !== _Const2.default.TOOLBAR_POS_BOTTOM;
var showToolbarOnBottom = toolbarPosition !== _Const2.default.TOOLBAR_POS_TOP;
var _props$options$hideRo = this.props.options.hideRowOnExpand,
hideRowOnExpand = _props$options$hideRo === undefined ? false : _props$options$hideRo;
return _react2.default.createElement(
'div',
@@ -764,7 +784,9 @@ var BootstrapTable = function (_Component) {
showPaginationOnTop ? pagination : null,
_react2.default.createElement(
'div',
{ ref: 'table',
{ ref: function ref(node) {
return _this5.table = node;
},
className: (0, _classnames2.default)('react-bs-table', { 'react-bs-table-bordered': this.props.bordered }, this.props.tableContainerClass),
style: _extends({}, style, this.props.tableStyle),
onMouseEnter: this.handleMouseEnter,
@@ -772,7 +794,9 @@ var BootstrapTable = function (_Component) {
_react2.default.createElement(
_TableHeader2.default,
{
ref: 'header',
ref: function ref(node) {
return _this5.header = node;
},
version: this.props.version,
colGroups: colGroups,
headerContainerClass: this.props.headerContainerClass,
@@ -792,10 +816,17 @@ var BootstrapTable = function (_Component) {
reset: this.state.reset,
expandColumnVisible: expandColumnOptions.expandColumnVisible,
expandColumnComponent: expandColumnOptions.expandColumnComponent,
expandedColumnHeaderComponent: expandColumnOptions.expandedColumnHeaderComponent,
noAnyExpand: this.state.expanding.length === 0,
expandAll: this.props.options.expandAll,
toggleExpandAllChilds: this.toggleExpandAllChilds,
expandColumnBeforeSelectColumn: expandColumnOptions.expandColumnBeforeSelectColumn },
this.props.children
),
_react2.default.createElement(_TableBody2.default, { ref: 'body',
_react2.default.createElement(_TableBody2.default, {
ref: function ref(node) {
return _this5.body = node;
},
bodyContainerClass: this.props.bodyContainerClass,
tableBodyClass: this.props.tableBodyClass,
style: _extends({}, style, this.props.bodyStyle),
@@ -835,13 +866,14 @@ var BootstrapTable = function (_Component) {
x: this.state.x,
y: this.state.y,
withoutTabIndex: this.props.withoutTabIndex,
hideRowOnExpand: hideRowOnExpand,
onEditCell: this.handleEditCell }),
tableFooter
),
tableFilter,
showPaginationOnBottom ? pagination : null,
showToolbarOnBottom ? toolBar : null,
_react2.default.createElement(_reactSAlert2.default, { stack: { limit: 3 } })
this.props.renderAlert ? _react2.default.createElement(_reactSAlert2.default, { stack: { limit: 3 } }) : null
);
}
}, {
@@ -936,20 +968,43 @@ var BootstrapTable = function (_Component) {
}
}, {
key: '__handleExpandRow__REACT_HOT_LOADER__',
value: function __handleExpandRow__REACT_HOT_LOADER__(expanding, rowKey, isRowExpanding) {
var _this5 = this;
value: function __handleExpandRow__REACT_HOT_LOADER__(expanding, rowKey, isRowExpanding, event) {
var _this6 = this;
var onExpand = this.props.options.onExpand;
if (onExpand) {
onExpand(rowKey, !isRowExpanding);
onExpand(rowKey, !isRowExpanding, event);
}
this.setState(function () {
return { expanding: expanding, reset: false };
}, function () {
_this5._adjustHeaderWidth();
_this6._adjustHeaderWidth();
});
}
}, {
key: 'toggleExpandAllChilds',
value: function toggleExpandAllChilds() {
var _this7 = this;
var expanding = this.state.expanding;
if (expanding.length > 0) {
this.setState(function () {
return {
expanding: [],
reset: false
};
});
} else {
this.setState(function () {
return {
expanding: _this7.store.getAllRowkey(),
reset: false
};
});
}
}
}, {
key: '__handlePaginationData__REACT_HOT_LOADER__',
value: function __handlePaginationData__REACT_HOT_LOADER__(page, sizePerPage) {
@@ -1031,7 +1086,7 @@ var BootstrapTable = function (_Component) {
if (y >= visibleRowSize) {
currPage++;
var lastPage = pagination ? this.refs.pagination.getLastPage() : -1;
var lastPage = pagination ? this.pagination.getLastPage() : -1;
if (currPage <= lastPage) {
this.handlePaginationData(currPage, this.state.sizePerPage);
} else {
@@ -1049,7 +1104,7 @@ var BootstrapTable = function (_Component) {
} else if (x >= visibleColumnSize) {
if (y + 1 === visibleRowSize) {
currPage++;
var _lastPage = pagination ? this.refs.pagination.getLastPage() : -1;
var _lastPage = pagination ? this.pagination.getLastPage() : -1;
if (currPage <= _lastPage) {
this.handlePaginationData(currPage, this.state.sizePerPage);
} else {
@@ -1082,13 +1137,13 @@ var BootstrapTable = function (_Component) {
}
}, {
key: '__handleRowClick__REACT_HOT_LOADER__',
value: function __handleRowClick__REACT_HOT_LOADER__(row, rowIndex, columnIndex) {
value: function __handleRowClick__REACT_HOT_LOADER__(row, rowIndex, columnIndex, event) {
var _props3 = this.props,
options = _props3.options,
keyBoardNav = _props3.keyBoardNav;
if (options.onRowClick) {
options.onRowClick(row, columnIndex, rowIndex);
options.onRowClick(row, columnIndex, rowIndex, event);
}
if (keyBoardNav) {
var _ref5 = (typeof keyBoardNav === 'undefined' ? 'undefined' : _typeof(keyBoardNav)) === 'object' ? keyBoardNav : {},
@@ -1108,9 +1163,9 @@ var BootstrapTable = function (_Component) {
}
}, {
key: '__handleRowDoubleClick__REACT_HOT_LOADER__',
value: function __handleRowDoubleClick__REACT_HOT_LOADER__(row) {
value: function __handleRowDoubleClick__REACT_HOT_LOADER__(row, event) {
if (this.props.options.onRowDoubleClick) {
this.props.options.onRowDoubleClick(row);
this.props.options.onRowDoubleClick(row, event);
}
}
}, {
@@ -1242,7 +1297,7 @@ var BootstrapTable = function (_Component) {
}, {
key: '__handleEditCell__REACT_HOT_LOADER__',
value: function __handleEditCell__REACT_HOT_LOADER__(newVal, rowIndex, colIndex) {
var _this6 = this;
var _this8 = this;
var beforeSaveCell = this.props.cellEdit.beforeSaveCell;
@@ -1250,9 +1305,9 @@ var BootstrapTable = function (_Component) {
var fieldName = columns[colIndex].name;
var invalid = function invalid() {
_this6.setState(function () {
_this8.setState(function () {
return {
data: _this6.store.get(),
data: _this8.store.get(),
reset: false
};
});
@@ -1261,14 +1316,15 @@ var BootstrapTable = function (_Component) {
if (beforeSaveCell) {
var beforeSaveCellCB = function beforeSaveCellCB(result) {
_this6.refs.body.cancelEditCell();
_this8.body.cancelEditCell();
if (result || result === undefined) {
_this6.editCell(newVal, rowIndex, colIndex);
_this8.editCell(newVal, rowIndex, colIndex);
} else {
invalid();
}
};
var isValid = beforeSaveCell(this.state.data[rowIndex], fieldName, newVal, beforeSaveCellCB);
var props = { rowIndex: rowIndex, colIndex: colIndex };
var isValid = beforeSaveCell(this.state.data[rowIndex], fieldName, newVal, beforeSaveCellCB, props);
if (isValid === false && typeof isValid !== 'undefined') {
return invalid();
} else if (isValid === _Const2.default.AWAIT_BEFORE_CELL_EDIT) {
@@ -1286,13 +1342,14 @@ var BootstrapTable = function (_Component) {
var columns = this.getColumnsDescription(this.props);
var fieldName = columns[colIndex].name;
var props = { rowIndex: rowIndex, colIndex: colIndex };
if (onCellEdit) {
newVal = onCellEdit(this.state.data[rowIndex], fieldName, newVal);
}
if (this.allowRemote(_Const2.default.REMOTE_CELL_EDIT)) {
if (afterSaveCell) {
afterSaveCell(this.state.data[rowIndex], fieldName, newVal);
afterSaveCell(this.state.data[rowIndex], fieldName, newVal, props);
}
return;
}
@@ -1306,7 +1363,7 @@ var BootstrapTable = function (_Component) {
});
if (afterSaveCell) {
afterSaveCell(this.state.data[rowIndex], fieldName, newVal);
afterSaveCell(this.state.data[rowIndex], fieldName, newVal, props);
}
}
}, {
@@ -1322,7 +1379,7 @@ var BootstrapTable = function (_Component) {
}, {
key: '__handleAddRow__REACT_HOT_LOADER__',
value: function __handleAddRow__REACT_HOT_LOADER__(newObj) {
var _this7 = this;
var _this9 = this;
var isAsync = false;
var onAddRow = this.props.options.onAddRow;
@@ -1330,7 +1387,7 @@ var BootstrapTable = function (_Component) {
var afterHandleAddRow = function afterHandleAddRow(errMsg) {
if (isAsync) {
_this7.refs.toolbar.afterHandleSaveBtnClick(errMsg);
_this9.toolbar.afterHandleSaveBtnClick(errMsg);
} else {
return errMsg;
}
@@ -1338,19 +1395,19 @@ var BootstrapTable = function (_Component) {
var afterAddRowCB = function afterAddRowCB(errMsg) {
if (typeof errMsg !== 'undefined' && errMsg !== '') return afterHandleAddRow(errMsg);
if (_this7.allowRemote(_Const2.default.REMOTE_INSERT_ROW)) {
if (_this7.props.options.afterInsertRow) {
_this7.props.options.afterInsertRow(newObj);
if (_this9.allowRemote(_Const2.default.REMOTE_INSERT_ROW)) {
if (_this9.props.options.afterInsertRow) {
_this9.props.options.afterInsertRow(newObj);
}
return afterHandleAddRow();
}
try {
_this7.store.add(newObj);
_this9.store.add(newObj);
} catch (e) {
return afterHandleAddRow(e.message);
}
_this7._handleAfterAddingRow(newObj, false);
_this9._handleAfterAddingRow(newObj, false);
return afterHandleAddRow();
};
@@ -1404,14 +1461,14 @@ var BootstrapTable = function (_Component) {
}, {
key: '__handleDropRow__REACT_HOT_LOADER__',
value: function __handleDropRow__REACT_HOT_LOADER__(rowKeys) {
var _this8 = this;
var _this10 = this;
var dropRowKeys = rowKeys ? rowKeys : this.store.getSelectedRowKeys();
// add confirm before the delete action if that option is set.
if (dropRowKeys && dropRowKeys.length > 0) {
if (this.props.options.handleConfirmDeleteRow) {
this.props.options.handleConfirmDeleteRow(function () {
_this8.deleteRow(dropRowKeys);
_this10.deleteRow(dropRowKeys);
}, dropRowKeys);
} else if (confirm('Are you sure you want to delete?')) {
this.deleteRow(dropRowKeys);
@@ -1421,7 +1478,7 @@ var BootstrapTable = function (_Component) {
}, {
key: 'deleteRow',
value: function deleteRow(dropRowKeys) {
var _this9 = this;
var _this11 = this;
var dropRow = this.store.getRowByKey(dropRowKeys);
var _props$options2 = this.props.options,
@@ -1458,7 +1515,7 @@ var BootstrapTable = function (_Component) {
this.setState(function () {
return {
data: result,
selectedRowKeys: _this9.store.getSelectedRowKeys(),
selectedRowKeys: _this11.store.getSelectedRowKeys(),
currPage: currPage,
reset: false
};
@@ -1469,7 +1526,7 @@ var BootstrapTable = function (_Component) {
return {
data: result,
reset: false,
selectedRowKeys: _this9.store.getSelectedRowKeys()
selectedRowKeys: _this11.store.getSelectedRowKeys()
};
});
}
@@ -1581,8 +1638,8 @@ var BootstrapTable = function (_Component) {
value: function __handleSearch__REACT_HOT_LOADER__(searchText) {
// Set search field if this function being called outside
// but it's not necessary if calling fron inside.
if (this.refs.toolbar) {
this.refs.toolbar.setSearchInput(searchText);
if (this.toolbar) {
this.toolbar.setSearchInput(searchText);
}
var search = this.props.autoCollapse.search;
var _props$options4 = this.props.options,
@@ -1639,6 +1696,8 @@ var BootstrapTable = function (_Component) {
}, {
key: 'renderPagination',
value: function renderPagination() {
var _this12 = this;
if (this.props.pagination) {
var dataSize = void 0;
if (this.allowRemote(_Const2.default.REMOTE_PAGE)) {
@@ -1654,7 +1713,10 @@ var BootstrapTable = function (_Component) {
'div',
{ className: 'react-bs-table-pagination' },
_react2.default.createElement(_PaginationList2.default, {
ref: 'pagination',
ref: function ref(node) {
return _this12.pagination = node;
},
version: this.props.version,
withFirstAndLast: withFirstAndLast,
alwaysShowAllBtns: options.alwaysShowAllBtns,
currPage: this.state.currPage,
@@ -1687,6 +1749,8 @@ var BootstrapTable = function (_Component) {
}, {
key: 'renderToolBar',
value: function renderToolBar() {
var _this13 = this;
var _props5 = this.props,
exportCSV = _props5.exportCSV,
selectRow = _props5.selectRow,
@@ -1738,7 +1802,9 @@ var BootstrapTable = function (_Component) {
'div',
{ className: 'react-bs-table-tool-bar ' + (print ? '' : 'hidden-print') },
_react2.default.createElement(_ToolBar2.default, {
ref: 'toolbar',
ref: function ref(node) {
return _this13.toolbar = node;
},
version: this.props.version,
defaultSearch: this.props.options.defaultSearch,
clearSearch: this.props.options.clearSearch,
@@ -1797,6 +1863,8 @@ var BootstrapTable = function (_Component) {
}, {
key: 'renderTableFooter',
value: function renderTableFooter(footerData, footerFormatterReturnData, columns, colGroups) {
var _this14 = this;
if (this.props.footer) {
var hideSelectColumn = true;
var mode = this.props.selectRow.mode;
@@ -1808,7 +1876,9 @@ var BootstrapTable = function (_Component) {
return _react2.default.createElement(
_TableFooter2.default,
{
ref: 'footer',
ref: function ref(node) {
return _this14.footer = node;
},
columns: columns,
colGroups: colGroups,
footerFormatterReturnData: footerFormatterReturnData,
@@ -1831,23 +1901,23 @@ var BootstrapTable = function (_Component) {
var scrollTop = this.props.scrollTop;
if (scrollTop === _Const2.default.SCROLL_TOP) {
this.refs.body.refs.container.scrollTop = 0;
this.body.container.scrollTop = 0;
} else if (scrollTop === _Const2.default.SCROLL_BOTTOM) {
this.refs.body.refs.container.scrollTop = this.refs.body.refs.container.scrollHeight;
this.body.container.scrollTop = this.body.container.scrollHeight;
} else if (typeof scrollTop === 'number' && !isNaN(scrollTop)) {
this.refs.body.refs.container.scrollTop = scrollTop;
this.body.container.scrollTop = scrollTop;
}
}
}, {
key: '___scrollHeader__REACT_HOT_LOADER__',
value: function ___scrollHeader__REACT_HOT_LOADER__(e) {
this.refs.header.refs.container.scrollLeft = e.currentTarget.scrollLeft;
this.header.container.scrollLeft = e.currentTarget.scrollLeft;
}
}, {
key: '___scrollFooter__REACT_HOT_LOADER__',
value: function ___scrollFooter__REACT_HOT_LOADER__(e) {
if (this.props.footer) {
this.refs.footer.refs.container.scrollLeft = e.currentTarget.scrollLeft;
this.footer.container.scrollLeft = e.currentTarget.scrollLeft;
}
}
}, {
@@ -1861,9 +1931,9 @@ var BootstrapTable = function (_Component) {
}, {
key: '_adjustHeaderWidth',
value: function _adjustHeaderWidth() {
var header = this.refs.header.getHeaderColGrouop();
var tbody = this.refs.body.refs.tbody;
var bodyHeader = this.refs.body.getHeaderColGrouop();
var header = this.header.getHeaderColGrouop();
var tbody = this.body.tbody;
var bodyHeader = this.body.getHeaderColGrouop();
var firstRow = tbody.childNodes[0];
var isScroll = tbody.parentNode.getBoundingClientRect().height > tbody.parentNode.parentNode.getBoundingClientRect().height;
@@ -1923,12 +1993,12 @@ var BootstrapTable = function (_Component) {
var maxHeight = this.props.maxHeight;
if (typeof height === 'number' && !isNaN(height) || height.indexOf('%') === -1) {
this.refs.body.refs.container.style.height = parseFloat(height, 10) - this.refs.header.refs.container.offsetHeight + 'px';
this.body.container.style.height = parseFloat(height, 10) - this.header.container.offsetHeight + 'px';
}
if (maxHeight) {
maxHeight = typeof maxHeight === 'number' ? maxHeight : parseInt(maxHeight.replace('px', ''), 10);
this.refs.body.refs.container.style.maxHeight = maxHeight - this.refs.header.refs.container.offsetHeight + 'px';
this.body.container.style.maxHeight = maxHeight - this.header.container.offsetHeight + 'px';
}
}
}, {
@@ -2126,11 +2196,14 @@ BootstrapTable.propTypes = {
beforeShowError: _propTypes2.default.func,
printToolBar: _propTypes2.default.bool,
insertFailIndicator: _propTypes2.default.string,
noAutoBOM: _propTypes2.default.bool
noAutoBOM: _propTypes2.default.bool,
expandAll: _propTypes2.default.bool,
hideRowOnExpand: _propTypes2.default.bool
}),
fetchInfo: _propTypes2.default.shape({
dataTotalSize: _propTypes2.default.number
}),
renderAlert: _propTypes2.default.bool,
exportCSV: _propTypes2.default.bool,
csvFileName: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
ignoreSinglePage: _propTypes2.default.bool,
@@ -2145,6 +2218,7 @@ BootstrapTable.propTypes = {
columnWidth: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]),
expandColumnVisible: _propTypes2.default.bool,
expandColumnComponent: _propTypes2.default.func,
expandedColumnHeaderComponent: _propTypes2.default.func,
expandColumnBeforeSelectColumn: _propTypes2.default.bool
}),
footer: _propTypes2.default.bool
@@ -2158,6 +2232,7 @@ BootstrapTable.defaultProps = {
expandColumnOptions: {
expandColumnVisible: false,
expandColumnComponent: undefined,
expandedColumnHeaderComponent: undefined,
expandColumnBeforeSelectColumn: true
},
height: '100%',
@@ -2293,11 +2368,14 @@ BootstrapTable.defaultProps = {
beforeShowError: undefined,
printToolBar: true,
insertFailIndicator: _Const2.default.INSERT_FAIL_INDICATOR,
noAutoBOM: true
noAutoBOM: true,
expandAll: false,
hideRowOnExpand: false
},
fetchInfo: {
dataTotalSize: 0
},
renderAlert: true,
exportCSV: false,
csvFileName: 'spreadsheet.csv',
ignoreSinglePage: false,