| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.Body = void 0; |
| 4 |
const tslib_1 = require("tslib"); |
| 5 |
const jsx_runtime_1 = require("react/jsx-runtime"); |
| 6 |
/** |
| 7 |
* body.tsx |
| 8 |
* |
| 9 |
* Forked from reactabular-table version 8.14.0 |
| 10 |
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src |
| 11 |
*/ |
| 12 |
const react_1 = require("react"); |
| 13 |
const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual")); |
| 14 |
const provider_1 = require("../../../../components/Table/base/provider"); |
| 15 |
const resolve_row_key_1 = require("./resolve-row-key"); |
| 16 |
const body_row_1 = require("./body-row"); |
| 17 |
class BaseBody extends react_1.Component { |
| 18 |
constructor() { |
| 19 |
super(...arguments); |
| 20 |
this.omitOnRow = (props) => { |
| 21 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 22 |
const { onRow } = props, ret = tslib_1.__rest(props, ["onRow"]); |
| 23 |
return ret; |
| 24 |
}; |
| 25 |
} |
| 26 |
shouldComponentUpdate(nextProps) { |
| 27 |
// Skip checking props against `onRow` since that can be bound at render(). |
| 28 |
// That's not particularly good practice but you never know how the users |
| 29 |
// prefer to define the handler. |
| 30 |
// Check for wrapper based override. |
| 31 |
const { renderers } = nextProps; |
| 32 |
if (renderers && |
| 33 |
renderers.body && |
| 34 |
renderers.body.wrapper && |
| 35 |
renderers.body.wrapper.shouldComponentUpdate) { |
| 36 |
if (typeof renderers.body.wrapper.shouldComponentUpdate === 'function') { |
| 37 |
return renderers.body.wrapper.shouldComponentUpdate.call(this, nextProps, {}, {}); |
| 38 |
} |
| 39 |
return true; |
| 40 |
} |
| 41 |
return !(0, isEqual_1.default)(this.omitOnRow(this.props), this.omitOnRow(nextProps)); |
| 42 |
} |
| 43 |
render() { |
| 44 |
const _a = this.props, { onRow, rows, rowKey, columns, renderers } = _a, props = tslib_1.__rest(_a, ["onRow", "rows", "rowKey", "columns", "renderers"]); |
| 45 |
const children = rows.map((rowData, index) => { |
| 46 |
const key = (0, resolve_row_key_1.resolveRowKey)({ rowData, rowIndex: index, rowKey }); |
| 47 |
return (0, react_1.createElement)(body_row_1.BodyRow, { |
| 48 |
key, |
| 49 |
renderers: renderers.body, |
| 50 |
onRow, |
| 51 |
rowKey: key, |
| 52 |
rowIndex: index, |
| 53 |
rowData, |
| 54 |
columns |
| 55 |
}); |
| 56 |
}); |
| 57 |
return (0, react_1.createElement)(renderers.body.wrapper, props, children); |
| 58 |
} |
| 59 |
} |
| 60 |
BaseBody.defaultProps = { |
| 61 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 62 |
onRow: (...args) => ({}) |
| 63 |
}; |
| 64 |
const Body = (props) => ((0, jsx_runtime_1.jsx)(provider_1.ProviderContext.Consumer, { children: ({ columns, renderers }) => (0, jsx_runtime_1.jsx)(BaseBody, Object.assign({ columns: columns, renderers: renderers }, props)) })); |
| 65 |
exports.Body = Body; |
| 66 |
//# sourceMappingURL=body.js.map |