From ca7edbcc6b201df7b5070cde205e66f576948475 Mon Sep 17 00:00:00 2001 From: Josh Kingsley Date: Sun, 26 Oct 2025 21:04:24 +0200 Subject: feat(web): add subdivideSelection method --- web/src/index.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'web/src/index.ts') diff --git a/web/src/index.ts b/web/src/index.ts index 6ab61c9..a6f0ac7 100644 --- a/web/src/index.ts +++ b/web/src/index.ts @@ -1,8 +1,10 @@ import Ratio from "./math/Ratio"; -import { Cell, CellRef, Doc, Grid } from "./types"; +import { Cell, CellRef, Doc, Grid, mapRowsInRange } from "./types"; import { ActiveCellSelection, Selection } from "./selection"; -import renderGrid, { RenderedGrid } from "./components/grid/renderGrid"; -import cellAtCoord from "./components/grid/cellAtCoord"; +import renderGrid, { + getRenderedCell, + RenderedGrid, +} from "./components/grid/renderGrid"; function defaultDoc(): Doc { const defaultCells: Cell[] = Array.from({ length: 16 }, () => ({ @@ -29,7 +31,12 @@ function defaultDoc(): Doc { baseCellWidthRatio: new Ratio(1, 16), parts: [ { - rows: Array.from({ length: 4 }, () => ({ + rows: Array.from({ length: 2 }, () => ({ + cells: [...defaultCells], + })), + }, + { + rows: Array.from({ length: 2 }, () => ({ cells: [...defaultCells], })), }, @@ -92,7 +99,23 @@ export default class Notive { } #dispatchSelectionChanged() { - window.dispatchEvent(new CustomEvent("ntv:selection-changed")); + window.dispatchEvent(new CustomEvent("ntv:selectionchange")); + } + + subdivideSelection(subdivisions: number) { + const selection = this.selection; + + if (!selection) return; + + const newDoc = mapRowsInRange( + this.doc, + selection.gridId, + selection.startCellRef(), + selection.endCellRef(), + (row, rowRef) => { + return row; + }, + ); } } -- cgit v1.2.3