macOS: fix config form rendering
This commit is contained in:
committed by
Peter Steinberger
parent
cc2d617ea6
commit
3ec221c70e
@@ -9,14 +9,14 @@ struct ConfigSchemaForm: View {
|
||||
self.renderNode(schema, path: path)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func renderNode(_ schema: ConfigSchemaNode, path: ConfigPath) -> some View {
|
||||
private func renderNode(_ schema: ConfigSchemaNode, path: ConfigPath) -> AnyView {
|
||||
let value = store.configValue(at: path)
|
||||
let label = hintForPath(path, hints: store.configUiHints)?.label ?? schema.title
|
||||
let help = hintForPath(path, hints: store.configUiHints)?.help ?? schema.description
|
||||
|
||||
switch schema.schemaType {
|
||||
case "object":
|
||||
return AnyView(
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let label {
|
||||
Text(label)
|
||||
@@ -43,24 +43,29 @@ struct ConfigSchemaForm: View {
|
||||
self.renderAdditionalProperties(schema, path: path, value: value)
|
||||
}
|
||||
}
|
||||
)
|
||||
case "array":
|
||||
self.renderArray(schema, path: path, value: value, label: label, help: help)
|
||||
return AnyView(self.renderArray(schema, path: path, value: value, label: label, help: help))
|
||||
case "boolean":
|
||||
return AnyView(
|
||||
Toggle(isOn: self.boolBinding(path)) {
|
||||
if let label { Text(label) } else { Text("Enabled") }
|
||||
}
|
||||
.help(help ?? "")
|
||||
)
|
||||
case "number", "integer":
|
||||
self.renderNumberField(schema, path: path, label: label, help: help)
|
||||
return AnyView(self.renderNumberField(schema, path: path, label: label, help: help))
|
||||
case "string":
|
||||
self.renderStringField(schema, path: path, label: label, help: help)
|
||||
return AnyView(self.renderStringField(schema, path: path, label: label, help: help))
|
||||
default:
|
||||
return AnyView(
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
if let label { Text(label).font(.callout.weight(.semibold)) }
|
||||
Text("Unsupported field type.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +176,7 @@ struct ConfigSchemaForm: View {
|
||||
path: ConfigPath,
|
||||
value: Any?) -> some View
|
||||
{
|
||||
guard let additionalSchema = schema.additionalProperties else { return }
|
||||
if let additionalSchema = schema.additionalProperties {
|
||||
let dict = value as? [String: Any] ?? [:]
|
||||
let reserved = Set(schema.properties.keys)
|
||||
let extras = dict.keys.filter { !reserved.contains($0) }.sorted()
|
||||
@@ -216,6 +221,7 @@ struct ConfigSchemaForm: View {
|
||||
.controlSize(.small)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func stringBinding(_ path: ConfigPath) -> Binding<String> {
|
||||
Binding(
|
||||
|
||||
@@ -65,9 +65,9 @@ extension ChannelsStore {
|
||||
}
|
||||
|
||||
func updateConfigValue(path: ConfigPath, value: Any?) {
|
||||
var root = self.configDraft
|
||||
var root: Any = self.configDraft
|
||||
setValue(&root, path: path, value: value)
|
||||
self.configDraft = root
|
||||
self.configDraft = root as? [String: Any] ?? self.configDraft
|
||||
self.configDirty = true
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ private func setValue(_ root: inout Any, path: ConfigPath, value: Any?) {
|
||||
case .index(let index):
|
||||
var array = root as? [Any] ?? []
|
||||
if index >= array.count {
|
||||
array.append(contentsOf: repeatElement(NSNull(), count: index - array.count + 1))
|
||||
array.append(contentsOf: repeatElement(NSNull() as Any, count: index - array.count + 1))
|
||||
}
|
||||
if path.count == 1 {
|
||||
if let value {
|
||||
|
||||
@@ -900,7 +900,7 @@ extension DebugSettings {
|
||||
}
|
||||
}
|
||||
|
||||
private struct PlainSettingsGroupBoxStyle: GroupBoxStyle {
|
||||
struct PlainSettingsGroupBoxStyle: GroupBoxStyle {
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
configuration.label
|
||||
|
||||
Reference in New Issue
Block a user