oficina / sheets Public

Spec: native optimistic edits (section 7), and durable edits deferred with a trigger

Also: only a cell with an unsaved edit carries a context menu and tooltip.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 604b09df76596bacea98a3c2082970ddebb028a4 parent 89bd9c4
2 files changed, +34 −8
  • docs/superpowers/specs/2026-08-30-sheets-design.md +13 −1
  • native/apple/Sources/SheetsKit/SheetCell.swift +21 −7
diff --git a/docs/superpowers/specs/2026-08-30-sheets-design.md b/docs/superpowers/specs/2026-08-30-sheets-design.md
index b974d6f..9e3b0a2 100644
--- a/docs/superpowers/specs/2026-08-30-sheets-design.md
+++ b/docs/superpowers/specs/2026-08-30-sheets-design.md
@@ -356,6 +356,18 @@ out-of-order paints by version rather than by arrival. Without this,
optimistic painting plus LWW produces visibly wrong grids under two
concurrent editors — the exact bug the optimism is meant to hide.
+**The native apps paint a committed cell at once and send in the
+background** (Paul, 2026-11-26: the cell going grey for a round trip was
+"unnecessary"). One send per document is in flight; edits made meanwhile
+wait and go together in the next. On screen, a queued or in-flight local
+value wins over the server's for that cell, so a peer update landing
+first does not flicker it back and then forward; once the server
+acknowledges, the cell shows the server's newest value by version (ours,
+or a peer's that came after it). A refused or unanswered edit keeps its
+value on screen, marked as not saved, with Retry and Revert, and blocks
+nothing else. These edits live in memory: they do not survive a quit or
+crash while unsent (§14).
+
**The SSE transport check is a streamed 200**, not a 101. SSE is
`text/event-stream` over a normal response; 101 is the WebSocket upgrade.
The test verifies an unbuffered stream through the real edge — a check
@@ -1148,7 +1160,7 @@ it is a fallback rather than a scramble.
| ~~Sharing a sheet whose sole owner left the team~~ | **Ruled and built 2026-10-28** (Paul, oficina/sheets #52). Team mode made it routine: a removed creator's own grant stops counting, so the team could edit the sheet and nobody could share it. A roster owner now holds `owner` on any sheet with no live owner grant (§8.2, `team_owner.go`). Still not built: an explicit, auditable "Take ownership" verb that writes a grant — trigger: **a team asks who rescued a sheet**, or the rule needs to outlive a roster owner's own removal. |
| Pivot tables | Asked for twice |
| Rich presence beyond who's-here | Teams above ~5 concurrent editors |
-| Offline editing | — |
+| **Durable native cell edits (offline editing)** | Native edits are optimistic but in memory (§7): a quit, crash or long offline spell loses what was not yet acknowledged, and Quit waits or asks rather than pretend. Durability needs more than the shared kit's outbox (`OutboxDrainer`/`NativeSealedStore`, as Docs uses): Docs replays CRDT updates, which are idempotent and merge, while a Sheets edit is last-write-wins (ruling 3), so replaying one after a crash — when the server may already have it — or after hours offline would silently overwrite newer edits by others. It needs a client edit id the server dedupes on (an additive table, every write route in `TestTeamEveryWriteRouteRefusesALapseBeforeCommit`) and a base version per cell so a stale replay is held as a conflict, not applied. Design in oficina/sheets discussion for branch `fix/cell-editing-optimistic`. Trigger: **Paul asks for offline editing, or an edit is reported lost to a quit or crash.** |
| Mobile-native apps | — |
| `client` shape for anything but the grid | A surface genuinely needs client-held keys |
| Print / PDF export | Asked for. docs-e6 keeps its layout engine's page model generic over content boxes so this stays open: paginated grid, repeating header rows, scale-to-width, explicit page breaks, charts as vector |
diff --git a/native/apple/Sources/SheetsKit/SheetCell.swift b/native/apple/Sources/SheetsKit/SheetCell.swift
index a3d04ce..2807a35 100644
--- a/native/apple/Sources/SheetsKit/SheetCell.swift
+++ b/native/apple/Sources/SheetsKit/SheetCell.swift
@@ -66,13 +66,7 @@ struct SheetCell: View {
.overlay(alignment: .topTrailing) { if failed { SheetNotSavedMark() } }
}.buttonStyle(.plain)
.simultaneousGesture(TapGesture(count: 2).onEnded { if model.mayWrite, !model.dirty { model.select(point); beginEditing() } })
- .contextMenu {
- if failed {
- Button(sheetsMacString("Retry")) { model.retryWrites([point]) }
- Button(sheetsMacString("Revert"), role: .destructive) { model.revertWrites([point]) }
- }
- }
- .help(failed ? sheetsMacString("Not saved") : "")
+ .modifier(NotSavedActions(model: model, point: point, failed: failed))
.accessibilityLabel("\(point.ref), \(cell?.display ?? "Empty")")
.accessibilityValue(failed ? sheetsMacString("Not saved") : style?.lc == true ? "Imported colours have low contrast" : "")
.accessibilityAddTraits(model.selection.contains(point) ? .isSelected : [])
@@ -89,6 +83,26 @@ struct SheetCell: View {
}
}
+/// Retry and Revert on a cell whose edit was not saved. Only such a cell
+/// carries a context menu and a tooltip, so the rest of the grid stays light.
+private struct NotSavedActions: ViewModifier {
+ let model: SheetModel
+ let point: Coordinate
+ let failed: Bool
+ func body(content: Content) -> some View {
+ if failed {
+ content
+ .contextMenu {
+ Button(sheetsMacString("Retry")) { model.retryWrites([point]) }
+ Button(sheetsMacString("Revert"), role: .destructive) { model.revertWrites([point]) }
+ }
+ .help(sheetsMacString("Not saved"))
+ } else {
+ content
+ }
+ }
+}
+
/// A refused or unanswered edit: a small corner flag, like a comment marker,
/// so the value stays readable and the rest of the sheet stays calm.
struct SheetNotSavedMark: View {