@revolist/revogrid
Version:
Virtual reactive data grid spreadsheet component - RevoGrid.
49 lines (48 loc) • 1.29 kB
JavaScript
/*!
* Built by Revolist OU ❤️
*/
export function nextCell(cell, lastCell) {
const nextItem = {};
let types = ['x', 'y'];
// previous item check
for (let t of types) {
if (cell[t] < 0) {
nextItem[t] = cell[t];
return nextItem;
}
}
// next item check
for (let t of types) {
if (cell[t] >= lastCell[t]) {
nextItem[t] = cell[t] - lastCell[t];
return nextItem;
}
}
return null;
}
export function cropCellToMax(cell, lastCell) {
const croppedCell = Object.assign({}, cell);
const cellCoordinates = ['x', 'y'];
for (const coordinate of cellCoordinates) {
if (cell[coordinate] < 0) {
croppedCell[coordinate] = 0;
}
else if (cell[coordinate] >= lastCell[coordinate]) {
croppedCell[coordinate] = lastCell[coordinate] - 1;
}
}
return croppedCell;
}
export function getRange(start, end) {
return start && end
? {
x: Math.min(start.x, end.x),
y: Math.min(start.y, end.y),
x1: Math.max(start.x, end.x),
y1: Math.max(start.y, end.y),
}
: null;
}
export function isRangeSingleCell(a) {
return a.x === a.x1 && a.y === a.y1;
}