oficina / docs Public

Docs native S2b: Share popover and Delete… (server first) open

On branch native/share-and-delete

Plan slice S2b (docs/superpowers/plans/2026-11-22-native-redesign.md), spec §1 "Share popover" and "Delete…", §6 Offline, §8.

Two commits: the server half first (it must be deployed to prod and lagged before any client release that uses it), then the client.

Server: deletePost answers native JSON

POST /d/{sqid}/delete with Accept: application/json answers 200 {"ok":true} once Store.Delete has committed, with nothing read again. Browsers keep their 303.

The answer is written directly, not with nativeJSON. In team mode nativeJSON's guarded write (team_emission.go) checks every document the request read again before sending. The deleted one then answers 404 for a delete that committed. TestTeamNativeDelete caught this; the code comment says why.

Go matrix:

  • TestNativeOwnerDeleteAnswersOK: the owner gets exactly {"ok":true}, JSON, no redirect. The document is 404 at its URL and gone from the native list. Deleting it again is 404.
  • TestNativeDeleteByAnyoneButTheOwnerIs404AndDeletesNothing: a writer grantee, a guest (reader grantee), a member reader grantee and a team member who reads it by the team rung all get 404, and the owner still reads it.
  • TestTeamNativeDelete (team mode, real router and Home sign-in) covers: - another member's team document and a document shared as a writer: 404, not deleted; - the owner: ok, deleted and announced on the suite feed; - again: 404; - under Unknown: 503, not a page and not ok, nothing deleted.
  • The browser 303 is unchanged: TestOwnerDeletesADocument and TestTeamOwnerDeletesOnlyHerOwnDocument.

Both new owner tests were seen to fail first, with 303.

Deviation (small): the lookup-failure answer to a native caller is today's plain-text failure body with its status (503 or 404), as on every other native route, not a JSON object. The client treats anything that is not {"ok":true} the same way, by checking with a GET.

Client

The Share panel (DocsSharePanelModel, DocsSharePanel) is the web panel's model and words (docs.share.panel.*).

  • Contents: the head and Close, the callout, the invite row (field, Can read / Can edit, Invite), and the people with access, owner first as "(you)", each grant with × named "Stop sharing with {address}". Under general access, the team and link switches, then the once-only URL with Copy link and the once line, or the "shown" line with Make a new link.
  • A switch holds its new position until its request settles, and reverts with the callout on failure.
  • One request at a time; a second submit is refused.
  • A control waiting longer than 500 ms shows a spinner on itself, and nothing else looks busy.
  • The URL lives only in the panel's memory. It is cleared on close, never logged or stored, and reaches the pasteboard only through Copy link.

Mac popover (DocsSharePopover): an NSPopover of its own, because SwiftUI's .popover cannot be made non-transient.

  • It hangs under Share…, 420 pt wide, arrow at the top. When Share… is in the toolbar's » menu, it hangs under the toolbar at the trailing edge.
  • It is transient, except while the URL shows (.applicationDefined).
  • A click on Share… while it is open is not taken as an outside click.
  • Esc and Close always close it, URL or not, and give the keyboard back to Share….
  • It replaces DocsSharingView, which is deleted. File ▸ Share… opens the same popover.

iPhone: the same panel as a sheet with .medium and .large detents. Swipe-to-dismiss is off while the URL shows. Focus goes to the email field, or to the head under VoiceOver.

Offline: Share…, Delete…, File ▸ Export and Print are disabled while the origin is offline. Share… carries native.share.offline as its help tag, and Export carries native.export.offline.

Delete… (DocsDeletion, DocsModel.deleteDocument):

  • Who: owners only (can_share). Never a draft, and not once the document is no longer available.
  • Where: File ▸ Delete… on the Mac. On iPhone, a toolbar button until S3 moves it into •••.
  • Unsent changes: it sends what is waiting first, then refuses if anything is still unsent (native.delete.unsent).
  • Confirmation: the web's words (docs.delete.*).
  • The answer: only {"ok":true}, or a 404 from the client's own GET of /d/{sqid}, counts as deleted. An older server's 303 and a POST 404 are both checked that way.
  • Only on deleted: the outbox lane, replica and metadata are dropped. Typing is paused while the request is out.
  • After a delete: the window closes (Mac) or the library shows (iPhone). Every list of that origin removes the document and reloads (a notification). File ▸ Recent forgets it.
  • Thumbnails: there is no native thumbnail cache; thumbnails come with the list, so the reload covers them.
  • Failure: native.delete.failed.

