Something went wrong

Thank you for being patient! We're working hard on resolving the issue

Sheet & SheetRow - Lona Docs Log in

Sheet & SheetRow

Sheet is the in-memory hydrated model of one Lona sheet. It owns the row tree, every SheetRow instance, and the canonical cell store the render pipeline reads from.

Hydration

A sheet usually starts from a wire-format RawSheet and a Backend:

import { Sheet, RawSheet, TestBackend } from "@tento-lona/sheets";

const raw: RawSheet = JSON.parse(await Deno.readTextFile("fixture.sheet.json"));
const backend = new TestBackend();
const sheet = await Sheet.from(raw, { backend });

Sheet.from walks the wire rows list, registers each row in sheet.stores.rows, builds the parent/child links in sheet.stores.tree, and seeds source cells into sheet.stores.sourceCellData.

Row enumeration

// All rows, in tree order:
for (const row of sheet.allRows()) { /* ... */ }

// Just root rows:
for (const id of sheet.stores.tree.roots()) {
  const row = sheet.findRow(id)!;
  /* ... */
}

// Children of a row:
for (const id of sheet.stores.tree.children(parentId)) { /* ... */ }

SheetRow

Every row implements SheetRow:

class SheetRow {
  readonly id: RowLocalId;        // stable identity for this Sheet session
  readonly rowId: RowId;          // wire-format id (`r_<hex>`, `:lookup`, …)
  readonly label: string;
  readonly descriptor: Descriptor;  // role + per-type metadata
  attributes<A>(): Optional<A>;     // typed attribute bag
  capabilities(): RowCapabilities;  // can-reparent, can-duplicate, etc.
}

Concrete subclasses live under variants/ and carry role-specific state — SourceRow, LayoutRow, RendererRow, AliasRow, FormulaDataSource, plus per-type concretes like ColumnText, ColumnCheckmark, CalendarRow, etc. See Variants & Facades.

Cells

Source cells live on sheet.stores.sourceCellData:

const cells = sheet.stores.sourceCellData.cells(row.id);
for (const [date, entry] of cells) {
  console.log(date.toString(), entry.value);
}

For aggregate / provider rows, cells are reached through indices or the per-row RangeCellHandle (SDK side).

Mutation

Sheet is mutable. addRow, removeRow, setCell, reparent, and friends fire invalidation events on sheet.invalidation — the same sink TreeWatcher and RenderPlan subscribe to.

import { RowDataChanged } from "@tento-lona/sheets";

sheet.invalidation.addListener(this, (e) => {
  if (e instanceof RowDataChanged) {
    rerender(e.rowId);
  }
});

See also