Files
luma/Luma/Instruments/HookPackUI.swift

54 lines
1.4 KiB
Swift

import SwiftUI
import LumaCore
struct HookPackUI: InstrumentUI {
let pack: HookPack
func makeConfigEditor(
configJSON: Binding<Data>,
engine: Engine,
selection: Binding<SidebarItemID?>
) -> AnyView {
let cfgBinding = Binding<HookPackConfig>(
get: {
(try? JSONDecoder().decode(HookPackConfig.self, from: configJSON.wrappedValue))
?? HookPackConfig(packId: pack.id, features: [:])
},
set: { newValue in
if let data = try? JSONEncoder().encode(newValue) {
configJSON.wrappedValue = data
}
}
)
return AnyView(
HookPackConfigView(
pack: pack,
config: cfgBinding,
engine: engine,
selection: selection
)
)
}
func renderEvent(
_ event: RuntimeEvent,
engine: Engine,
selection: Binding<SidebarItemID?>
) -> AnyView {
guard case .jsValue(let v) = event.payload else {
return AnyView(Text(String(describing: event.payload)))
}
return AnyView(
JSInspectValueView(
value: v,
sessionID: event.sessionID ?? UUID(),
engine: engine,
selection: selection
)
.font(.system(.footnote, design: .monospaced))
)
}
}