summaryrefslogtreecommitdiff
path: root/web/src/index.ts
diff options
context:
space:
mode:
authorJosh Kingsley <josh@joshkingsley.me>2025-10-26 14:28:55 +0200
committerJosh Kingsley <josh@joshkingsley.me>2025-10-26 14:28:55 +0200
commit0324660a26684a5382b2c6c18cd0a4e9f0169631 (patch)
tree64c16e8a4a4815f050f7e06a3b9486a668f2b4d4 /web/src/index.ts
parent1b8d05bf83d7bd9ab425852f519ea81bdc379444 (diff)
feat(web): add dummy toolbar + tailwindcss colors
Diffstat (limited to 'web/src/index.ts')
-rw-r--r--web/src/index.ts38
1 files changed, 35 insertions, 3 deletions
diff --git a/web/src/index.ts b/web/src/index.ts
index fbbf37c..ac4870c 100644
--- a/web/src/index.ts
+++ b/web/src/index.ts
@@ -1,5 +1,7 @@
import Ratio from "./math/Ratio";
-import { Cell, Doc, Grid } from "./types";
+import { Cell, CellRef, Doc, Grid } from "./types";
+import { ActiveCellSelection, PendingSelection, Selection } from "./selection";
+import renderGrid, { RenderedGrid } from "./components/grid/renderGrid";
function defaultDoc(): Doc {
const defaultCells: Cell[] = Array.from({ length: 16 }, () => ({
@@ -20,17 +22,47 @@ function defaultDoc(): Doc {
},
],
},
+ {
+ id: window.crypto.randomUUID(),
+ baseCellSize: 48,
+ baseCellWidthRatio: new Ratio(1, 16),
+ parts: [
+ {
+ rows: Array.from({ length: 4 }, () => ({
+ cells: [...defaultCells],
+ })),
+ },
+ ],
+ },
],
};
}
export default class Notive {
doc: Doc = defaultDoc();
- gridsById = Object.fromEntries(this.doc.grids.map((grid) => [grid.id, grid]));
- getGrid(id: string): Grid | undefined {
+ gridsById = Object.fromEntries(
+ this.doc.grids.map((grid) => [grid.id, renderGrid(grid)]),
+ );
+
+ selection?: Selection;
+
+ pendingSelection?: Selection;
+
+ getGrid(id: string): RenderedGrid | undefined {
return this.gridsById[id];
}
+
+ selectCell(gridId: string, cellRef: CellRef) {
+ const previousSelection = this.selection;
+ this.selection = new ActiveCellSelection(gridId, cellRef);
+
+ window.dispatchEvent(
+ new CustomEvent("ntv:selection-changed", {
+ detail: { selection: this.selection, previousSelection },
+ }),
+ );
+ }
}
window.notive = new Notive();