From b8f56fee0354d5e51ad27b0a3b5d04797b0e683e Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 15 Jun 2026 02:08:33 +0100 Subject: [PATCH] feat(base): add pure next-cell navigation helper --- .../client/src/ee/base/utils/grid-cell-nav.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 apps/client/src/ee/base/utils/grid-cell-nav.ts diff --git a/apps/client/src/ee/base/utils/grid-cell-nav.ts b/apps/client/src/ee/base/utils/grid-cell-nav.ts new file mode 100644 index 000000000..d945ca672 --- /dev/null +++ b/apps/client/src/ee/base/utils/grid-cell-nav.ts @@ -0,0 +1,33 @@ +import { CellCoord } from "@/ee/base/types/base.types"; + +export function computeNextCell( + rowIds: string[], + colIds: string[], + current: CellCoord, + rowDelta: number, + colDelta: number, + wrap: boolean, +): CellCoord | null { + const colIndex = colIds.indexOf(current.propertyId); + const rowIndex = rowIds.indexOf(current.rowId); + if (colIndex === -1 || rowIndex === -1) return null; + + let nextCol = colIndex + colDelta; + let nextRow = rowIndex + rowDelta; + + if (wrap) { + if (nextCol < 0) { + nextCol = colIds.length - 1; + nextRow -= 1; + } else if (nextCol >= colIds.length) { + nextCol = 0; + nextRow += 1; + } + } else if (nextCol < 0 || nextCol >= colIds.length) { + return null; + } + + if (nextRow < 0 || nextRow >= rowIds.length) return null; + + return { rowId: rowIds[nextRow], propertyId: colIds[nextCol] }; +}