mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-23 22:36:55 +00:00
- 移除底部「添加参数」按钮(与末尾空行重复) - 「值/开关」分段选择器移到行首;「无值开关」文案改「开关」 - 删除按钮文案改「删除」 - 编辑面与订阅只读面拆成两个独立视图,均改用 Table 控件布局; 编辑行输入框改无边框(plain),参数名列限宽、值列弹性 - 原始文本编辑区与长值编辑 sheet 补分隔线边框 - NewServerSheet 的 isEditable 恒真,提交期禁用由外层负责, 避免编辑视图闪换成只读视图 - 列宽不用 TableColumn width: 参数:无排序 Table 列泛型固定为 Never,width:/value: 变体编译不过(macOS 15 SDK 实测),改经 内容约束表达
70 lines
2.4 KiB
Swift
70 lines
2.4 KiB
Swift
import SwiftUI
|
|
|
|
/// 「新建服务器」表单(服务器视图工具栏入口):连接字段草稿与表单栅格走
|
|
/// 共享 `ServerFormFields`(与编辑表单同一 interface),默认值端口 8388、
|
|
/// 加密 aes-256-gcm、插件「无」。落点由父视图按既有
|
|
/// `importTargetParent` 语义在打开时固定;提交成功关闭表单并把新身份交给
|
|
/// selection(由父视图选中);校验/提交失败留在表单,错误经共享呈现器点名。
|
|
struct NewServerSheet: View {
|
|
let workflow: CatalogWorkflow
|
|
let errors: ErrorAlertPresenter
|
|
let parent: NodeID?
|
|
@Binding var selection: NodeID?
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
/// 连接字段草稿由共享 module 持有(与编辑表单同一 interface),默认值
|
|
/// 端口 8388、加密 aes-256-gcm、插件「无」。
|
|
@StateObject private var fields = ServerFormFields.newForm()
|
|
@State private var isSubmitting = false
|
|
@FocusState private var fieldFocus: ServerFormField?
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 14) {
|
|
Text("新建服务器")
|
|
.font(.title2)
|
|
|
|
// isEditable 恒真:提交期间的禁用由外层 .disabled(isSubmitting) 负责,
|
|
// 避免参数编辑区在提交瞬间闪换成订阅只读视图。
|
|
ServerFormFieldsGrid(
|
|
fields: fields, plugin: pluginSection, isEditable: true,
|
|
fieldFocus: $fieldFocus)
|
|
|
|
HStack {
|
|
Spacer()
|
|
Button("取消", role: .cancel) { dismiss() }
|
|
Button("创建") { create() }
|
|
.keyboardShortcut(.defaultAction)
|
|
}
|
|
}
|
|
.disabled(isSubmitting)
|
|
.interactiveDismissDisabled(isSubmitting)
|
|
.defaultFocus($fieldFocus, .name)
|
|
.padding(20)
|
|
.frame(minWidth: 520, minHeight: 400)
|
|
}
|
|
|
|
/// 插件区状态经 workflow 投影(与编辑面同缝),选中态跟随草稿。
|
|
private var pluginSection: PluginSectionState {
|
|
workflow.newFormPluginSection(selection: fields.pluginChoice)
|
|
}
|
|
|
|
private func create() {
|
|
guard !isSubmitting else { return }
|
|
guard fields.validateForSubmit(), let draft = fields.draft else {
|
|
fieldFocus = fields.firstErrorField
|
|
return
|
|
}
|
|
isSubmitting = true
|
|
Task {
|
|
defer { isSubmitting = false }
|
|
do {
|
|
let id = try await workflow.createServer(draft, into: parent)
|
|
selection = id
|
|
dismiss()
|
|
} catch {
|
|
errors.present(error)
|
|
}
|
|
}
|
|
}
|
|
}
|