oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1import SwiftUI
2
3// Draft observation stays in these small views, away from the grid hierarchy.
4struct SheetFormulaBar: View {
5 @Bindable var model: SheetModel
6 var formulaFocused: FocusState<Bool>.Binding
7 var body: some View {
8 HStack {
9 TextField("Cell or range", text: $model.rangeText).frame(width: 110).onSubmit {
10 model.selectRange()
11 }.accessibilityLabel("Cell or range, for example A1:B5")
12 Text("fx").foregroundStyle(.secondary)
13 TextField("Cell contents or formula", text: $model.draft).focused(formulaFocused).disabled(
14 !model.mayWrite || model.busy
15 )
16 .autocorrectionDisabled()
17 #if os(iOS)
18 .textInputAutocapitalization(.never)
19 #endif
20 .onSubmit { model.commit() }
21 .onKeyPress(.escape) {
22 model.discard()
23 return .handled
24 }
25 .onKeyPress(.tab) {
26 model.commit(moveRight: true)
27 return .handled
28 }
29 if model.dirty {
30 Button(sheetsMacString("Save")) { model.commit() }.disabled(model.busy)
31 Button("Discard") { model.discard() }.disabled(model.busy)
32 }
33 }.textFieldStyle(.roundedBorder).padding(8)
34 }
35}
36
37/// Edits the server refused or never answered. Editing goes on around them;
38/// each marked cell also offers Retry and Revert from its context menu.
39struct SheetFailedEditsBar: View {
40 var model: SheetModel
41 var body: some View {
42 if model.hasFailedEdits {
43 HStack {
44 Image(systemName: "exclamationmark.circle").foregroundStyle(.red).accessibilityHidden(true)
45 Text(sheetsMacString("Some cell edits weren’t saved."))
46 Spacer()
47 Button(sheetsMacString("Retry")) { model.retryWrites() }
48 Button(sheetsMacString("Revert"), role: .destructive) { model.revertWrites() }
49 }.font(.callout).padding(.horizontal, 8).padding(.vertical, 4)
50 }
51 }
52}
53
54struct SheetStatusBar: View {
55 var model: SheetModel
56 var body: some View {
57 HStack {
58 Text(model.page?.Sheet.TabName ?? "Sheet")
59 Spacer()
60 if model.busy { ProgressView().controlSize(.small) }
61 Text(model.saveStatus)
62 Text(model.live).foregroundStyle(.secondary)
63 }.font(.caption).padding(8)
64 }
65}
66