summaryrefslogtreecommitdiff
path: root/web/src/components/app
diff options
context:
space:
mode:
authorJosh Kingsley <josh@joshkingsley.me>2025-10-30 13:25:02 +0200
committerJosh Kingsley <josh@joshkingsley.me>2025-10-30 13:25:02 +0200
commit715996aceb4d4dc96410464f60727b98a289be08 (patch)
tree876d97664a22246ebecfc25cad1f4b96dee031a0 /web/src/components/app
parent7ef8366bfc43775bf26e71e77bddf31af829dfde (diff)
refactor(web): move selection code
Diffstat (limited to 'web/src/components/app')
-rw-r--r--web/src/components/app/index.ts17
1 files changed, 9 insertions, 8 deletions
diff --git a/web/src/components/app/index.ts b/web/src/components/app/index.ts
index c30249f..aa7c738 100644
--- a/web/src/components/app/index.ts
+++ b/web/src/components/app/index.ts
@@ -1,22 +1,21 @@
import defaultDoc from "../../defaultDoc";
import NotiveElement, { customElement } from "../../element";
-import { Selection } from "../../selection";
import { Doc } from "../../types";
import ntvGrid, { NotiveGridElement } from "../grid";
import renderGrid from "../grid/renderGrid";
+import { GridSelection } from "../grid/selection";
import ntvToolbar from "../toolbar";
import "./index.css";
@customElement("ntv-app")
export class NotiveAppElement extends NotiveElement {
doc: Doc = defaultDoc();
- #selection?: Selection;
- get selection() {
- return this.#selection;
- }
+ #selectedGridId?: string;
+ #selection?: GridSelection;
- set selection(selection: Selection | undefined) {
+ setSelection(gridId: string, selection: GridSelection) {
+ this.#selectedGridId = gridId;
this.#selection = selection;
this.#updateGridSelections();
}
@@ -24,7 +23,7 @@ export class NotiveAppElement extends NotiveElement {
#updateGridSelections() {
this.querySelectorAll<NotiveGridElement>("ntv-grid").forEach((grid) => {
grid.selection =
- this.#selection?.gridId === grid.grid?.id ? this.#selection : undefined;
+ this.#selectedGridId === grid.grid?.id ? this.#selection : undefined;
});
}
@@ -37,7 +36,7 @@ export class NotiveAppElement extends NotiveElement {
grid: renderGrid(grid),
dataset: { gridId: grid.id },
ongridselectionchange: (event) => {
- this.selection = event.selection;
+ this.setSelection(grid.id, event.selection);
},
oncellchange: (event) => {
console.log(event);
@@ -47,3 +46,5 @@ export class NotiveAppElement extends NotiveElement {
);
}
}
+
+export default NotiveAppElement.makeFactory();