feat(book/table): allow editing cell values

This commit is contained in:
Elian Doran
2025-06-25 13:06:38 +03:00
parent 66761a69d3
commit 7e20e41521
4 changed files with 73 additions and 40 deletions

View File

@@ -1,11 +1,35 @@
import { createGrid, AllCommunityModule, ModuleRegistry } from "ag-grid-community";
import { buildData } from "./data.js";
import { createGrid, AllCommunityModule, ModuleRegistry, columnDropStyleBordered, GridOptions } from "ag-grid-community";
import { buildData, type TableData } from "./data.js";
import FNote from "../../../entities/fnote.js";
import getPromotedAttributeInformation, { PromotedAttributeInformation } from "./parser.js";
import { setLabel } from "../../../services/attributes.js";
ModuleRegistry.registerModules([ AllCommunityModule ]);
export default function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[]) {
const info = getPromotedAttributeInformation(parentNote);
createGrid(el, {
...buildData(parentNote, notes)
...buildData(info, notes),
...setupEditing(info)
});
}
function setupEditing(info: PromotedAttributeInformation[]): GridOptions<TableData> {
return {
onCellValueChanged(event) {
if (event.type !== "cellValueChanged") {
return;
}
const noteId = event.data.noteId;
const name = event.colDef.field;
if (!name) {
return;
}
const { newValue } = event;
setLabel(noteId, name, newValue);
}
}
}