summaryrefslogtreecommitdiff
path: root/web/src/index.ts
diff options
context:
space:
mode:
authorJosh Kingsley <josh@joshkingsley.me>2025-10-26 22:59:39 +0200
committerJosh Kingsley <josh@joshkingsley.me>2025-10-26 22:59:39 +0200
commit41b9d5840ddb6b484fc9f309a95d80f62832cfeb (patch)
tree710ef3e016a0a8ff23f39247561587c5806581f8 /web/src/index.ts
parent74592676444cdb9bdc2fef5dc8c483667b557a5e (diff)
feat(web): editing cells
Diffstat (limited to 'web/src/index.ts')
-rw-r--r--web/src/index.ts28
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();