Architecture decision record · ADR-0017

The Sheet surface (milestone M10, part 2)

LatticeSheet (packages/sheet/src/surface/) takes @workbook, @label, @editing, @collab and @rowHeight.

Status
Proposed
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

Plan section 4.7 asks for a Sheet surface: A1 headers, a formula bar, sheet tabs, frozen panes and a fill handle, with ARIA grid. ADR 0015 made the model (Workbook, Sheet) and the engine seam. ADR 0016 made the collaboration client (CollabSession). The surface must use LatticeGrid through its public args and extension points (docs/m2-grid-contract.md), and the editing plug-in of @ember-lattice/editing.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

1. One component on top of LatticeGrid

LatticeSheet (packages/sheet/src/surface/) takes @workbook, @label, @editing, @collab and @rowHeight. SheetSurface holds the state: the active sheet, the table, the input path, the viewport watch and the peers.

  • The grid gets data-lt-preset="sheet" and data-lt-borders="cells" through ...attributes. No Grid change is necessary for the preset.
  • The table has one column for each sheet column (header A, B, ...) and a row number column (:row, pinned at the start). A sheet column ID cannot have a colon.
  • Each sheet cell is a full cell (SheetCell). It shows the computed value with the number format, the cell style, the conditional format, the merge box and the markers.
  • The surface reads the active cell and the scroll offset from a GridStateHandle. It reads them in a microtask after each notify, because the grid notifies during its own updates.

2. The value of a sheet cell is a handle

The core row model caches each value (row._valuesCache) while the data array stays the same. Thus a text value would be old after an edit. The accessor gives a SheetCellValue instead: the position and the editor text (the A1 formula or the raw value) at the time of the read.

  • EditController keeps the handle as the value before an edit, so undo writes the old text.
  • A fill repeats the source handles (fillSeries repeats values that are not strings). sheetCellEdit sees a handle of another cell and moves its formula through R1C1, as Excel does. =A1*2 filled down gives =A2*2.
  • The column format gives the shown text, so a copy gives the shown values.
  • The surface removes the cached value of a cell when it writes the cell, and of the active cell when the active cell changes. A remote edit can leave an old handle until then.

3. The input path

sheetCellEdit is the onCellEdit of the EditController. The formula bar uses the same path. Without @collab, it calls Workbook.setInput. With @collab, it checks the validation, converts A1 to the stored form and calls session.apply, so the op goes to the server. Notes, frozen panes, rules and validations are local only, because the wire carries SheetOp only (ADR 0016). An invalid value rejects the save, and the message goes to the live region.

4. The viewport watch

The surface calls engine.watch with the rows in view (40 rows before, 120 rows after the first row) and all columns, on the first render, on a scroll to a new row and on a sheet change. One call is in flight; the newest range wins. The values go into the model with Sheet.updateCell. shortcut: all columns; limit to the columns in view for wide sheets.

5. Merges: an overlay box in the anchor cell

LatticeGrid has no body cell spanning. The anchor cell (top-left) shows a box with the width of the merged columns and the height of the merged rows. The row of the anchor goes above the next rows. The covered cells show no text (data-merged). A pinned anchor gets clip-path: none, because a pinned cell clips its shadow side.

  • When the anchor row is outside the rendered range, the merge shows as blank cells.
  • A merge from a pinned column into the center columns covers those columns when they scroll.

6. Frozen panes

Frozen columns are pinned at the start (columnPinning.start). Frozen rows need pinned rows in LatticeGrid (see "Grid changes").

7. Validation, notes and presence

  • A cell with a list validation edits with a select. A value that the validation refuses gets data-invalid (a mark at the start corner).
  • A cell with a note gets data-note (a mark at the end corner). When the cell is active, the note shows in div.lt-sheet-note role="note", outside role=grid, under the cell.
  • With @collab, the surface keeps the peers in tracked state through onPresence and gives the old callback back when it is destroyed. A cell shows a ring for a peer cursor or selection, a name label on the cursor (black or white text, from the contrast) and stripes for a soft lock. A list of the peers is outside the grid, for screen readers. The surface sends the cursor and the selection when the active cell changes, and the edited cell while the editor is open.

