diff options
Diffstat (limited to 'web/src/index.ts')
| -rw-r--r-- | web/src/index.ts | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/web/src/index.ts b/web/src/index.ts index f08aedc..97cfdf8 100644 --- a/web/src/index.ts +++ b/web/src/index.ts @@ -7,9 +7,8 @@ import renderGrid, { } from "./components/grid/renderGrid"; function defaultDoc(): Doc { - const defaultCells: Cell[] = Array.from({ length: 16 }, (_, i) => ({ + const defaultCells: Cell[] = Array.from({ length: 16 }, () => ({ widthRatio: new Ratio(1, 16), - value: i.toString(), })); return { @@ -185,6 +184,31 @@ export default class Notive { }), ); } + + setCellValue(gridId: string, cellRef: CellRef, value: string | undefined) { + const grid = this.doc.grids.find((grid) => grid.id === gridId); + + if (!grid) return; + + const cell = + grid.parts[cellRef.partIndex].rows[cellRef.rowIndex].cells[ + cellRef.cellIndex + ]; + + grid.parts[cellRef.partIndex].rows[cellRef.rowIndex].cells[ + cellRef.cellIndex + ] = { ...cell, value }; + + this.#gridsById = Object.fromEntries( + this.#doc.grids.map((grid) => [grid.id, renderGrid(grid)]), + ); + + window.dispatchEvent( + new CustomEvent("ntv:grid:change", { + detail: { gridId }, + }), + ); + } } window.notive = new Notive(); |
