@justjarethb/table-core
Version:
Fork of @tanstack/table-core with support for event listeners in different windows
55 lines (50 loc) • 1.66 kB
JavaScript
/**
* table-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var utils = require('../utils.js');
function getExpandedRowModel() {
return table => utils.memo(() => [table.getState().expanded, table.getPreExpandedRowModel(), table.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
if (!rowModel.rows.length || expanded !== true && !Object.keys(expanded != null ? expanded : {}).length) {
return rowModel;
}
if (!paginateExpandedRows) {
// Only expand rows at this point if they are being paginated
return rowModel;
}
return expandRows(rowModel);
}, {
key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
debug: () => {
var _table$options$debugA;
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugTable;
}
});
}
function expandRows(rowModel) {
const expandedRows = [];
const handleRow = row => {
var _row$subRows;
expandedRows.push(row);
if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
row.subRows.forEach(handleRow);
}
};
rowModel.rows.forEach(handleRow);
return {
rows: expandedRows,
flatRows: rowModel.flatRows,
rowsById: rowModel.rowsById
};
}
exports.expandRows = expandRows;
exports.getExpandedRowModel = getExpandedRowModel;
//# sourceMappingURL=getExpandedRowModel.js.map