UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

70 lines (69 loc) 2.6 kB
/** * DevExtreme (esm/__internal/grids/pivot_grid/keyboard_navigation/table_cell_navigation.js) * Version: 26.1.4 * Build date: Fri Jul 24 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ export function buildCellMatrix(section) { const matrix = []; Array.from(section.rows).forEach((row, rowIndex) => { matrix[rowIndex] ?? (matrix[rowIndex] = []); let columnIndex = 0; Array.from(row.cells).forEach(cell => { var _a; while (matrix[rowIndex][columnIndex]) { columnIndex += 1 } for (let rowOffset = 0; rowOffset < cell.rowSpan; rowOffset += 1) { for (let columnOffset = 0; columnOffset < cell.colSpan; columnOffset += 1) { matrix[_a = rowIndex + rowOffset] ?? (matrix[_a] = []); matrix[rowIndex + rowOffset][columnIndex + columnOffset] = cell } } columnIndex += cell.colSpan }) }); return matrix } export function getCellCoordinates(matrix, cell) { for (let rowIndex = 0; rowIndex < matrix.length; rowIndex += 1) { var _matrix$rowIndex; const columnIndex = (null === (_matrix$rowIndex = matrix[rowIndex]) || void 0 === _matrix$rowIndex ? void 0 : _matrix$rowIndex.indexOf(cell)) ?? -1; if (columnIndex > -1) { return { rowIndex: rowIndex, columnIndex: columnIndex } } } return } export function getAdjacentCell(section, cell, direction) { const matrix = buildCellMatrix(section); const coordinates = getCellCoordinates(matrix, cell); if (!coordinates) { return null } const { rowIndex: rowIndex, columnIndex: columnIndex } = coordinates; const target = (() => { var _matrix, _matrix2; switch (direction) { case "left": return matrix[rowIndex][columnIndex - 1]; case "right": return matrix[rowIndex][columnIndex + cell.colSpan]; case "up": return null === (_matrix = matrix[rowIndex - 1]) || void 0 === _matrix ? void 0 : _matrix[columnIndex]; case "down": return null === (_matrix2 = matrix[rowIndex + cell.rowSpan]) || void 0 === _matrix2 ? void 0 : _matrix2[columnIndex]; default: return } })(); return target && target !== cell ? target : null }