UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

17 lines (16 loc) 807 B
import { clamp } from "@1771technologies/lytenyte-shared"; export function boundSelectionRect(view, rowCount, rect) { const maxRow = rowCount; const minRow = 0; const maxColumn = view.visibleColumns.length; const minColumn = 0; const rowStartMaybe = clamp(minRow, rect.rowStart, maxRow); const rowEndMaybe = clamp(minRow, rect.rowEnd, maxRow); const colStartMaybe = clamp(minColumn, rect.columnStart, maxColumn); const colEndMaybe = clamp(minColumn, rect.columnEnd, maxColumn); const rowStart = Math.min(rowStartMaybe, rowEndMaybe); const rowEnd = Math.max(rowStartMaybe, rowEndMaybe); const columnStart = Math.min(colStartMaybe, colEndMaybe); const columnEnd = Math.max(colStartMaybe, colEndMaybe); return { rowStart, rowEnd, columnStart, columnEnd }; }