restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import HelderCore
|
||||
import SwiftUI
|
||||
|
||||
/// The 460pt prompt: an optional note over the reference it inserts into the agent's composer.
|
||||
public struct PassOnPanel: View {
|
||||
let request: PassOnRequest
|
||||
let insert: (String) -> Void
|
||||
let cancel: () -> Void
|
||||
@State private var note = ""
|
||||
@FocusState private var focused: Bool
|
||||
|
||||
public init(request: PassOnRequest, insert: @escaping (String) -> Void, cancel: @escaping () -> Void) {
|
||||
self.request = request
|
||||
self.insert = insert
|
||||
self.cancel = cancel
|
||||
}
|
||||
|
||||
private var composed: String {
|
||||
PassOn.compose(note: note, reference: request.reference, code: request.code)
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
GeometryReader { geometry in
|
||||
ZStack(alignment: .topLeading) {
|
||||
Color.clear
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture(perform: cancel)
|
||||
panel
|
||||
.offset(x: min(max(8, request.anchor.x), geometry.size.width - Metrics.passOnWidth - 8),
|
||||
y: min(max(8, request.anchor.y + 6), geometry.size.height - 170))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var panel: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
HStack(spacing: 10) {
|
||||
SparkGlyph()
|
||||
.stroke(Palette.amber, style: StrokeStyle(lineWidth: 1.1 * 13 / 16, lineJoin: .round))
|
||||
.frame(width: 13, height: 13)
|
||||
Text("Pass on to agent").typeRole(TypeRole(.monoBold, 13)).foregroundStyle(Palette.text1)
|
||||
Spacer()
|
||||
EscChip()
|
||||
}
|
||||
TextField("", text: $note, prompt: Text("Add a note (optional)…").foregroundStyle(Palette.text4))
|
||||
.textFieldStyle(.plain)
|
||||
.typeRole(TypeRole(.monoRegular, 13))
|
||||
.foregroundStyle(Palette.text1)
|
||||
.focused($focused)
|
||||
.onSubmit { insert(composed) }
|
||||
.onExitCommand(perform: cancel)
|
||||
.padding(.horizontal, 10)
|
||||
.frame(height: 38)
|
||||
.background(Palette.editor, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).stroke(Palette.amber, lineWidth: Metrics.accentRule))
|
||||
.padding(Metrics.focusRingWidth)
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall + 2).stroke(Palette.focusRing, lineWidth: Metrics.focusRingWidth))
|
||||
.padding(-Metrics.focusRingWidth)
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
Text("Inserts").typeRole(Typography.panelLabel).foregroundStyle(Palette.text4).padding(.top, 5)
|
||||
preview
|
||||
}
|
||||
OverlayFooter.hint([("↵", "insert into agent"), ("esc", "cancel")])
|
||||
.typeRole(Typography.meta)
|
||||
}
|
||||
.padding(14)
|
||||
.frame(width: Metrics.passOnWidth)
|
||||
.background(Palette.panel, in: RoundedRectangle(cornerRadius: Metrics.radiusMedium))
|
||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusMedium).stroke(Palette.raised, lineWidth: Metrics.hairline))
|
||||
.shadow(color: Palette.menuShadow, radius: Metrics.menuShadowRadius, y: Metrics.menuShadowY)
|
||||
.onAppear { focused = true }
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var preview: some View {
|
||||
let chip = Text(composed)
|
||||
.typeRole(Typography.path)
|
||||
.foregroundStyle(Palette.ink)
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 4)
|
||||
if request.code != nil {
|
||||
ScrollView {
|
||||
chip.fixedSize(horizontal: false, vertical: true)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.frame(maxHeight: 132)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.background(Palette.amber, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
} else {
|
||||
chip.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
.background(Palette.amber, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The four-point spark that marks every "Pass on" action, drawn on a 16-unit grid.
|
||||
struct SparkGlyph: Shape {
|
||||
func path(in rect: CGRect) -> Path {
|
||||
let unit = min(rect.width, rect.height) / 16
|
||||
let points: [(CGFloat, CGFloat)] = [(8, 1.5), (9.6, 6.4), (14.5, 8), (9.6, 9.6), (8, 14.5), (6.4, 9.6), (1.5, 8), (6.4, 6.4)]
|
||||
var path = Path()
|
||||
for (index, point) in points.enumerated() {
|
||||
let p = CGPoint(x: rect.minX + point.0 * unit, y: rect.minY + point.1 * unit)
|
||||
if index == 0 { path.move(to: p) } else { path.addLine(to: p) }
|
||||
}
|
||||
path.closeSubpath()
|
||||
return path
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user