diff options
| author | Josh Kingsley <josh@joshkingsley.me> | 2025-11-06 22:31:12 +0200 |
|---|---|---|
| committer | Josh Kingsley <josh@joshkingsley.me> | 2025-11-06 22:31:12 +0200 |
| commit | 6ea86b1b56aebbae7edeb37b01d7bf5cd145bf60 (patch) | |
| tree | bfd0178097a56087471543950caebed5f8280040 /web/src/types.ts | |
| parent | dad5b47f0bb480532043df8d488f5609f731b00d (diff) | |
feat(web): change subvisions
Diffstat (limited to 'web/src/types.ts')
| -rw-r--r-- | web/src/types.ts | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/web/src/types.ts b/web/src/types.ts index b41bb9a..dc26c89 100644 --- a/web/src/types.ts +++ b/web/src/types.ts @@ -1,9 +1,10 @@ +import { Immutable } from "immer"; import Ratio from "./math/Ratio"; -export interface Cell { +export type Cell = Immutable<{ value?: string; widthRatio: Ratio; -} +}>; export interface Row { cells: Cell[]; @@ -44,42 +45,11 @@ export function cellRefEquals(a: CellRef, b: CellRef): boolean { ); } -export function mapRowsInRange( - doc: Doc, - gridId: string, - startRef: CellRef, - endRef: CellRef, - mapFn: (row: Row, ref: RowRef) => Row, -): Doc { - const firstPartIndex = Math.min(startRef.partIndex, endRef.partIndex); - const lastPartIndex = Math.max(startRef.partIndex, endRef.partIndex); - const firstRowIndex = Math.min(startRef.rowIndex, endRef.rowIndex); - const lastRowIndex = Math.max(startRef.rowIndex, endRef.rowIndex); - - return { - ...doc, - grids: doc.grids.map((grid) => { - if (grid.id !== gridId) return grid; - - return { - ...grid, - parts: grid.parts.map((part, partIndex) => { - if (partIndex < firstPartIndex || partIndex > lastPartIndex) { - return part; - } - - return { - ...part, - rows: part.rows.map((row, rowIndex) => { - if (rowIndex < firstRowIndex || rowIndex > lastRowIndex) { - return row; - } - - return mapFn(row, { partIndex, rowIndex }); - }), - }; - }), - }; - }), - }; +export function renderedRowIndexToRef( + grid: Grid, + renderedRowIndex: number, +): RowRef { + const partIndex = renderedRowIndex % grid.parts.length; + const rowIndex = Math.floor(renderedRowIndex / grid.parts.length); + return { partIndex, rowIndex }; } |