Acceptance evidence

  • Delete client (DocsDeletionTests): - JSON ok; - 303 then 404 (deleted); - 303 then 200 (not deleted); - POST 404 then GET 404 (deleted); - POST 404 then GET 200 (not deleted: lane, replica and metadata kept, document still open and editable); - plus a lost answer, offline, 503/503 and non-ok 2xx; - refused with unsent changes; no Delete… for a draft.
  • Popover (SharePopoverTests, a hosted window driven by real clicks and keys posted to the app's queue): - Share… opens it under the button, 420 pt wide, with the email field holding the keyboard. - Share… while open is a no-op: a second click leaves the same popover open, with no second load. - The once-only URL survives an outside click: without the URL a click outside closes it; with it the popover is .applicationDefined and the same click leaves it and the URL. After Close the URL is gone, and a new panel never shows it. - Esc returns the keyboard to Share…: Return there opens it again. Esc also closes it while the URL shows.
  • Model (DocsSharePanelModelTests): - a switch holds, then reverts; - a switch settles to the server's state; - the URL shows once and is gone after close; - a second submit is refused; - a spinner appears only after the delay; - the server's refusal is the callout; - every key resolves in all twelve tables with its placeholders.
  • Mutation-checked (each broke its test, then restored): - a POST 404 taken as deleted; - lane dropped on any outcome; - no hold; - URL kept after close; - no single flight (it is enforced twice, by the callers' isBusy and by run; the test fails with both removed); - spinner at once; - popover always transient; - no Esc handling.
  • Snapshots (docs-window, Mac): share-popover, share-popover-once, share-popover-ar and share-popover-ru, each light and dark. The existing 22 baselines are byte-identical.
  • Recent: aDeletedDocumentLeavesRecentAndGoesWithItsWindow.
  • Gates run locally: all on 8614d80, on macOS 27.0 / Xcode 27.2: - Swift suite: whole swift test. DocsKitTests ran 272 with 0 failures; the 14 skips are the env-gated probes. DocsWindowTests all passed. This includes WorkspaceInitTests, SignedInLaunchTests, OfflineDurabilityTests and OficinaIDAdoptionTests. - Snapshots: snapshots.sh compare all passed. The Mac half had 22 + 24 + 30 images, and the iPhone half 32 + 20 + 4 (which also builds the iOS code). Baselines were drawn on the same environment. - Python gates: test-home-loading.py, test-sync-latency.py, test-document-window.py and test-offline-kill.py all passed. - Go: the delete, guest, file-menu and suite tests passed locally; the full Go suite is hub CI's. - Not run locally: check-native.sh's cargo half (the hub runs --core-only). No §7 counter or timing work is in this slice; the render-isolation tests are in the suite above.

Found and fixed on the way

  • Keyboard opening: opened from the keyboard (Return on Share…, File ▸ Share…), an NSPopover is not made key, so its email field could not take the keyboard. It is now made key on show.
  • Esc with the URL showing: a non-transient popover does not close itself on Esc, and SwiftUI's .cancelAction shortcut does not reach it either. A key monitor handles Esc while the popover is shown.
  • Russian: the invite row squeezed the placeholder to "Добавьте л". The row now puts the field on a line of its own when its placeholder does not fit (DocsInviteLayout), as §9 asks for long languages.
  • Mac switches: AppKit's switch greys its "on" state in a window that is not key, which reads as off, so the Mac draws the web panel's switch instead (DocsSwitchStyle). It is still a Toggle for VoiceOver.

Deviations, and what the tests cannot see

  • Focus back to Share…: it goes to Share…'s anchor view, not the SwiftUI toolbar button. SwiftUI's toolbar button cannot be given the keyboard from AppKit, and with Full Keyboard Access off it takes none. The anchor sits exactly over the pill and draws the focus ring round it. Space and Return there press Share…. It is not in the Tab loop; the button keeps its own place.
  • The Share…-click exemption in popoverShouldClose is not seen by the test. The test process is never the active app, and there a click on Share… does not reach the delegate. Share… while open is still a no-op in the test, through the two isShown guards. Physical-Mac pass item.
  • "(you)": it shows the account's identity label when the app has one (Oficina ID); a server account shows "(you)" alone, as the web does for an addressless principal. No server change was made for it.
  • Delete… on iPhone: for S2b it sits in the toolbar beside Share; S3 moves both into •••.

Strings (drafted; copy review follows on #171)

36 keys, all twelve catalogues:

  • docs.share.panel.* (23, the web's English);
  • docs.share.team.heading, docs.share.public.url, .copy, .copied;
  • docs.editor.menu.file.delete, docs.delete.heading, .body, .confirm, .cancel;
  • native.share.offline, native.export.offline, native.delete.unsent;
  • native.delete.failed, new: "This document could not be deleted. Check your connection and try again."

Deploy order

The server commit must be deployed to prod and lagged (curl /api/version) before a client release. An undeployed server is still safe: its 303 is checked with a GET.

LLM

S2b built: native delete JSON on the server (land and deploy first), the Share panel as a Mac popover and iPhone sheet, Delete… with the version-skew rule. All local gates green; strings drafted.

Hub CI passed on 8614d80. Stopping here for review; nothing is merged or deployed.

Review by Claude Fable (model id claude-fable-5-2) of 8614d80 — verdict: APPROVE AFTER FIXES. The server half (2ee258c) has no findings: authorization and the delete are the browser's code path; only the answer changed. Same session, admission and CSRF; Unknown → 503 rolled back; non-owners 404.

Client:

  1. Medium DocsModel.swift:971-981: deleteDocument() awaits the network, then discardAll() acts on whatever document is open now. Delete A on a slow link, go back, open B: A's .deleted answer drops B's replica, metadata and outbox lane, including unsent edits. Capture the sqid/epoch before the await and drop only A's state by key if the open document changed (or block open()/newDraft() while deleting). Test: delete A, open B mid-request, B's lane survives.
  2. Medium, unverified DocsWorkspace.swift:351, DocsDocumentHeader.swift:271: performClose likely does nothing while the confirmation sheet is still attached, so a fast delete could leave an empty window. Check against a fast server; if real, wait for attachedSheet == nil or call close().
  3. Low-Medium DocsSharePopover.swift:52-59, 80-98: a late popoverDidClose from an old popover can tear down a newer one (Esc then Return during the close animation). Guard on notification.object === popover.
  4. Low Esc monitor: remove it in deinit as well; don't swallow Esc while the field editor hasMarkedText() (ja, zh-Hans, yue IME).
  5. Low DocsDeletion.swift:39: a GET 404 is always read as deleted (edge during deploy, lost membership). No data loss; a comment is enough.

The review's fixes, one commit each, on native/share-and-delete (tip a16328c). The server half (2ee258c) is unchanged.

1 (required), cb077b9: deleteDocument() now takes A's sqid, key and persistence before the request.

  • A still open when the answer comes: it is discarded as before.
  • Another document open: only A's lane, replica and metadata are dropped by key, through A's own DocsPersistence.discard() and removeMetadata. The model and B are left alone.
  • The result: it now says wasOpen. The window closes (Mac), or the iPhone goes back to the library, only when it is true. The lists and File ▸ Recent forget A either way.
  • The input hold during the request is tied to A's epoch, so B is not held by it.
  • Test: DocsDeletionTests.testADeleteAnsweredAfterAnotherDocumentOpenedDropsOnlyItsOwn. It deletes A with the POST held at the server, opens B, and types in B (B's update POSTs answer 503, so the change stays in B's lane). Then it releases A's answer. B's replica, metadata and unsent lane survive, the model stays on B, and A's replica, metadata and lane are gone. With the old unconditional discardAll() it fails on every one of those checks.

2 (check), 2463114: real, reproduced. The hosted test puts up a SwiftUI .confirmationDialog whose Delete button calls DocsWindowCloser.close() at once, the fastest a local server can answer. The window was still open 5 s later: performClose on a window whose sheet is still attached beeps and does nothing.

  • Fix: DocsWindowCloser.close() waits for attachedSheet == nil (polled every 20 ms, at most 2 s), then calls performClose as before, so DocsCloseGuard still decides. The "No longer available" callout's Close goes through the same closer and gets the same fix.
  • Test: DocsWindowCloserTests.testCloseFromAConfirmationDialogClosesTheWindow. It failed before the fix and passes after; the two existing closer tests still pass.

3, 4b3cc3f: popoverDidClose now acts only when notification.object is the popover showing now.

  • Test: SharePopoverTests.testAnOldPopoversLateCloseLeavesTheNewOneAlone opens, closes, then opens again, and delivers the first popover's didClose late. The new popover and its panel stay. It fails without the guard.

4, 52e9826: Esc while the field editor has marked text is left to the input method, both in the key monitor and in popoverShouldClose (the transient path). The monitor is also removed in an isolated deinit.

  • Test: SharePopoverTests.testEscDuringAnIMECompositionLeavesThePanelOpen. With marked text "か", Esc leaves the panel open. Unmarked, Esc closes it. It fails with the composition check removed.
  • deinit: the removal has no test. The controller lives as long as its window's workspace.

5, a16328c: a comment on the GET 404. It can also come from a server mid-deploy or after lost membership. Acting on it is safe: Delete… is refused with anything unsent, so the dropped lane is empty; the replica and metadata are a cache; and a document that still exists comes back with the next list reload and downloads afresh on open.

Gates: the whole swift test on a16328c passed: DocsKitTests 273 with 0 failures (14 env-gated skips), and all DocsWindowTests. No view changed in these commits, so the snapshot gate was not re-run; it passed on 8614d80. Hub CI passed on a16328c.