es-grid-template
Version:
es-grid-template
65 lines (64 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.autoRowSpan = autoRowSpan;
var _internals = require("../../internals");
var _utils = require("../../utils");
function isIdentity(x, y) {
return x === y;
}
function autoRowSpan() {
return function autoRowSpanStep(pipeline) {
const dataSource = pipeline.getDataSource();
return pipeline.mapColumns((0, _utils.makeRecursiveMapper)((col, {
startIndex,
endIndex
}) => {
if (!col.features?.autoRowSpan) {
return col;
}
if (!(0, _utils.isLeafNode)(col)) {
return col;
}
const isFunc = typeof col.features.autoRowSpan === 'function';
const shouldMergeCell = isFunc ? col.features.autoRowSpan : isIdentity;
const spanRects = [];
let lastBottom = 0;
let prevValue = null;
let prevRow = null;
for (let rowIndex = 0; rowIndex < dataSource.length; rowIndex++) {
const row = dataSource[rowIndex];
const value = _internals.internals.safeGetValue(col, row, rowIndex);
if (rowIndex === 0 || !shouldMergeCell(prevValue, value, prevRow, row)) {
const spanRect = {
top: lastBottom,
bottom: rowIndex,
left: startIndex,
right: endIndex
};
for (let i = lastBottom; i < rowIndex; i++) {
spanRects.push(spanRect);
}
lastBottom = rowIndex;
}
prevValue = value;
prevRow = row;
}
for (let i = lastBottom; i < dataSource.length; i++) {
spanRects.push({
top: lastBottom,
bottom: dataSource.length,
left: startIndex,
right: endIndex
});
}
return {
...col,
getSpanRect(value, row, rowIndex) {
return spanRects[rowIndex];
}
};
}));
};
}