#if os(iOS) import RastrilloApple import SwiftUI /// What the iPhone document's ••• menu and controls ask of the window. struct DocsPhoneActions { var share: () -> Void = {} var rename: () -> Void = {} var export: (String) -> Void = { _ in } var wordCount: () -> Void = {} var openDocument: () -> Void = {} var shortcuts: () -> Void = {} var colophon: () -> Void = {} var delete: () -> Void = {} var format: () -> Void = {} } /// The bar's trailing controls (spec §3): the undo/redo pill, Aa and ••• /// for a writer; ••• alone for a reader. No Share pill (Paul's ruling 4): /// Share lives in •••. While the title is folded into the bar, undo and /// redo move to the top of ••• so the title has the room (the /// coordinator's ruling on #180). Their own view, reading the access, the /// history, the connectivity and the fold, so the text view's host reads /// none of them. @MainActor struct DocsPhoneDocumentControls: View { let model: DocsModel let origin: URL @Binding var paged: Bool let header: DocumentHeaderState let actions: DocsPhoneActions var body: some View { let folded = header.collapsed HStack(spacing: DocsSpacing.sp2) { if model.documentAccess == .writable { if !folded { DocsPhoneUndoRedoPill(model: model) } Button(action: actions.format) { Text(verbatim: "Aa").font(.body.weight(.semibold)).frame(minWidth: 44, minHeight: 44) } .accessibilityLabel(Text("docs.editor.inspector.toggle", bundle: DocsResources.bundle)) .accessibilityIdentifier("docs.format.toggle") } DocsPhoneMoreMenu(model: model, origin: origin, paged: $paged, actions: actions, history: folded) } } } /// Undo and redo in one pill, each enabled from the history. @MainActor struct DocsPhoneUndoRedoPill: View { let model: DocsModel var body: some View { let history = model.history HStack(spacing: 0) { button("docs.editor.toolbar.undo", icon: "arrow.uturn.backward", op: "undo", enabled: history.canUndo) Rectangle().fill(OficinaPalette.line).frame(width: 1, height: 20) button("docs.editor.toolbar.redo", icon: "arrow.uturn.forward", op: "redo", enabled: history.canRedo) } .accessibilityElement(children: .contain) .accessibilityLabel(Text("docs.editor.toolbar.history", bundle: DocsResources.bundle)) } private func button(_ key: String, icon: String, op: String, enabled: Bool) -> some View { Button { DocumentCommands(model: model, content: model.surface.content).perform(op) } label: { Image(systemName: icon).font(.body.weight(.semibold)) .flipsForRightToLeftLayoutDirection(true) .frame(minWidth: 44, minHeight: 44) } .disabled(!enabled) .accessibilityLabel(Text(LocalizedStringKey(key), bundle: DocsResources.bundle)) .accessibilityIdentifier("docs." + op) } } /// ••• (spec §3): the web's File, View, Tools and Help, in that order. What /// a capability forbids is absent, not disabled; what needs the server waits /// while the origin is offline (disabled, as the Mac's menus are). @MainActor struct DocsPhoneMoreMenu: View { let model: DocsModel let origin: URL @Binding var paged: Bool let actions: DocsPhoneActions /// Undo and Redo at the top (the title folded into the bar). var history = false var body: some View { let offline = model.connectivity.isOffline(origin) let owner = model.detail?.can_share == true && !model.isDraft && model.documentAccess != .unavailable let writer = model.documentAccess == .writable let saved = model.detail != nil && !model.isDraft Menu { if history && writer { Section { Button { DocumentCommands(model: model, content: model.surface.content).perform("undo") } label: { Label { Text("docs.editor.toolbar.undo", bundle: DocsResources.bundle) } icon: { Image(systemName: "arrow.uturn.backward") } } .disabled(!model.history.canUndo) Button { DocumentCommands(model: model, content: model.surface.content).perform("redo") } label: { Label { Text("docs.editor.toolbar.redo", bundle: DocsResources.bundle) } icon: { Image(systemName: "arrow.uturn.forward") } } .disabled(!model.history.canRedo) } } Section { if owner { Button(action: actions.share) { Label { Text("docs.share.action", bundle: DocsResources.bundle) } icon: { Image(systemName: "person.crop.circle.badge.plus") } } .disabled(offline) } if writer { Button(action: actions.rename) { Label { Text("docs.document.rename", bundle: DocsResources.bundle) } icon: { Image(systemName: "pencil") } } } } Section { if saved { Menu { Button { actions.export("pdf") } label: { Text("docs.export.pdf.label", bundle: DocsResources.bundle) } Button { actions.export("markdown") } label: { Text("docs.export.markdown.label", bundle: DocsResources.bundle) } Button { actions.export("print") } label: { Text("docs.editor.menu.file.print", bundle: DocsResources.bundle) } } label: { Label { Text("native.export", bundle: DocsResources.bundle) } icon: { Image(systemName: "square.and.arrow.up") } } .disabled(offline) } Button(action: actions.wordCount) { Label { Text("docs.editor.menu.tools.wordcount", bundle: DocsResources.bundle) } icon: { Image(systemName: "number") } } .disabled(!model.showsDocument) Button(action: actions.openDocument) { Label { Text("docs.editor.menu.file.open", bundle: DocsResources.bundle) } icon: { Image(systemName: "doc.text.magnifyingglass") } } Picker(selection: $paged) { Text("docs.editor.menu.view.paged", bundle: DocsResources.bundle).tag(true) Text("docs.editor.menu.view.infinite", bundle: DocsResources.bundle).tag(false) } label: { EmptyView() } .pickerStyle(.inline) } Section { Menu { Button(action: actions.shortcuts) { Text("docs.editor.menu.tools.shortcuts", bundle: DocsResources.bundle) } Button(action: actions.colophon) { Text(verbatim: DocsColophonView.title) } } label: { Label { Text("docs.editor.menu.help", bundle: DocsResources.bundle) } icon: { Image(systemName: "questionmark.circle") } } if owner { Button(role: .destructive, action: actions.delete) { Label { Text("docs.editor.menu.file.delete", bundle: DocsResources.bundle) } icon: { Image(systemName: "trash") } } .disabled(offline) } } } label: { Image(systemName: "ellipsis").font(.body.weight(.semibold)).frame(minWidth: 44, minHeight: 44) } .accessibilityLabel(Text("native.more", bundle: DocsResources.bundle)) .accessibilityIdentifier("docs.more") } } /// The iPhone's callouts under the bar (spec §6, banners): the session /// ended (rows 5 and 6), No longer available (row 1) with Back, and today's /// `errorKey` text with Try again. Their own view. @MainActor struct DocsPhoneCallouts: View { let model: DocsModel @Environment(\.locale) private var locale let discard: () -> Void let back: () -> Void var signIn: () -> Void = {} var body: some View { VStack(spacing: DocsSpacing.sp2) { if model.documentAccess != .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.documentAccess == .unavailable { callout(Text("native.unavailable.body", bundle: DocsResources.bundle), negative: true) { Button(action: back) { Text("native.back", bundle: DocsResources.bundle) } if model.hasUnsavedChanges { Button(role: .destructive) { discard() } label: { Text("native.discard.action", bundle: DocsResources.bundle) } } } } else if let key = model.errorKey { callout(Text(LocalizedStringKey(key), bundle: DocsResources.bundle), negative: false) { Button { Task { await model.retry() } } label: { Text("native.retry", bundle: DocsResources.bundle) } if model.hasUnsavedChanges { Button(role: .destructive) { discard() } label: { Text("native.discard.action", bundle: DocsResources.bundle) } } } } } .padding(.horizontal, DocsSpacing.sp3) } private func callout(_ text: Text, negative: Bool, @ViewBuilder actions: () -> Actions) -> some View { VStack(alignment: .leading, spacing: DocsSpacing.sp2) { text.font(.callout).foregroundStyle(negative ? OficinaPalette.negative : OficinaPalette.text) .fixedSize(horizontal: false, vertical: true) HStack(spacing: DocsSpacing.sp3) { actions() }.font(.callout.weight(.semibold)) } .frame(maxWidth: .infinity, alignment: .leading) .padding(DocsSpacing.sp3) .background(RoundedRectangle(cornerRadius: 12).fill(negative ? OficinaPalette.negativeSoft : OficinaPalette.surface)) .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(OficinaPalette.line, lineWidth: 1)) .accessibilityElement(children: .contain) .accessibilityIdentifier(negative ? "docs.callout.negative" : "docs.callout.error") } } #endif