UNPKG

handsontable

Version:

Handsontable is a JavaScript Data Grid available for React, Angular and Vue.

95 lines (92 loc) 3.25 kB
"use strict"; exports.__esModule = true; exports.getMostBottomEndPosition = getMostBottomEndPosition; exports.getMostTopStartPosition = getMostTopStartPosition; exports.normalizeCoordsIfNeeded = normalizeCoordsIfNeeded; var _number = require("../../helpers/number"); /** * Normalizes the coordinates (clamps to nearest visible cell position within dataset range). * * @param {Core} hot The Handsontable instance. * @returns {function(Coords | undefined): Coords | null} */ function normalizeCoordsIfNeeded(hot) { return coords => { if (!coords) { return null; } const { rowIndexMapper, columnIndexMapper } = hot; if (rowIndexMapper.isHidden(coords.row) || columnIndexMapper.isHidden(coords.col)) { return null; } const mostTopStartCoords = getMostTopStartPosition(hot); const mostBottomEndCoords = getMostBottomEndPosition(hot); if (mostTopStartCoords === null || mostBottomEndCoords === null) { return null; } coords.row = (0, _number.clamp)(coords.row, mostTopStartCoords.row, mostBottomEndCoords.row); coords.col = (0, _number.clamp)(coords.col, mostTopStartCoords.col, mostBottomEndCoords.col); return coords; }; } /** * Gets the coordinates of the most top-start cell or header (depends on the table settings and its size). * * @param {Core} hot The Handsontable instance. * @returns {CellCoords|null} */ function getMostTopStartPosition(hot) { const { rowIndexMapper, columnIndexMapper } = hot; const { navigableHeaders } = hot.getSettings(); let topRow = navigableHeaders && hot.countColHeaders() > 0 ? -hot.countColHeaders() : 0; let startColumn = navigableHeaders && hot.countRowHeaders() > 0 ? -hot.countRowHeaders() : 0; if (topRow === 0) { topRow = rowIndexMapper.getVisualFromRenderableIndex(topRow); } if (startColumn === 0) { startColumn = columnIndexMapper.getVisualFromRenderableIndex(startColumn); } if (topRow === null || startColumn === null) { return null; } return hot._createCellCoords(topRow, startColumn); } /** * Gets the coordinates of the most bottom-end cell or header (depends on the table settings and its size). * * @param {Core} hot The Handsontable instance. * @returns {CellCoords|null} */ function getMostBottomEndPosition(hot) { var _rowIndexMapper$getVi, _columnIndexMapper$ge; const { rowIndexMapper, columnIndexMapper } = hot; const { navigableHeaders } = hot.getSettings(); let bottomRow = rowIndexMapper.getRenderableIndexesLength() - 1; let endColumn = columnIndexMapper.getRenderableIndexesLength() - 1; if (bottomRow < 0) { if (!navigableHeaders || hot.countColHeaders() === 0) { return null; } bottomRow = -1; } if (endColumn < 0) { if (!navigableHeaders || hot.countColHeaders() === 0) { return null; } endColumn = -1; } return hot._createCellCoords((_rowIndexMapper$getVi = rowIndexMapper.getVisualFromRenderableIndex(bottomRow)) !== null && _rowIndexMapper$getVi !== void 0 ? _rowIndexMapper$getVi : bottomRow, (_columnIndexMapper$ge = columnIndexMapper.getVisualFromRenderableIndex(endColumn)) !== null && _columnIndexMapper$ge !== void 0 ? _columnIndexMapper$ge : endColumn); }