Docs native S2a: the sign-in callout, style pop-up at 13pt, and the window snapshot screens
- §6 rows 5 and 6 raise a callout under the header with the kit's Sign in, which opens the home window's account flow. - The inspector's style pop-up draws Body text and Headings 1–3 at 13pt (headings bold), as the mock-up, rather than at their page sizes. - DocsWindowSnapshots (docs-window catalog): the header as the toolbar lays it out, the real page, desk and floating inspector; writer with Format open, closed and at 1000pt (the page under the inspector), reader, no longer available, ar and ru; every subtitle row in en, ar and ru.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+188
−9
native/apple/Sources/DocsKit/DocsDocumentHeader.swift+13 −1native/apple/Sources/DocsKit/DocsFormatInspector.swift+1 −1native/apple/Sources/DocsKit/DocsWorkspace.swift+1 −1native/apple/Tests/DocsSnapshots/EditorSnapshots.swift+32 −6native/apple/Tests/DocsSnapshots/WindowSnapshots.swift+141 −0
diff --git a/native/apple/Sources/DocsKit/DocsDocumentHeader.swift b/native/apple/Sources/DocsKit/DocsDocumentHeader.swift| index ffd0386..794816d 100644 |
| --- a/native/apple/Sources/DocsKit/DocsDocumentHeader.swift |
| +++ b/native/apple/Sources/DocsKit/DocsDocumentHeader.swift |
| @@ -1,6 +1,7 @@ |
| #if os(macOS) |
| import AppKit |
| import RastrilloApple |
| +import RastrilloNative |
| import SwiftUI |
| /// The app-wide Format inspector state (spec D1): open by default, one value |
| @@ -182,10 +183,21 @@ struct DocsPillStyle: ButtonStyle { |
| /// view, so the text view's host does not read either. |
| @MainActor struct DocsDocumentCallouts: View { |
| let model: DocsModel |
| + @Environment(\.locale) private var locale |
| let discard: () -> Void |
| let close: () -> Void |
| + /// The account flow, as Settings' Sign in… opens it (the home window). |
| + var signIn: () -> Void = {} |
| var body: some View { |
| VStack(spacing: 8) { |
| + // §6 rows 5 and 6: the session ended. Typing still reaches the |
| + // outbox; signing in sends it. |
| + if model.access != .unavailable, case .needsSignIn(let pending) = model.syncStatus { |
| + let sync = NativeSyncStrings.kit |
| + callout(Text(verbatim: pending > 0 ? sync.needsSignIn(pending) : DocsStrings(locale: locale)("native.subtitle.signedOut")), negative: true) { |
| + Button { signIn() } label: { Text(verbatim: sync.signIn) } |
| + } |
| + } |
| if model.access == .unavailable { |
| callout(Text("native.unavailable.body", bundle: DocsResources.bundle), negative: true) { |
| Button { close() } label: { Text("native.close", bundle: DocsResources.bundle) } |
| @@ -217,7 +229,7 @@ struct DocsPillStyle: ButtonStyle { |
| .overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(OficinaPalette.line, lineWidth: 1)) |
| .shadow(color: .black.opacity(0.08), radius: 8, y: 3) |
| .accessibilityElement(children: .contain) |
| - .accessibilityIdentifier(negative ? "docs.callout.unavailable" : "docs.callout.error") |
| + .accessibilityIdentifier(negative ? "docs.callout.negative" : "docs.callout.error") |
| } |
| } |
| #endif |
diff --git a/native/apple/Sources/DocsKit/DocsFormatInspector.swift b/native/apple/Sources/DocsKit/DocsFormatInspector.swift| index d3aa0d3..731f0f8 100644 |
| --- a/native/apple/Sources/DocsKit/DocsFormatInspector.swift |
| +++ b/native/apple/Sources/DocsKit/DocsFormatInspector.swift |
| @@ -118,7 +118,7 @@ import SwiftUI |
| font: DocsFonts.font(marks: [:], size: 13, heading: false))] |
| for level in 1...3 { |
| entries.append(.init(id: "heading" + String(level), title: strings(EditorToolbar.headingKey(level)), |
| - font: DocsFonts.font(marks: [:], size: [18, 16, 14][level - 1], heading: true))) |
| + font: DocsFonts.font(marks: [:], size: 13, heading: true))) |
| } |
| return DocsPopUp(entries: entries, selected: selection.style, label: strings("docs.editor.toolbar.block"), identifier: "docs.style-picker") { style in |
| if style.hasPrefix("heading"), let level = Int(style.dropFirst("heading".count)) { actions.block("heading", level: level) } |
diff --git a/native/apple/Sources/DocsKit/DocsWorkspace.swift b/native/apple/Sources/DocsKit/DocsWorkspace.swift| index 3b5a3cd..c10120f 100644 |
| --- a/native/apple/Sources/DocsKit/DocsWorkspace.swift |
| +++ b/native/apple/Sources/DocsKit/DocsWorkspace.swift |
| @@ -306,7 +306,7 @@ import SwiftUI |
| // One title (spec §1): the window's title stays the document's, |
| // for the Window menu, tabs and VoiceOver, but the system does |
| // not draw it; Docs' title area does, with the subtitle. |
| - .overlay(alignment: .top) { DocsDocumentCallouts(model: model, discard: { discarding = true }, close: { dismissWindow() }) } |
| + .overlay(alignment: .top) { DocsDocumentCallouts(model: model, discard: { discarding = true }, close: { dismissWindow() }, signIn: { openWindow(id: "home") }) } |
| .toolbar(removing: .title) |
| .toolbar { |
| ToolbarItem(placement: .navigation) { |
diff --git a/native/apple/Tests/DocsSnapshots/EditorSnapshots.swift b/native/apple/Tests/DocsSnapshots/EditorSnapshots.swift| index b569628..6173643 100644 |
| --- a/native/apple/Tests/DocsSnapshots/EditorSnapshots.swift |
| +++ b/native/apple/Tests/DocsSnapshots/EditorSnapshots.swift |
| @@ -145,6 +145,9 @@ enum EditorScript: Sendable { |
| let zoom: Double |
| let scroll: CGFloat |
| let script: EditorScript |
| + /// The S2a window chrome around the page (WindowSnapshots.swift), nil |
| + /// for the page alone. |
| + var chrome: WindowChrome? = nil |
| @State private var model: DocsModel? |
| @State private var server: EditorServer? |
| @State private var images = DocsImageStore() |
| @@ -165,8 +168,20 @@ enum EditorScript: Sendable { |
| var body: some View { |
| ZStack(alignment: .topLeading) { |
| if let model, let server { |
| + #if os(macOS) |
| + if let chrome { |
| + WindowChromeView(chrome: chrome, model: model) { |
| + EditorPage(model: model, images: images, client: server, paged: paged, zoom: zoom, inspector: chrome.inspectorSide) |
| + .background { ProbeView(probe: probe) } |
| + } |
| + } else { |
| + EditorPage(model: model, images: images, client: server, paged: paged, zoom: zoom) |
| + .background { ProbeView(probe: probe) } |
| + } |
| + #else |
| EditorPage(model: model, images: images, client: server, paged: paged, zoom: zoom) |
| .background { ProbeView(probe: probe) } |
| + #endif |
| } |
| if !ready { OpeningCounter() } |
| } |
| @@ -177,6 +192,7 @@ enum EditorScript: Sendable { |
| private func open() async { |
| do { |
| let server = EditorServer() |
| + if let chrome, chrome.reader { await server.readOnly() } |
| try await server.seed(fixture.blocks) |
| let connectivity = NativeConnectivity(source: ScriptedPathSource(.satisfied)) |
| let account = DocsOfflineAccount(store: EphemeralDocsStore(), accountID: UUID().uuidString, |
| @@ -192,6 +208,8 @@ enum EditorScript: Sendable { |
| try await until("the first render") { model.renderedGeneration == model.projectionGeneration && probe.textView != nil } |
| if case .typeBeforeBreakThenPeer = script { try await typeBeforeBreakThenPeer(model, server, account) } |
| try await settle(model, account) |
| + // A document deleted or unshared while open (spec §6 row 1). |
| + if chrome?.unavailable == true { model.unavailable = true; model.inputPaused = true } |
| try await layOut() |
| await Task.yield() |
| ready = true |
| @@ -265,9 +283,10 @@ enum EditorScript: Sendable { |
| // ones: pinned, like the kit pins the accent, so the picture does |
| // not depend on what is plugged in. |
| scrollView.scrollerStyle = .overlay |
| - try await until("the scroll view is \(self.window)") { |
| + let expected = CGSize(width: self.window.width, height: self.window.height - (chrome == nil ? 0 : WindowChrome.headerHeight)) |
| + try await until("the scroll view is \(expected)") { |
| window.contentView?.layoutSubtreeIfNeeded() |
| - return scrollView.frame.size == self.window |
| + return scrollView.frame.size == expected |
| } |
| text.needsLayout = true |
| text.layoutSubtreeIfNeeded() |
| @@ -324,17 +343,18 @@ struct EditorScreenFailure: Error, CustomStringConvertible { |
| /// The page as `DocsWorkspace.editor` draws it: the projection rendered with |
| /// its images, in `NativeDocumentTextView`, wired to the model. |
| -@MainActor private struct EditorPage: View { |
| +@MainActor struct EditorPage: View { |
| /// Held as `DocsWorkspace` holds it, in `@State`. |
| @State private var model: DocsModel |
| let images: DocsImageStore |
| let client: NativeTransport |
| let paged: Bool |
| let zoom: Double |
| + var inspector: DocsDeskLayout.Side? = nil |
| - init(model: DocsModel, images: DocsImageStore, client: NativeTransport, paged: Bool, zoom: Double) { |
| + init(model: DocsModel, images: DocsImageStore, client: NativeTransport, paged: Bool, zoom: Double, inspector: DocsDeskLayout.Side? = nil) { |
| _model = State(initialValue: model) |
| - self.images = images; self.client = client; self.paged = paged; self.zoom = zoom |
| + self.images = images; self.client = client; self.paged = paged; self.zoom = zoom; self.inspector = inspector |
| } |
| var body: some View { |
| @@ -353,6 +373,9 @@ struct EditorScreenFailure: Error, CustomStringConvertible { |
| && (action == "undo" ? projection.canUndo : projection.canRedo) |
| }, |
| explicitCommandRevision: model.explicitCommandRevision, zoom: zoom, typingMarks: model.typingMarks) |
| + #if os(macOS) |
| + .inspectorSide(inspector) |
| + #endif |
| .id(model.editorIdentity) |
| } |
| } |
| @@ -404,6 +427,9 @@ private struct ProbeView: UIViewRepresentable { |
| actor EditorServer: NativeTransport { |
| nonisolated let origin = URL(string: "https://docs.snapshot.invalid")! |
| private let replica = CRDTReplica(guid: "editor-snapshots") |
| + private var canWrite = true |
| + /// The detail answers can_write false: a reader's window. |
| + func readOnly() { canWrite = false } |
| private var sequence: Int64 = 0 |
| private var rows: [Int64: Data] = [:] |
| private var listeners: [UUID: AsyncStream<Int64>.Continuation] = [:] |
| @@ -450,7 +476,7 @@ actor EditorServer: NativeTransport { |
| let highest = sequence |
| return NativeResponse(data: try await replica.persistentState().state, status: 200, headers: ["Docs-Seq": String(highest)]) |
| } |
| - let detail = DocumentDetail(sqid: "doc", title: "A History of the Millbrook Waterworks", guid: "editor-snapshots", can_write: true, can_share: false) |
| + let detail = DocumentDetail(sqid: "doc", title: "A History of the Millbrook Waterworks", guid: "editor-snapshots", can_write: canWrite, can_share: canWrite) |
| return NativeResponse(data: try JSONEncoder().encode(detail), status: 200, headers: [:]) |
| } |
diff --git a/native/apple/Tests/DocsSnapshots/WindowSnapshots.swift b/native/apple/Tests/DocsSnapshots/WindowSnapshots.swift| new file mode 100644 |
| index 0000000..094b3c7 |
| --- /dev/null |
| +++ b/native/apple/Tests/DocsSnapshots/WindowSnapshots.swift |
| @@ -0,0 +1,141 @@ |
| +import Foundation |
| +import RastrilloApple |
| +import RastrilloSnapshots |
| +import SwiftUI |
| +import XCTest |
| +@testable import DocsKit |
| + |
| +/// What the window around the page shows. |
| +struct WindowChrome: Sendable { |
| + static let headerHeight: CGFloat = 52 |
| + var inspector: Bool |
| + var reader = false |
| + var unavailable = false |
| + /// The interface language, nil for English. |
| + var language: String? = nil |
| + var rightToLeft: Bool { language == "ar" } |
| + /// The side the inspector covers when it shows (writers only). |
| + var inspectorSide: DocsDeskLayout.Side? { inspector && !reader && !unavailable ? (rightToLeft ? .left : .right) : nil } |
| +} |
| + |
| +#if os(macOS) |
| + |
| +/// The S2a document window (spec §1, §6, §11): the header Docs draws in the |
| +/// toolbar (the title area with its subtitle, undo/redo, Format, Share…), |
| +/// the floating Format inspector over the desk and the page placed by the |
| +/// centring rule, for a writer with the inspector open and closed, a |
| +/// reader, a document no longer available, in Arabic and Russian; and every |
| +/// subtitle row. |
| +/// |
| +/// The kit draws a borderless window, which has no toolbar, so the header |
| +/// here is the same views laid out as the toolbar lays them out: the title |
| +/// area at the leading edge after the window buttons' space, the controls |
| +/// at the trailing edge, 8pt apart. The page, the desk and the inspector |
| +/// are the real ones. |
| +final class DocsWindowSnapshots: XCTestCase { |
| + @MainActor func testWindowScreens() async throws { |
| + try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, |
| + "Run with native/scripts/snapshots.sh") |
| + DocsFonts.register() |
| + let settings = SnapshotSettings(tint: OficinaPalette.accent(.docs)) |
| + await assertSnapshots(of: SnapshotCatalog(app: "docs-window", variants: [.init(.light, .standard), .init(.dark, .standard)], |
| + settings: settings, screens: Self.screens)) |
| + await EditorScreen.stopAll() |
| + } |
| + |
| + /// 1280 wide: the inspector open puts the page at 188pt, clear of it. |
| + static let size = SnapshotSize.fixed(width: 1280, height: 760) |
| + /// 1000 wide: the page runs under the inspector (the cost of option B). |
| + static let narrow = SnapshotSize.fixed(width: 1000, height: 640) |
| + |
| + @MainActor static var screens: [SnapshotScreen] { |
| + [ |
| + window("window-format-open", .init(inspector: true)), |
| + window("window-format-closed", .init(inspector: false)), |
| + window("window-format-open-narrow", .init(inspector: true), size: narrow), |
| + window("window-reader", .init(inspector: true, reader: true)), |
| + window("window-unavailable", .init(inspector: true, unavailable: true)), |
| + window("window-format-open-ar", .init(inspector: true, language: "ar"), fixture: .arabic), |
| + window("window-format-open-ru", .init(inspector: true, language: "ru"), fixture: .russian), |
| + SnapshotScreen("subtitles", mac: .width(420), iphone: nil) { SubtitleRows(language: "en") }, |
| + SnapshotScreen("subtitles-ar", mac: .width(420), iphone: nil) { SubtitleRows(language: "ar") }, |
| + SnapshotScreen("subtitles-ru", mac: .width(420), iphone: nil) { SubtitleRows(language: "ru") }, |
| + ] |
| + } |
| + |
| + @MainActor static func window(_ name: String, _ chrome: WindowChrome, size: SnapshotSize = size, fixture: EditorFixture = .millbrook) -> SnapshotScreen { |
| + var frame = CGSize.zero |
| + if case .fixed(let width, let height) = size { frame = CGSize(width: width, height: height) } |
| + return SnapshotScreen(name, mac: size, iphone: nil) { [frame] in |
| + var screen = EditorScreen(fixture, window: frame, paged: true) |
| + screen.chrome = chrome |
| + return screen |
| + } |
| + } |
| +} |
| + |
| +/// The header strip and the desk, the way `DocsWorkspace.editor` puts them |
| +/// in a window: the title area, the controls, the page, the floating |
| +/// inspector and the callout. |
| +@MainActor struct WindowChromeView<Page: View>: View { |
| + static var headerHeight: CGFloat { WindowChrome.headerHeight } |
| + let chrome: WindowChrome |
| + let model: DocsModel |
| + @ViewBuilder let page: Page |
| + @State private var renaming = false |
| + @State private var open = true |
| + |
| + var body: some View { |
| + VStack(spacing: 0) { |
| + HStack(spacing: 8) { |
| + // Where the window's close, minimise and zoom buttons sit. |
| + Color.clear.frame(width: 78) |
| + DocsTitleArea(model: model, team: "Tito", renaming: $renaming, beginRename: {}, finishRename: {}) |
| + Spacer(minLength: 24) |
| + DocsHeaderControls(model: model, inspectorOpen: $open, part: .history, share: {}) |
| + DocsHeaderControls(model: model, inspectorOpen: $open, part: .format, share: {}) |
| + DocsHeaderControls(model: model, inspectorOpen: $open, part: .share, share: {}) |
| + } |
| + .padding(.trailing, 16) |
| + .frame(height: Self.headerHeight) |
| + .background(Color(nsColor: .windowBackgroundColor)) |
| + .overlay(alignment: .bottom) { Rectangle().fill(OficinaPalette.line).frame(height: 1) } |
| + page |
| + .overlay(alignment: .topTrailing) { |
| + if chrome.inspectorSide != nil, let projection = model.projection { |
| + DocsFormatInspector(model: model, content: NativeTextProjection.render(projection)) |
| + .padding(.top, DocsDeskLayout.inspectorInset) |
| + .padding(.trailing, DocsDeskLayout.inspectorInset) |
| + } |
| + } |
| + .overlay(alignment: .top) { DocsDocumentCallouts(model: model, discard: {}, close: {}) } |
| + } |
| + .onAppear { open = chrome.inspector } |
| + .environment(\.locale, Locale(identifier: chrome.language ?? "en")) |
| + .environment(\.layoutDirection, chrome.rightToLeft ? .rightToLeft : .leftToRight) |
| + } |
| +} |
| + |
| +/// Every §6 subtitle row under one title, in one language. |
| +@MainActor struct SubtitleRows: View { |
| + let language: String |
| + static let rows: [DocsSubtitleRow] = [.unavailable, .failedHeld, .cannotSaveOnDevice, .tooManyUnsent, .needsSignIn(pending: 3), .signedOut, |
| + .offline(pending: 2), .retrying(pending: 1), .saving, .viewOnly, .saved, .loading] |
| + var body: some View { |
| + let strings = DocsStrings(locale: Locale(identifier: language)) |
| + VStack(alignment: .leading, spacing: 10) { |
| + ForEach(Array(Self.rows.enumerated()), id: \.offset) { index, row in |
| + VStack(alignment: .leading, spacing: 1) { |
| + Text(verbatim: "A History of the Millbrook Waterworks") |
| + .font(.system(size: 15, weight: .semibold)).foregroundStyle(OficinaPalette.text).lineLimit(1) |
| + DocsSubtitleLine(row: row, team: "Tito", strings: strings) |
| + } |
| + } |
| + } |
| + .padding(16) |
| + .frame(maxWidth: .infinity, alignment: .leading) |
| + .environment(\.locale, Locale(identifier: language)) |
| + .environment(\.layoutDirection, language == "ar" ? .rightToLeft : .leftToRight) |
| + } |
| +} |
| +#endif |