8. Not in the package index

The surface is not exported from src/index.ts. The model must load in Node: collab loads the built package in Vitest, and the sheet tests load the source. A Glimmer component in that import graph breaks both. The surface has its own barrel, src/surface/index.ts, and uses structural model types (SheetBook, SheetModel), so a source copy and a built copy of Workbook both fit.

Amendment 1: grid spans, frozen rows, the column watch, undo, help and wire ops

The grid now has row pinning, cell and row spans and row numbers (ADR 0018). This amendment replaces the parts of sections 1, 3, 4, 5 and 6 that it names.

  1. Row numbers. The row number column is rowNumberColumn() of @ember-lattice/ember, with the ID :row. The grid shows the display position. Frozen rows come first, so the display position is the sheet row.
  2. Frozen rows. The table has rowPinningFeature. initialState.rowPinning.top holds the first frozen.rows row IDs. A frozen row is a pinned row: it stays under the header.
  3. Merges are grid spans (replaces section 5). The table has cellSpanningFeature. The start column of a merge gets spanColumns (the merge width on each merge row) and spanRows (a predicate: the anchor row and the row are in the same merge). The anchor is one gridcell with aria-rowspan and aria-colspan. The covered cells are not in the grid. The overlay box and data-merged are gone. enableCellSpanning is false for a sheet with no merge, so a large sheet builds no span index. Limits: a merge does not cross the edge of the frozen rows or the frozen columns (a span never crosses a pinned section), and ADR 0018 lists the limits of a column span.
  4. The column watch (replaces the shortcut of section 4). The surface watches the frozen columns and the center columns from 1,000 px before the scroll offset to 4,000 px after it, from the column sizes. The frozen rows are always in the watched rows.
  5. Undo with @collab. A capture-phase key listener on the panel sends Ctrl+Z to session.undo() and Ctrl+Y or Ctrl+Shift+Z to session.redo(). It ignores keys in an input or a select. The session undo does not write over a later edit of another user. The EditController stack is not used with @collab. Without @collab, the EditController undoes, as before.
  6. Remote edits. CollabSession.onRemote(ops) runs after the ops of another user are in the model. The surface removes the cached values of the written cells (this closes the gap of section 2) and tells the open editor. An editor with no typed text takes the new text. An editor with typed text keeps it, gets data-conflict, and the live region says that another user changed the cell. Escape shows the new value.
  7. Formula help. The formula bar is a combobox with aria-autocomplete="list". A function name after = opens a listbox (outside role=grid) of the functions with that start, each with its signature from engine.functions() (FunctionInfo.signature, new and optional). The arrow keys move aria-activedescendant. Enter or Tab puts in NAME( and does not commit. Escape closes the list. In a call, div.lt-sheet-hint shows the signature and is in aria-describedby. The list has the class lt-sheet-note, so the theme shows it as a popup.
  8. Notes and frozen panes go over the wire (replaces the last sentences of section 3). The wire op is CollabOp: SheetOp, setNote and freeze. The server checks them, applies them to its model, logs them and does not give them to the engine. A snapshot has note on a cell and frozen on a sheet only when they are set, so the form of a doc without them does not change. Conditional formats and data validation stay local.

Evidence

test-app/tests/sheet/lattice-sheet-test.gts has 13 render tests, each with an axe audit: the pinned frozen row, a merge of rows and columns, the column watch, the formula help, undo and redo through the session, and a remote edit under an open editor are new. packages/collab/tests/session.test.ts tests redo, the note and pane ops and onRemote. The convergence test makes random setNote and freeze ops. packages/server/tests/collab tests the parser and the server for the new ops.

The sheet gate again, after the amendment: the same method, production build, headless Chromium, Apple M4. Other builds and tests ran on the host at the same time, so the load took about twice as long as in the first table.

Item Run 1 Run 2
Edit to paint 115, 117, 117, 150, 105 ms 116, 117, 101, 167, 117 ms
Median 117 ms 117 ms
Long tasks (> 50 ms) 0 0
Longest frame gap 17 ms 17 ms
Load (outside the gate) 6,072 ms 6,890 ms

The gate passes: under 300 ms, and the UI does not block. The gate sheet has no merge, so it builds no span index.

Grid changes still needed

  • A cell that a merge above covers leaves a spacer of one column (spanOf with a row span of 0). In a merge of more than one row and more than one column, the rows under the anchor then put the cells after the merge too far to the start. The spacer must have the width of the column span of that cell.
  • role="rowheader" on the row number cells (another change adds it in the grid).

Consequences of the amendment

  • The .lt-sheet-merge rule in packages/theme/src/sheet.css is not used now, and the theme fixture (fixtures/sheet.html) still shows the old overlay box.
  • A rebuild of the view in CollabSession loads the doc from the shadow, which has no rules and no validations. A rebuild thus removes the local rules and validations of the view.
  • A server without setNote and freeze (the Ruby and Python ports now, or an older TS server) rejects such a submit as bad_message with no op ID. The op then stays pending in the session. Add the ops to a port before a client that uses notes or panes connects to it.
  • onRemote does not run for a snapshot after a reconnect, so an open editor does not take a change that comes in a snapshot.
  • Remaining work: wire ops for rules and validations, and a test of the cursor of a peer on another sheet.

Consequences

  • The surface follows the grid contract. It needs no Grid change for the preset, the editor, the fill handle or the clipboard.
  • Remaining work: frozen rows and true merges (the Grid changes), the watch of the columns in view, undo through the session with @collab, the formula help in the bar, and a test of the cursor of a peer on another sheet.

Confirmation

Evidence

Tests

test-app/tests/sheet/lattice-sheet-test.gts: 8 render tests, each with an axe audit. They use MiniEngine (test-app/app/sheet/mini-engine.ts), a small engine with the IronCalc diff model. packages/theme/tests-browser/sheet.test.mjs: 4 tests on fixtures/sheet.html (contrast in light and dark, the pinned merge box, the markers).

Sheet gate

The /sheet?gate demo loads 100,000 formula cells (B{r} = $A$1*2 + A{r}) into IronCalc 0.9.1 in a module worker. It then sets A1 five times with Workbook.setInput and times each edit to the next frame after a MutationObserver sees B5 change. The long task observer and the frame gap loop start after the load. Production build, headless Chromium (Playwright 1.65), Apple M4. Two runs:

Item Run 1 Run 2
Edit to paint 83, 67, 83, 83, 83 ms 66, 84, 100, 83, 67 ms
Median 83 ms 83 ms
Long tasks (> 50 ms) 0 0
Longest frame gap 17 ms 17 ms
Load (outside the gate) 3,258 ms 3,045 ms

The gate passes: under 300 ms, and the UI does not block. The load blocks the page for part of its time (watch(null) sends 200,000 values). Load large sheets from a snapshot.

Grid changes

  • Pinned rows (rowPinning) in LatticeGrid, for frozen rows.
  • Body cell spanning, so a merge is one cell for the grid, the selection and ARIA.
  • role="rowheader" for a column (the row numbers).

Package changes

  • packages/sheet/package.json: exports["./surface"] with { "types": "./declarations/surface/index.d.ts", "default": "./dist/surface/index.js" }.
  • packages/sheet/rollup.config.mjs: addon.publicEntrypoints(['index.js', 'surface/index.js']).
  • test-app/package.json: @ember-lattice/formula-ironcalc, so the demo does not import the built file by a relative path.

Interview record

Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0017-sheet-surface.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so.Document: docs/adr/0017-sheet-surface.md

Changelog

DateAuthorChange
2026-12-02Joe GaudetStatus in the Markdown file: proposed, 2026-12-02. Amended 2026-12-02: see "Amendment 1" at the end.
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0017-sheet-surface.md to this page. The text is the text of the Markdown file.

The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.