Something went wrong. Try again.
Convert CSV banking statements to hledger journals
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// The cells picked for a rule (D12, §6.7 of DESIGN_M1.md): some cells of one// row no rule matches, whose clauses the row's buttons add to a rule.//// Rows are told apart by their physical row number, which is all the page// knows of them, and the table is drawn anew on every answer from the server.// So the selection is kept here rather than on the cells, and outlives a// redraw as long as its row is still shown unmatched.
import { clause, patternOf } from "./clause.js";
export class Selection { // The physical row the selected cells are in, and their column numbers. #row = null; #columns = new Set();
// A cell of another row starts the selection over. toggle(row, column) { if (row !== this.#row) this.clear(); this.#row = row; if (!this.#columns.delete(column)) this.#columns.add(column); }
has(row, column) { return row === this.#row && this.#columns.has(column); }
// Whether any cell of `row` is selected. holds(row) { return row === this.#row && this.#columns.size > 0; }
clear() { this.#columns = new Set(); }
// The rows a redraw shows. A selection whose row is matched now, or hidden // by the filter or search, would be added by buttons no one can see. keep(rows) { if (!rows.some((row) => row.row === this.#row && row.status === "zero")) this.clear(); }
// The clauses of the selected cells of a row with `cells`, left to right, // each under the first alias naming its column (legend.js's `columns`). clauses(cells, columns) { return [...this.#columns] .sort((a, b) => a - b) .map((column) => clause(columns.get(column).aliases[0], patternOf(cells[column]))); }}