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