devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
72 lines (70 loc) • 2.48 kB
JavaScript
/**
* DevExtreme (cjs/__internal/grids/grid_core/m_export.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.prepareItems = prepareItems;
var _extend = require("../../../core/utils/extend");
function prepareItems(items, emptyCell) {
const defaultSetter = value => !value ? 1 : value;
const resultItems = [];
const cols = (items[0] ?? []).reduce((sum, item) => sum + defaultSetter(item.colspan), 0);
const getItem = (rows => {
let rowIndex = 0;
let cellIndex = 0;
return () => {
const row = rows[rowIndex] ?? [];
const item = row[cellIndex];
cellIndex += 1;
if (cellIndex >= row.length) {
rowIndex += 1;
cellIndex = 0
}
if (item) {
item.colspan = defaultSetter(item.colspan);
item.rowspan = defaultSetter(item.rowspan)
}
return item
}
})(items);
const addItem = (rowIndex, cellIndex, item) => {
resultItems[rowIndex] = resultItems[rowIndex] ?? [];
const row = resultItems[rowIndex];
row[cellIndex] = item;
if (item.colspan > 1 || item.rowspan > 1) {
const clone = (item => (0, _extend.extend)({}, item, emptyCell))(item);
for (let c = 1; c < item.colspan; c += 1) {
addItem(rowIndex, cellIndex + c, clone)
}
for (let r = 1; r < item.rowspan; r += 1) {
for (let c = 0; c < item.colspan; c += 1) {
addItem(rowIndex + r, cellIndex + c, clone)
}
}
}
};
let item = getItem();
let rowIndex = 0;
while (item) {
for (let cellIndex = 0; cellIndex < cols; cellIndex += 1) {
var _resultItems$rowIndex;
if (!item) {
break
}
if (!(null !== (_resultItems$rowIndex = resultItems[rowIndex]) && void 0 !== _resultItems$rowIndex && _resultItems$rowIndex[cellIndex])) {
addItem(rowIndex, cellIndex, item);
cellIndex += item.colspan - 1;
item = getItem()
}
}
rowIndex += 1
}
return resultItems
}