@he0119/dsh-settings-sync 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +122 -0
- package/README.md +76 -2
- package/cordis.patch.yml +3 -0
- package/icon.svg +7 -0
- package/lib/client.js +1175 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +1346 -0
- package/lib/types/credential-sync.d.ts +55 -0
- package/lib/types/error.d.ts +2 -0
- package/lib/types/index.d.ts +37 -0
- package/lib/types/local-only.d.ts +30 -0
- package/lib/types/patch-view.d.ts +43 -0
- package/lib/types/settings-fields.d.ts +16 -0
- package/lib/types/settings-selection.d.ts +11 -0
- package/lib/types/snapshot.d.ts +23 -0
- package/lib/types/sync-scope.d.ts +15 -0
- package/lib/types/sync.d.ts +73 -0
- package/lib/types/web.d.ts +25 -0
- package/lib/types/webdav.d.ts +38 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +94 -3
package/lib/client.js
ADDED
|
@@ -0,0 +1,1175 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@he0119/dsh-settings-sync",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let _deepseek_ai_dsh_client_ui_primitives_client = require("@deepseek-ai/dsh-client-ui-primitives/client");
|
|
9
|
+
// src/client/locales.ts
|
|
10
|
+
const namespace = "dsh-settings-sync";
|
|
11
|
+
const dictionaries = {
|
|
12
|
+
zh: {
|
|
13
|
+
title: "同步配置",
|
|
14
|
+
connection: "WebDAV",
|
|
15
|
+
operations: "同步",
|
|
16
|
+
introduction: "选择同步方向,检查将改变的配置条目和凭据,再确认写入。凭据和配置一起上传、下载,勾选在「同步范围」里完成;凭据加密后才写到服务器。",
|
|
17
|
+
credentialScopeGroup: "凭据",
|
|
18
|
+
credentialsPush: "上传到服务器",
|
|
19
|
+
credentialsPull: "从服务器下载",
|
|
20
|
+
credentialDirection: "凭据同步方向",
|
|
21
|
+
credentialSelection: "选择要同步的凭据",
|
|
22
|
+
previewCredentialPush: "预览上传",
|
|
23
|
+
previewCredentialPull: "预览下载",
|
|
24
|
+
previewCredentialsAgain: "重新预览",
|
|
25
|
+
listingCredentials: "正在读取凭据清单…",
|
|
26
|
+
credentialsNeedsAddress: "保存 WebDAV 地址后即可选择凭据。",
|
|
27
|
+
credentialReloadList: "重新读取清单",
|
|
28
|
+
credentialSelectionRemoved: "{count} 项已选凭据不在新清单中,已从本次选择移除。",
|
|
29
|
+
credentialPickOne: "勾选至少一项后可预览。",
|
|
30
|
+
credentialLimitReached: "已达上限。取消勾选一项后可继续选择。",
|
|
31
|
+
credentialGroupCount: "已选 {count} / 共 {total} 项",
|
|
32
|
+
credentialGroupLimit: "还可选 {remaining} 项,请逐项勾选。",
|
|
33
|
+
credentialSelectGroup: "全选本组",
|
|
34
|
+
credentialClearGroup: "清除本组",
|
|
35
|
+
credentialReviewUpload: "上传预览",
|
|
36
|
+
credentialReviewDownload: "下载预览",
|
|
37
|
+
credentialBack: "返回修改",
|
|
38
|
+
credentialConfirmUpload: "确认上传到服务器",
|
|
39
|
+
credentialConfirmDownload: "确认下载到本机",
|
|
40
|
+
credentialChangesPush: "新增 {added} 项,覆盖服务器上的同名凭据 {replaced} 项。",
|
|
41
|
+
credentialChangesPull: "新增 {added} 项,覆盖本机同名凭据 {replaced} 项。",
|
|
42
|
+
credentialOverwriteHint: "这次同步不会保存覆盖前的值。",
|
|
43
|
+
credentialRefs: "凭据引用",
|
|
44
|
+
credentialRecords: "凭据记录",
|
|
45
|
+
credentialUnscoped: "未归类的记录",
|
|
46
|
+
syncScope: "同步范围",
|
|
47
|
+
syncScopeHint: "默认同步本机配置补丁里的全部条目和凭据。取消勾选的条目、键或凭据只留在这台机器,不参与上传和下载。",
|
|
48
|
+
syncScopeLoading: "正在读取本机配置…",
|
|
49
|
+
syncScopeFailed: "无法读取本机配置。",
|
|
50
|
+
scopeListPartial: "本机凭据这次没能列进同步范围(读取凭据文件失败或超时),配置仍可照常同步。稍后「重试」或重新打开本页即可。",
|
|
51
|
+
scopeListInvalid: "同步范围列表格式不对,凭据这次没有列出来。请刷新后重试。",
|
|
52
|
+
syncScopeEmpty: "本机配置补丁里没有可同步的条目。",
|
|
53
|
+
localOnlyBadge: "仅本机",
|
|
54
|
+
localOnlyStale: "这些规则在本机配置里找不到对应条目或键(取消勾选即可移除)。",
|
|
55
|
+
treeSelected: "同步 {count} 项,共 {total} 项",
|
|
56
|
+
treeSelectedLimited: "已选 {count} / {limit} 项",
|
|
57
|
+
treeGroupLocalOnly: "{count}/{total} 项仅本机",
|
|
58
|
+
treeCollapse: "折叠 {group}",
|
|
59
|
+
treeExpand: "展开 {group}",
|
|
60
|
+
treeClearGroup: "全部标为仅本机",
|
|
61
|
+
treeSelectGroup: "全部参与同步",
|
|
62
|
+
retry: "重试",
|
|
63
|
+
credentialsLocalEmpty: "本机没有可上传的凭据。",
|
|
64
|
+
credentialsRemoteEmpty: "服务器上没有可下载的凭据。",
|
|
65
|
+
credentialsListFailed: "无法读取凭据清单。请检查 WebDAV 设置和同步加密密钥,再试一次。",
|
|
66
|
+
credentialsPreviewFailed: "无法预览凭据改动。请检查 WebDAV 设置和同步加密密钥,再重新预览。",
|
|
67
|
+
credentialsOutcomeUnknown: "未能确认凭据写入结果。请重新预览,核对本机和服务器上的凭据是否仍有差异。",
|
|
68
|
+
credentialsNoChanges: "所选凭据在本机和服务器上已经一致。",
|
|
69
|
+
push: "预览上传",
|
|
70
|
+
pull: "预览下载",
|
|
71
|
+
applyPush: "确认上传",
|
|
72
|
+
applyPull: "确认下载",
|
|
73
|
+
cancel: "取消",
|
|
74
|
+
preview: "改动预览",
|
|
75
|
+
previewing: "正在读取同步差异…",
|
|
76
|
+
applying: "正在应用改动…",
|
|
77
|
+
requestFailed: "无法完成同步请求。请确认插件已启用,刷新页面后重试。",
|
|
78
|
+
outcomeUnknown: "未收到写入结果。请重新预览,核对哪些配置已经同步。",
|
|
79
|
+
address: "WebDAV 目录",
|
|
80
|
+
addressHint: "填写 HTTPS 目录地址。插件会在里面自建 dsh-settings-sync 文件夹存放同步文件。",
|
|
81
|
+
auto: "自动同步",
|
|
82
|
+
autoHint: "每分钟检查一次配置。凭据不随自动同步搬运,改动后请在同步范围里手动同步。两边有冲突时请手动确认。",
|
|
83
|
+
username: "用户名",
|
|
84
|
+
usernameHint: "服务器需要登录时填写。",
|
|
85
|
+
password: "WebDAV 登录密码",
|
|
86
|
+
syncKey: "同步加密密钥",
|
|
87
|
+
syncKeyHint: "填写 64 位十六进制密钥。参与同步的设备需要使用同一份密钥。留空保留原值。",
|
|
88
|
+
invalidKey: "请输入 64 位十六进制密钥。",
|
|
89
|
+
keyWriteFailed: "凭据服务未保存同步加密密钥。",
|
|
90
|
+
sameRef: "请为登录密码和同步密钥使用不同的凭据名称。",
|
|
91
|
+
passwordHint: "填写新密码,留空保留原密码。",
|
|
92
|
+
configured: "配置",
|
|
93
|
+
notConfigured: "未设置",
|
|
94
|
+
discard: "放弃改动",
|
|
95
|
+
readOnly: "当前设置为只读。",
|
|
96
|
+
invalidUsername: "用户名不能含冒号或控制字符。",
|
|
97
|
+
passwordNeedsUser: "填写密码时也要填写用户名。",
|
|
98
|
+
settingsConflict: "设置已变化或宿主拒绝了保存,请重新读取设置。",
|
|
99
|
+
passwordWriteFailed: "凭据服务未保存密码。",
|
|
100
|
+
passwordUnavailable: "凭据存储当前不可用。",
|
|
101
|
+
save: "保存设置",
|
|
102
|
+
saving: "正在保存设置…",
|
|
103
|
+
saved: "设置已保存。",
|
|
104
|
+
reloadAddress: "重新读取设置",
|
|
105
|
+
addressError: "无法读取或保存 WebDAV 设置。",
|
|
106
|
+
dirtyAddress: "保存设置后即可预览同步。"
|
|
107
|
+
},
|
|
108
|
+
en: {
|
|
109
|
+
title: "Sync settings",
|
|
110
|
+
connection: "WebDAV",
|
|
111
|
+
operations: "Sync",
|
|
112
|
+
introduction: "Choose a direction, review the configuration entries and credentials that change, then confirm the write. Credentials upload and download with the configuration, selected in Sync scope, and only reach the server encrypted.",
|
|
113
|
+
credentialScopeGroup: "Credentials",
|
|
114
|
+
credentialsPush: "Upload to server",
|
|
115
|
+
credentialsPull: "Download from server",
|
|
116
|
+
credentialDirection: "Credential sync direction",
|
|
117
|
+
credentialSelection: "Select credentials to sync",
|
|
118
|
+
previewCredentialPush: "Preview upload",
|
|
119
|
+
previewCredentialPull: "Preview download",
|
|
120
|
+
previewCredentialsAgain: "Preview again",
|
|
121
|
+
listingCredentials: "Loading credential list…",
|
|
122
|
+
credentialsNeedsAddress: "Save the WebDAV URL to select credentials.",
|
|
123
|
+
credentialReloadList: "Reload list",
|
|
124
|
+
credentialSelectionRemoved: "{count} selected credentials are no longer listed and were removed from this selection.",
|
|
125
|
+
credentialPickOne: "Select at least one credential to preview changes.",
|
|
126
|
+
credentialLimitReached: "Selection limit reached. Deselect an item to select another.",
|
|
127
|
+
credentialGroupCount: "{count} of {total} selected",
|
|
128
|
+
credentialGroupLimit: "You can select {remaining} more. Select items individually.",
|
|
129
|
+
credentialSelectGroup: "Select whole group",
|
|
130
|
+
credentialClearGroup: "Clear group selection",
|
|
131
|
+
credentialReviewUpload: "Upload preview",
|
|
132
|
+
credentialReviewDownload: "Download preview",
|
|
133
|
+
credentialBack: "Back to selection",
|
|
134
|
+
credentialConfirmUpload: "Confirm upload to server",
|
|
135
|
+
credentialConfirmDownload: "Confirm download to this device",
|
|
136
|
+
credentialChangesPush: "Add {added} and overwrite {replaced} matching credentials on the server.",
|
|
137
|
+
credentialChangesPull: "Add {added} and overwrite {replaced} matching credentials on this device.",
|
|
138
|
+
credentialOverwriteHint: "This sync does not keep the previous values of overwritten credentials.",
|
|
139
|
+
credentialRefs: "Credential references",
|
|
140
|
+
credentialRecords: "Credential records",
|
|
141
|
+
credentialUnscoped: "Unscoped records",
|
|
142
|
+
syncScope: "Sync scope",
|
|
143
|
+
syncScopeHint: "Every entry of this profile’s configuration patch and every credential syncs by default. Unchecking an entry, key or credential keeps it on this machine.",
|
|
144
|
+
syncScopeLoading: "Loading this device’s configuration…",
|
|
145
|
+
syncScopeFailed: "Could not load this device’s configuration.",
|
|
146
|
+
scopeListPartial: "This device’s credentials did not make it into the sync scope this time (the credential file could not be read or the lookup timed out). Configuration still syncs as usual; retry or reopen this page later.",
|
|
147
|
+
scopeListInvalid: "The sync scope list came back in an unexpected shape, so credentials were left out this time. Refresh and retry.",
|
|
148
|
+
syncScopeEmpty: "This profile’s configuration patch has no syncable entries.",
|
|
149
|
+
localOnlyBadge: "This device only",
|
|
150
|
+
localOnlyStale: "These rules match no entry or key in this device’s configuration (uncheck to remove).",
|
|
151
|
+
treeSelected: "{count} of {total} synced",
|
|
152
|
+
treeSelectedLimited: "{count} / {limit} selected",
|
|
153
|
+
treeGroupLocalOnly: "{count}/{total} on this device only",
|
|
154
|
+
treeCollapse: "Collapse {group}",
|
|
155
|
+
treeExpand: "Expand {group}",
|
|
156
|
+
treeClearGroup: "Keep the whole group on this device",
|
|
157
|
+
treeSelectGroup: "Sync the whole group",
|
|
158
|
+
retry: "Retry",
|
|
159
|
+
credentialsLocalEmpty: "There are no credentials to upload from this device.",
|
|
160
|
+
credentialsRemoteEmpty: "There are no credentials to download from the server.",
|
|
161
|
+
credentialsListFailed: "Could not load the credential list. Check your WebDAV settings and sync encryption key, then try again.",
|
|
162
|
+
credentialsPreviewFailed: "Could not preview credential changes. Check your WebDAV settings and sync encryption key, then preview again.",
|
|
163
|
+
credentialsOutcomeUnknown: "The credential write result could not be confirmed. Preview again to check whether credentials still differ.",
|
|
164
|
+
credentialsNoChanges: "The selected credentials already match on this device and the server.",
|
|
165
|
+
push: "Preview upload",
|
|
166
|
+
pull: "Preview download",
|
|
167
|
+
applyPush: "Confirm upload",
|
|
168
|
+
applyPull: "Confirm download",
|
|
169
|
+
cancel: "Cancel",
|
|
170
|
+
preview: "Changes to review",
|
|
171
|
+
previewing: "Reading changes…",
|
|
172
|
+
applying: "Applying changes…",
|
|
173
|
+
requestFailed: "The sync request failed. Check that the plugin is enabled, then refresh and try again.",
|
|
174
|
+
outcomeUnknown: "The write result was not received. Preview again to check which configuration was synced.",
|
|
175
|
+
address: "WebDAV directory",
|
|
176
|
+
addressHint: "Use an HTTPS directory URL. The plugin creates a dsh-settings-sync folder inside it for its own files.",
|
|
177
|
+
auto: "Automatic sync",
|
|
178
|
+
autoHint: "Checks the configuration once a minute. Credentials never move automatically; sync them manually from Sync scope. Review conflicting changes manually.",
|
|
179
|
+
username: "Username",
|
|
180
|
+
usernameHint: "Enter a username if the server requires sign-in.",
|
|
181
|
+
password: "WebDAV password",
|
|
182
|
+
syncKey: "Sync encryption key",
|
|
183
|
+
syncKeyHint: "Enter a 64-character hexadecimal key. Use the same key on each device. Leave blank to keep it.",
|
|
184
|
+
invalidKey: "Enter a 64-character hexadecimal key.",
|
|
185
|
+
keyWriteFailed: "The credential service did not save the encryption key.",
|
|
186
|
+
sameRef: "Use separate credential references for the password and encryption key.",
|
|
187
|
+
passwordHint: "Enter a new password or leave blank to keep the current one.",
|
|
188
|
+
configured: "Configured",
|
|
189
|
+
notConfigured: "Not set",
|
|
190
|
+
discard: "Discard changes",
|
|
191
|
+
readOnly: "These settings are read-only.",
|
|
192
|
+
invalidUsername: "The username cannot contain colons or control characters.",
|
|
193
|
+
passwordNeedsUser: "Enter a username with the password.",
|
|
194
|
+
settingsConflict: "The settings changed or the host rejected the save. Reload the settings.",
|
|
195
|
+
passwordWriteFailed: "The credential service did not save the password.",
|
|
196
|
+
passwordUnavailable: "Credential storage is unavailable.",
|
|
197
|
+
save: "Save settings",
|
|
198
|
+
saving: "Saving settings…",
|
|
199
|
+
saved: "Settings saved.",
|
|
200
|
+
reloadAddress: "Reload settings",
|
|
201
|
+
addressError: "The WebDAV settings could not be loaded or saved.",
|
|
202
|
+
dirtyAddress: "Save the settings to preview changes."
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
// src/error.ts
|
|
206
|
+
/** An operation failure whose message is safe to return to the browser. */
|
|
207
|
+
var SyncError = class extends Error {};
|
|
208
|
+
// src/local-only.ts
|
|
209
|
+
const ENTRY = /^[A-Za-z0-9_@][A-Za-z0-9_@/.-]*$/;
|
|
210
|
+
/** 把 `条目ID:键.路径` 拆成段;没有冒号时只有条目本身。 */
|
|
211
|
+
function idSegments(id) {
|
|
212
|
+
const separator = id.indexOf(":");
|
|
213
|
+
if (separator < 0) return [id];
|
|
214
|
+
return [id.slice(0, separator), ...id.slice(separator + 1).split(".")];
|
|
215
|
+
}
|
|
216
|
+
/** 段列表拼回节点 ID。 */
|
|
217
|
+
function nodeId(segments) {
|
|
218
|
+
const [entry, ...path] = segments;
|
|
219
|
+
return path.length ? `${entry}:${path.join(".")}` : entry;
|
|
220
|
+
}
|
|
221
|
+
function isPrefix(prefix, target) {
|
|
222
|
+
return prefix.length <= target.length && prefix.every((segment, index) => target[index] === segment);
|
|
223
|
+
}
|
|
224
|
+
function parseRule(raw) {
|
|
225
|
+
const include = raw.startsWith("+");
|
|
226
|
+
const body = include ? raw.slice(1) : raw;
|
|
227
|
+
const separator = body.indexOf(":");
|
|
228
|
+
const entry = separator < 0 ? body : body.slice(0, separator);
|
|
229
|
+
const path = separator < 0 ? [] : body.slice(separator + 1).split(".");
|
|
230
|
+
if (entry.length > 100 || !ENTRY.test(entry)) return void 0;
|
|
231
|
+
if (path.some((segment) => segment.length === 0 || /[\u0000-\u001f]/.test(segment))) return void 0;
|
|
232
|
+
return {
|
|
233
|
+
raw,
|
|
234
|
+
include,
|
|
235
|
+
segments: [entry, ...path]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function localOnlyState(rules) {
|
|
239
|
+
const parsed = [];
|
|
240
|
+
const invalid = [];
|
|
241
|
+
for (const raw of rules) {
|
|
242
|
+
const rule = parseRule(raw);
|
|
243
|
+
if (rule === void 0) invalid.push(raw);
|
|
244
|
+
else parsed.push(rule);
|
|
245
|
+
}
|
|
246
|
+
function nearest(id) {
|
|
247
|
+
const target = idSegments(id);
|
|
248
|
+
let best;
|
|
249
|
+
for (const rule of parsed) {
|
|
250
|
+
if (!isPrefix(rule.segments, target)) continue;
|
|
251
|
+
if (best === void 0 || rule.segments.length > best.segments.length || rule.segments.length === best.segments.length && rule.include) best = rule;
|
|
252
|
+
}
|
|
253
|
+
return best;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
invalid,
|
|
257
|
+
isLocalOnly: (id) => {
|
|
258
|
+
const rule = nearest(id);
|
|
259
|
+
return rule !== void 0 && !rule.include;
|
|
260
|
+
},
|
|
261
|
+
reasonFor: (id) => nearest(id)?.raw
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** 勾选/取消勾选一个节点,返回新的规则列表。`synced` 为 true 表示这一项参与同步。 */
|
|
265
|
+
function toggleLocalOnly(rules, id, synced) {
|
|
266
|
+
if (!idSegments(id).every((segment) => segment.length > 0)) throw new SyncError("同步范围节点无效。");
|
|
267
|
+
const target = idSegments(id);
|
|
268
|
+
const kept = rules.filter((raw) => {
|
|
269
|
+
const rule = parseRule(raw);
|
|
270
|
+
return rule === void 0 || !isPrefix(target, rule.segments);
|
|
271
|
+
});
|
|
272
|
+
const state = localOnlyState(kept);
|
|
273
|
+
if (synced) return state.isLocalOnly(id) ? [...kept, `+${id}`] : kept;
|
|
274
|
+
return state.isLocalOnly(id) ? kept : [...kept, id];
|
|
275
|
+
}
|
|
276
|
+
// src/client/styles.ts
|
|
277
|
+
const prefix = "dsh-settings-sync";
|
|
278
|
+
const styles = [
|
|
279
|
+
".dsh-settings-sync { container-type: inline-size; display: grid; gap: 18px; padding: 4px 0; color: var(--dsw-alias-label-primary); }",
|
|
280
|
+
".dsh-settings-sync__group { display: grid; min-width: 0; gap: 8px; }",
|
|
281
|
+
".dsh-settings-sync__group + .dsh-settings-sync__group { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 18px; }",
|
|
282
|
+
".dsh-settings-sync h3, .dsh-settings-sync h4, .dsh-settings-sync p { margin: 0; }",
|
|
283
|
+
".dsh-settings-sync h3 { font-size: 16px; font-weight: 600; line-height: 24px; }",
|
|
284
|
+
".dsh-settings-sync h4, .dsh-settings-sync p { font-size: 13px; line-height: 1.6; }",
|
|
285
|
+
".dsh-settings-sync__hint, .dsh-settings-sync__note { color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 18px; }",
|
|
286
|
+
".dsh-settings-sync__form { display: grid; gap: 8px; }",
|
|
287
|
+
".dsh-settings-sync__row { display: grid; grid-template-columns: minmax(0, 1fr) min(320px, 55%); align-items: center; gap: 16px; padding: 8px 0; }",
|
|
288
|
+
".dsh-settings-sync__row-text { display: grid; min-width: 0; gap: 2px; }",
|
|
289
|
+
".dsh-settings-sync__label { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 14px; line-height: 22px; }",
|
|
290
|
+
".dsh-settings-sync__tag { border: 0.5px solid var(--dsw-alias-border-l2); border-radius: 6px; padding: 0 6px; color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 16px; }",
|
|
291
|
+
".dsh-settings-sync__tag[data-configured=true] { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }",
|
|
292
|
+
".dsh-settings-sync__actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }",
|
|
293
|
+
".dsh-settings-sync__preview { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--dsw-alias-border-l3); border-radius: 8px; }",
|
|
294
|
+
".dsh-settings-sync__credential-picker:not([hidden]) { display: grid; min-width: 0; gap: 8px; }",
|
|
295
|
+
".dsh-settings-sync__tree { display: grid; gap: 6px; min-width: 0; }",
|
|
296
|
+
".dsh-settings-sync__tree > ul { max-block-size: 18rem; overflow: auto; padding: 3px; }",
|
|
297
|
+
".dsh-settings-sync__tree-branch { list-style: none; margin: 0; padding: 0; overflow-wrap: anywhere; }",
|
|
298
|
+
".dsh-settings-sync__tree-branch .dsh-settings-sync__tree-branch { padding-inline-start: 16px; margin-inline-start: 14px; border-inline-start: 1px solid var(--dsw-alias-border-l2); }",
|
|
299
|
+
".dsh-settings-sync__tree-row { display: flex; align-items: center; gap: 4px; min-block-size: 28px; }",
|
|
300
|
+
".dsh-settings-sync__tree-choice { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 6px; min-width: 0; }",
|
|
301
|
+
".dsh-settings-sync__tree-choice > span { min-width: 0; }",
|
|
302
|
+
".dsh-settings-sync__tree-disclosure { flex: 0 0 auto; }",
|
|
303
|
+
".dsh-settings-sync__tree-credential-row { flex-wrap: wrap; }",
|
|
304
|
+
".dsh-settings-sync__tree-credential-disclosure { min-inline-size: 0; max-inline-size: 100%; block-size: auto; min-block-size: 28px; text-align: start; }",
|
|
305
|
+
".dsh-settings-sync__tree-credential-limit { padding-inline-start: 10px; }",
|
|
306
|
+
".dsh-settings-sync__tree-leaf { display: flex; align-items: center; gap: 8px; padding-inline-start: 32px; min-block-size: 28px; }",
|
|
307
|
+
".dsh-settings-sync__value { min-inline-size: 0; max-inline-size: 26rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 18px; }",
|
|
308
|
+
".dsh-settings-sync__summary { white-space: pre-wrap; overflow-wrap: anywhere; }",
|
|
309
|
+
".dsh-settings-sync__error { color: var(--dsw-alias-state-error-primary); }",
|
|
310
|
+
".dsh-settings-sync progress { width: 100%; }",
|
|
311
|
+
".dsh-settings-sync__switch { justify-self: end; }",
|
|
312
|
+
"@container (max-width: 480px) { .dsh-settings-sync__row { grid-template-columns: minmax(0, 1fr); gap: 6px; } }"
|
|
313
|
+
].join("\n");
|
|
314
|
+
// src/client/SelectionTree.ts
|
|
315
|
+
function makeGroups(entries) {
|
|
316
|
+
const root = /* @__PURE__ */ new Map();
|
|
317
|
+
for (const { id, path } of entries) {
|
|
318
|
+
let children = root;
|
|
319
|
+
for (let depth = 0; depth < path.length - 1; depth++) {
|
|
320
|
+
const label = path[depth];
|
|
321
|
+
const key = `group:${label}`;
|
|
322
|
+
let group = children.get(key);
|
|
323
|
+
if (!group) {
|
|
324
|
+
group = {
|
|
325
|
+
label,
|
|
326
|
+
groupId: nodeId(path.slice(0, depth + 1)),
|
|
327
|
+
children: /* @__PURE__ */ new Map(),
|
|
328
|
+
ids: []
|
|
329
|
+
};
|
|
330
|
+
children.set(key, group);
|
|
331
|
+
}
|
|
332
|
+
group.ids.push(id);
|
|
333
|
+
children = group.children;
|
|
334
|
+
}
|
|
335
|
+
children.set(`entry:${id}`, {
|
|
336
|
+
label: path.at(-1) ?? id,
|
|
337
|
+
id
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return root;
|
|
341
|
+
}
|
|
342
|
+
function GroupRow({ t, label, open, toggle, total, note, checked, mixed, disabled, onChange, children }) {
|
|
343
|
+
const checkbox = (0, react.useRef)(null);
|
|
344
|
+
const branchId = (0, react.useId)();
|
|
345
|
+
const noteId = `${branchId}-note`;
|
|
346
|
+
const disclosureLabel = t(open ? "treeCollapse" : "treeExpand").replace("{group}", () => label);
|
|
347
|
+
(0, react.useLayoutEffect)(() => {
|
|
348
|
+
const input = checkbox.current?.querySelector("input");
|
|
349
|
+
if (!input) return;
|
|
350
|
+
input.indeterminate = mixed;
|
|
351
|
+
if (note) input.setAttribute("aria-describedby", noteId);
|
|
352
|
+
else input.removeAttribute("aria-describedby");
|
|
353
|
+
});
|
|
354
|
+
return (0, react.createElement)("li", null, (0, react.createElement)("div", { className: `${prefix}__tree-row` }, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
355
|
+
type: "button",
|
|
356
|
+
size: "sm",
|
|
357
|
+
variant: "ghost",
|
|
358
|
+
onClick: toggle,
|
|
359
|
+
"aria-label": disclosureLabel,
|
|
360
|
+
"aria-expanded": open,
|
|
361
|
+
"aria-controls": branchId,
|
|
362
|
+
className: `${prefix}__tree-disclosure`
|
|
363
|
+
}, (0, react.createElement)("span", { "aria-hidden": true }, open ? "▾" : "▸")), (0, react.createElement)("div", { className: `${prefix}__tree-choice` }, (0, react.createElement)("span", { ref: checkbox }, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Checkbox, {
|
|
364
|
+
label,
|
|
365
|
+
checked,
|
|
366
|
+
title: t(checked ? "treeClearGroup" : "treeSelectGroup"),
|
|
367
|
+
disabled: disabled || mixed === false && total === 0,
|
|
368
|
+
onChange: () => onChange(!checked)
|
|
369
|
+
})), note && (0, react.createElement)("span", {
|
|
370
|
+
id: noteId,
|
|
371
|
+
className: `dsh-settings-sync__note`
|
|
372
|
+
}, note))), (0, react.createElement)("ul", {
|
|
373
|
+
id: branchId,
|
|
374
|
+
className: `${prefix}__tree-branch`,
|
|
375
|
+
hidden: !open
|
|
376
|
+
}, open && children));
|
|
377
|
+
}
|
|
378
|
+
function CredentialGroupRow({ t, label, open, toggle, total, selected, remaining, disabled, onSelect, onClear, children }) {
|
|
379
|
+
const disclosure = (0, react.useRef)(null);
|
|
380
|
+
const branchId = (0, react.useId)();
|
|
381
|
+
const labelId = `${branchId}-label`;
|
|
382
|
+
const countId = `${branchId}-count`;
|
|
383
|
+
const noteId = `${branchId}-limit`;
|
|
384
|
+
const [rejected, setRejected] = (0, react.useState)(false);
|
|
385
|
+
const disclosureLabel = t(open ? "treeCollapse" : "treeExpand").replace("{group}", () => label);
|
|
386
|
+
const count = t("credentialGroupCount").replace("{count}", String(selected)).replace("{total}", String(total));
|
|
387
|
+
const exceedsLimit = total - selected > remaining;
|
|
388
|
+
let note = "";
|
|
389
|
+
if (rejected && exceedsLimit) note = remaining === 0 ? t("credentialLimitReached") : t("credentialGroupLimit").replace("{remaining}", String(remaining));
|
|
390
|
+
return (0, react.createElement)("li", null, (0, react.createElement)("div", { className: `${prefix}__tree-row ${prefix}__tree-credential-row` }, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
391
|
+
type: "button",
|
|
392
|
+
size: "sm",
|
|
393
|
+
variant: "ghost",
|
|
394
|
+
onClick: toggle,
|
|
395
|
+
ref: disclosure,
|
|
396
|
+
"aria-label": disclosureLabel,
|
|
397
|
+
"aria-expanded": open,
|
|
398
|
+
"aria-controls": branchId,
|
|
399
|
+
"aria-describedby": countId,
|
|
400
|
+
className: `${prefix}__tree-credential-disclosure`
|
|
401
|
+
}, (0, react.createElement)("span", { "aria-hidden": true }, open ? "▾" : "▸"), (0, react.createElement)("span", { id: labelId }, label)), (0, react.createElement)("span", {
|
|
402
|
+
id: countId,
|
|
403
|
+
className: `${prefix}__note`
|
|
404
|
+
}, count), open && total > 1 && (0, react.createElement)("div", {
|
|
405
|
+
className: `dsh-settings-sync__actions`,
|
|
406
|
+
role: "group",
|
|
407
|
+
"aria-labelledby": labelId
|
|
408
|
+
}, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
409
|
+
type: "button",
|
|
410
|
+
size: "sm",
|
|
411
|
+
variant: "outline",
|
|
412
|
+
disabled: disabled || selected === total,
|
|
413
|
+
"aria-describedby": note ? noteId : void 0,
|
|
414
|
+
onClick: () => {
|
|
415
|
+
setRejected(exceedsLimit);
|
|
416
|
+
if (!exceedsLimit) {
|
|
417
|
+
disclosure.current?.focus();
|
|
418
|
+
onSelect();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}, t("credentialSelectGroup")), (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
422
|
+
type: "button",
|
|
423
|
+
size: "sm",
|
|
424
|
+
variant: "outline",
|
|
425
|
+
disabled: disabled || selected === 0,
|
|
426
|
+
onClick: () => {
|
|
427
|
+
setRejected(false);
|
|
428
|
+
disclosure.current?.focus();
|
|
429
|
+
onClear();
|
|
430
|
+
}
|
|
431
|
+
}, t("credentialClearGroup")))), open && (0, react.createElement)("div", {
|
|
432
|
+
id: noteId,
|
|
433
|
+
className: `dsh-settings-sync__note dsh-settings-sync__tree-credential-limit`,
|
|
434
|
+
role: "status"
|
|
435
|
+
}, note), (0, react.createElement)("ul", {
|
|
436
|
+
id: branchId,
|
|
437
|
+
className: `${prefix}__tree-branch`,
|
|
438
|
+
hidden: !open
|
|
439
|
+
}, open && children));
|
|
440
|
+
}
|
|
441
|
+
function SelectionTree(props) {
|
|
442
|
+
const { t, entries, disabled, labelledBy } = props;
|
|
443
|
+
const root = (0, react.useMemo)(() => makeGroups(entries), [entries]);
|
|
444
|
+
const [expansion, setExpansion] = (0, react.useState)(() => /* @__PURE__ */ new Map());
|
|
445
|
+
const shortCredentialList = props.kind === "credentials" && entries.length <= 8;
|
|
446
|
+
const state = (0, react.useMemo)(() => props.kind === "localOnly" ? localOnlyState(props.rules) : void 0, [props.kind, props.kind === "localOnly" ? props.rules : void 0]);
|
|
447
|
+
const picked = new Set(props.kind === "credentials" ? props.selection : []);
|
|
448
|
+
const remaining = props.kind === "credentials" ? Math.max(0, props.limit - picked.size) : 0;
|
|
449
|
+
const stale = props.kind === "localOnly" ? props.stale ?? [] : [];
|
|
450
|
+
function toggle(path) {
|
|
451
|
+
setExpansion((current) => {
|
|
452
|
+
const open = current.get(path) ?? shortCredentialList;
|
|
453
|
+
const next = new Map(current);
|
|
454
|
+
next.set(path, !open);
|
|
455
|
+
return next;
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
function changeLeaf(id, checked) {
|
|
459
|
+
if (props.kind === "localOnly") {
|
|
460
|
+
props.onChange(toggleLocalOnly(props.rules, id, checked));
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (!checked) props.onChange(props.selection.filter((entry) => entry !== id));
|
|
464
|
+
else if (remaining > 0 && !picked.has(id)) props.onChange([...props.selection, id]);
|
|
465
|
+
}
|
|
466
|
+
function renderNodes(nodes, parents) {
|
|
467
|
+
return Array.from(nodes, ([key, node]) => {
|
|
468
|
+
if ("id" in node) {
|
|
469
|
+
const excluded = state?.isLocalOnly(node.id) ?? false;
|
|
470
|
+
const title = props.kind === "localOnly" ? excluded ? `${t("localOnlyBadge")}:${state?.reasonFor(node.id) ?? node.id}` : node.id : void 0;
|
|
471
|
+
const checked = props.kind === "credentials" ? picked.has(node.id) : !excluded;
|
|
472
|
+
const value = props.kind === "localOnly" ? props.values?.[node.id] : void 0;
|
|
473
|
+
return (0, react.createElement)("li", {
|
|
474
|
+
key,
|
|
475
|
+
className: `${prefix}__tree-leaf`
|
|
476
|
+
}, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Checkbox, {
|
|
477
|
+
label: node.label,
|
|
478
|
+
title,
|
|
479
|
+
checked,
|
|
480
|
+
disabled: disabled || props.kind === "credentials" && !checked && remaining <= 0,
|
|
481
|
+
onChange: (next) => changeLeaf(node.id, next)
|
|
482
|
+
}), value ? (0, react.createElement)("span", {
|
|
483
|
+
className: `${prefix}__value`,
|
|
484
|
+
title: value
|
|
485
|
+
}, value) : null);
|
|
486
|
+
}
|
|
487
|
+
const path = [...parents, key];
|
|
488
|
+
const pathKey = JSON.stringify(path);
|
|
489
|
+
const open = expansion.get(pathKey) ?? shortCredentialList;
|
|
490
|
+
const group = {
|
|
491
|
+
key,
|
|
492
|
+
t,
|
|
493
|
+
label: node.label,
|
|
494
|
+
open,
|
|
495
|
+
total: node.ids.length,
|
|
496
|
+
disabled,
|
|
497
|
+
toggle: () => toggle(pathKey),
|
|
498
|
+
children: open && renderNodes(node.children, path)
|
|
499
|
+
};
|
|
500
|
+
if (props.kind === "credentials") {
|
|
501
|
+
const added = node.ids.filter((id) => !picked.has(id));
|
|
502
|
+
return (0, react.createElement)(CredentialGroupRow, {
|
|
503
|
+
...group,
|
|
504
|
+
selected: group.total - added.length,
|
|
505
|
+
remaining,
|
|
506
|
+
onSelect: () => props.onChange([...props.selection, ...added]),
|
|
507
|
+
onClear: () => {
|
|
508
|
+
const removed = new Set(node.ids);
|
|
509
|
+
props.onChange(props.selection.filter((id) => !removed.has(id)));
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
const excluded = node.ids.filter((id) => state?.isLocalOnly(id)).length;
|
|
514
|
+
const note = excluded > 0 ? t("treeGroupLocalOnly").replace("{count}", String(excluded)).replace("{total}", String(group.total)) : "";
|
|
515
|
+
return (0, react.createElement)(GroupRow, {
|
|
516
|
+
...group,
|
|
517
|
+
note,
|
|
518
|
+
checked: excluded === 0,
|
|
519
|
+
mixed: excluded > 0 && excluded < group.total,
|
|
520
|
+
onChange: (next) => props.onChange(toggleLocalOnly(props.rules, node.groupId, next))
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
const summary = props.kind === "localOnly" ? t("treeSelected").replace("{count}", String(entries.filter((entry) => !state?.isLocalOnly(entry.id)).length)).replace("{total}", String(entries.length)) : null;
|
|
525
|
+
return (0, react.createElement)(react.Fragment, null, entries.length > 0 && (0, react.createElement)("div", { className: `dsh-settings-sync__tree` }, (0, react.createElement)("ul", {
|
|
526
|
+
className: `dsh-settings-sync__tree-branch`,
|
|
527
|
+
"aria-labelledby": labelledBy
|
|
528
|
+
}, renderNodes(root, [])), summary && (0, react.createElement)("p", {
|
|
529
|
+
role: "status",
|
|
530
|
+
className: `dsh-settings-sync__note`
|
|
531
|
+
}, summary)), stale.length > 0 && (0, react.createElement)("div", { className: `dsh-settings-sync__tree` }, (0, react.createElement)("p", { className: `dsh-settings-sync__hint` }, t("localOnlyStale")), (0, react.createElement)("ul", { className: `dsh-settings-sync__tree-branch` }, stale.map((raw) => (0, react.createElement)("li", {
|
|
532
|
+
key: raw,
|
|
533
|
+
className: `dsh-settings-sync__tree-leaf`
|
|
534
|
+
}, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Checkbox, {
|
|
535
|
+
label: raw,
|
|
536
|
+
checked: true,
|
|
537
|
+
disabled,
|
|
538
|
+
onChange: () => props.kind === "localOnly" && props.onChange(props.rules.filter((rule) => rule !== raw))
|
|
539
|
+
}))))));
|
|
540
|
+
}
|
|
541
|
+
// src/client/SyncPanel.ts
|
|
542
|
+
const endpoint = "/api/dsh-settings-sync/run";
|
|
543
|
+
/** 用户写的是上级目录:统一补上结尾斜杠,写不出合法地址时返回 undefined。 */
|
|
544
|
+
function folderAddress(value) {
|
|
545
|
+
if (!value) return void 0;
|
|
546
|
+
try {
|
|
547
|
+
const url = new URL(value);
|
|
548
|
+
if (!url.pathname.endsWith("/")) url.pathname += "/";
|
|
549
|
+
return url;
|
|
550
|
+
} catch {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function isObject(value) {
|
|
555
|
+
return typeof value === "object" && value !== null;
|
|
556
|
+
}
|
|
557
|
+
function sameChoices(first, second) {
|
|
558
|
+
if (first === second) return true;
|
|
559
|
+
const choices = new Set(first);
|
|
560
|
+
return choices.size === new Set(second).size && second.every((id) => choices.has(id));
|
|
561
|
+
}
|
|
562
|
+
/** 同步范围里的节点:配置行按条目和键分段,凭据行挂在「凭据」分组下。 */
|
|
563
|
+
function scopeNodes(entries, t) {
|
|
564
|
+
return entries.map((id) => {
|
|
565
|
+
if (!id.startsWith(`credentials:`)) return {
|
|
566
|
+
id,
|
|
567
|
+
path: idSegments(id)
|
|
568
|
+
};
|
|
569
|
+
return {
|
|
570
|
+
id,
|
|
571
|
+
path: [t("credentialScopeGroup"), id.slice(12)]
|
|
572
|
+
};
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
function SettingRow({ id, label, hint, state, input }) {
|
|
576
|
+
const hintId = `${id}-hint`;
|
|
577
|
+
const stateId = `${id}-state`;
|
|
578
|
+
return (0, react.createElement)("div", { className: `${prefix}__row` }, (0, react.createElement)("div", { className: `${prefix}__row-text` }, (0, react.createElement)("div", { className: `${prefix}__label` }, (0, react.createElement)("label", { htmlFor: id }, label), state && (0, react.createElement)("span", {
|
|
579
|
+
id: stateId,
|
|
580
|
+
className: `dsh-settings-sync__tag`,
|
|
581
|
+
"data-configured": state.configured
|
|
582
|
+
}, state.label)), (0, react.createElement)("div", {
|
|
583
|
+
className: `${prefix}__note`,
|
|
584
|
+
id: hintId
|
|
585
|
+
}, hint)), (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Input, {
|
|
586
|
+
...input,
|
|
587
|
+
id,
|
|
588
|
+
"aria-describedby": state ? `${stateId} ${hintId}` : hintId
|
|
589
|
+
}));
|
|
590
|
+
}
|
|
591
|
+
function SyncPanel({ t, configForm, getCredentials, subscribeCredentials }) {
|
|
592
|
+
const [pending, setPending] = (0, react.useState)(null);
|
|
593
|
+
const [preview, setPreview] = (0, react.useState)(null);
|
|
594
|
+
const [picker, setPicker] = (0, react.useState)(null);
|
|
595
|
+
const [feedback, setFeedback] = (0, react.useState)(null);
|
|
596
|
+
const [snapshot, setSnapshot] = (0, react.useState)(() => configForm?.getSnapshot());
|
|
597
|
+
const [draft, setDraft] = (0, react.useState)(null);
|
|
598
|
+
const [entries, setEntries] = (0, react.useState)(void 0);
|
|
599
|
+
const [values, setValues] = (0, react.useState)({});
|
|
600
|
+
const [staleRules, setStaleRules] = (0, react.useState)([]);
|
|
601
|
+
const [entriesError, setEntriesError] = (0, react.useState)(false);
|
|
602
|
+
const [scopeNote, setScopeNote] = (0, react.useState)(null);
|
|
603
|
+
const [entriesAttempt, setEntriesAttempt] = (0, react.useState)(0);
|
|
604
|
+
const [password, setPassword] = (0, react.useState)("");
|
|
605
|
+
const [syncKey, setSyncKey] = (0, react.useState)("");
|
|
606
|
+
const [addressStatus, setAddressStatus] = (0, react.useState)(null);
|
|
607
|
+
const [saving, setSaving] = (0, react.useState)(false);
|
|
608
|
+
const [credentialInfo, setCredentialInfo] = (0, react.useState)(null);
|
|
609
|
+
const [credentialGeneration, setCredentialGeneration] = (0, react.useState)(0);
|
|
610
|
+
const address = snapshot?.status === "ready" ? snapshot.value?.sync ?? {} : null;
|
|
611
|
+
const credentials = (0, react.useSyncExternalStore)(subscribeCredentials, getCredentials);
|
|
612
|
+
const ref = address?.passwordRef?.trim() || "DSH_SETTINGS_SYNC_PASSWORD";
|
|
613
|
+
const keyRef = address?.keyEnv ?? "DSH_SETTINGS_SYNC_KEY";
|
|
614
|
+
const url = draft?.url ?? address?.url ?? "";
|
|
615
|
+
const username = draft?.username ?? address?.username ?? "";
|
|
616
|
+
const accountChanged = url.trim() !== (address?.url ?? "") || username.trim() !== (address?.username ?? "");
|
|
617
|
+
const auto = draft?.auto ?? address?.auto ?? false;
|
|
618
|
+
const savedLocalOnly = (0, react.useMemo)(() => address?.localOnly ?? [], [address?.localOnly]);
|
|
619
|
+
const localOnly = draft?.localOnly ?? savedLocalOnly;
|
|
620
|
+
const rulesChanged = !sameChoices(localOnly, savedLocalOnly);
|
|
621
|
+
const dirty = accountChanged || auto !== (address?.auto ?? false) || rulesChanged || password !== "" || syncKey !== "";
|
|
622
|
+
const nodes = (0, react.useMemo)(() => scopeNodes(entries ?? [], t), [entries, t]);
|
|
623
|
+
const [autoStatus, setAutoStatus] = (0, react.useState)("");
|
|
624
|
+
const addressBusy = saving || snapshot?.status === "loading";
|
|
625
|
+
const active = (0, react.useRef)(null);
|
|
626
|
+
const previewButton = (0, react.useRef)(null);
|
|
627
|
+
const previewHeading = (0, react.useRef)(null);
|
|
628
|
+
(0, react.useRef)(null);
|
|
629
|
+
const feedbackElement = (0, react.useRef)(null);
|
|
630
|
+
const mounted = (0, react.useRef)(false);
|
|
631
|
+
(0, react.useEffect)(() => {
|
|
632
|
+
mounted.current = true;
|
|
633
|
+
return () => {
|
|
634
|
+
mounted.current = false;
|
|
635
|
+
if (active.current && !active.current.applying) active.current.controller.abort();
|
|
636
|
+
};
|
|
637
|
+
}, []);
|
|
638
|
+
(0, react.useEffect)(() => {
|
|
639
|
+
if (!configForm) return void 0;
|
|
640
|
+
setSnapshot(configForm.getSnapshot());
|
|
641
|
+
return configForm.subscribe(() => setSnapshot(configForm.getSnapshot()));
|
|
642
|
+
}, [configForm]);
|
|
643
|
+
(0, react.useEffect)(() => {
|
|
644
|
+
let disposed = false;
|
|
645
|
+
const controller = new AbortController();
|
|
646
|
+
setEntriesError(false);
|
|
647
|
+
setScopeNote(null);
|
|
648
|
+
(async () => {
|
|
649
|
+
try {
|
|
650
|
+
const response = await fetch(endpoint, {
|
|
651
|
+
method: "POST",
|
|
652
|
+
credentials: "same-origin",
|
|
653
|
+
signal: controller.signal,
|
|
654
|
+
headers: {
|
|
655
|
+
"content-type": "application/json",
|
|
656
|
+
"x-dsh-settings-sync": "1"
|
|
657
|
+
},
|
|
658
|
+
body: JSON.stringify({
|
|
659
|
+
direction: "push",
|
|
660
|
+
scope: "settings",
|
|
661
|
+
action: "list"
|
|
662
|
+
})
|
|
663
|
+
});
|
|
664
|
+
const result = await response.json();
|
|
665
|
+
if (!response.ok || !isObject(result) || !Array.isArray(result.entries) || !result.entries.every((entry) => typeof entry === "string")) throw new Error("Invalid scope list");
|
|
666
|
+
const listed = isObject(result.values) ? Object.fromEntries(Object.entries(result.values).filter(([, value]) => typeof value === "string")) : {};
|
|
667
|
+
const stale = Array.isArray(result.stale) ? result.stale.filter((rule) => typeof rule === "string") : [];
|
|
668
|
+
if (!disposed) {
|
|
669
|
+
setEntries([...new Set(result.entries)]);
|
|
670
|
+
setValues(listed);
|
|
671
|
+
setStaleRules(stale);
|
|
672
|
+
}
|
|
673
|
+
} catch (error) {
|
|
674
|
+
if (!disposed && !controller.signal.aborted) {
|
|
675
|
+
setEntries(void 0);
|
|
676
|
+
setEntriesError(true);
|
|
677
|
+
setScopeNote(error instanceof SyntaxError ? "scopeListInvalid" : "scopeListPartial");
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
})();
|
|
681
|
+
return () => {
|
|
682
|
+
disposed = true;
|
|
683
|
+
controller.abort();
|
|
684
|
+
};
|
|
685
|
+
}, [entriesAttempt, snapshot?.revision]);
|
|
686
|
+
(0, react.useEffect)(() => {
|
|
687
|
+
if (active.current?.scope === "credentials" && !active.current.applying) active.current.controller.abort();
|
|
688
|
+
setPicker(null);
|
|
689
|
+
setPreview((current) => current?.scope === "credentials" ? null : current);
|
|
690
|
+
}, [
|
|
691
|
+
configForm,
|
|
692
|
+
snapshot?.revision,
|
|
693
|
+
address?.url,
|
|
694
|
+
address?.username,
|
|
695
|
+
ref,
|
|
696
|
+
keyRef,
|
|
697
|
+
credentialGeneration
|
|
698
|
+
]);
|
|
699
|
+
(0, react.useEffect)(() => {
|
|
700
|
+
let disposed = false;
|
|
701
|
+
setCredentialInfo(null);
|
|
702
|
+
if (credentials) credentials.describe([.../* @__PURE__ */ new Set([ref, keyRef])]).then((result) => {
|
|
703
|
+
if (!disposed && result.ok) setCredentialInfo(result.value);
|
|
704
|
+
}, () => {});
|
|
705
|
+
return () => {
|
|
706
|
+
disposed = true;
|
|
707
|
+
};
|
|
708
|
+
}, [
|
|
709
|
+
credentials,
|
|
710
|
+
ref,
|
|
711
|
+
keyRef,
|
|
712
|
+
credentialGeneration
|
|
713
|
+
]);
|
|
714
|
+
(0, react.useEffect)(() => {
|
|
715
|
+
if (!address?.auto) {
|
|
716
|
+
setAutoStatus("");
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
setAutoStatus("");
|
|
720
|
+
const controller = new AbortController();
|
|
721
|
+
async function refresh() {
|
|
722
|
+
try {
|
|
723
|
+
const response = await fetch(endpoint, {
|
|
724
|
+
credentials: "same-origin",
|
|
725
|
+
signal: controller.signal,
|
|
726
|
+
headers: { "x-dsh-settings-sync": "1" }
|
|
727
|
+
});
|
|
728
|
+
const status = response.ok ? await response.json() : null;
|
|
729
|
+
if (!controller.signal.aborted) setAutoStatus(isObject(status) && typeof status.summary === "string" ? status.summary : "");
|
|
730
|
+
} catch {
|
|
731
|
+
if (!controller.signal.aborted) setAutoStatus("");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
refresh();
|
|
735
|
+
const timer = setInterval(refresh, 15e3);
|
|
736
|
+
return () => {
|
|
737
|
+
clearInterval(timer);
|
|
738
|
+
controller.abort();
|
|
739
|
+
};
|
|
740
|
+
}, [
|
|
741
|
+
address?.auto,
|
|
742
|
+
address?.url,
|
|
743
|
+
address?.username
|
|
744
|
+
]);
|
|
745
|
+
function edit(field, value) {
|
|
746
|
+
setDraft((current) => ({
|
|
747
|
+
url,
|
|
748
|
+
username,
|
|
749
|
+
auto,
|
|
750
|
+
localOnly,
|
|
751
|
+
revision: current ? current.revision : snapshot?.revision,
|
|
752
|
+
[field]: value
|
|
753
|
+
}));
|
|
754
|
+
setAddressStatus(null);
|
|
755
|
+
setPreview(null);
|
|
756
|
+
setPicker(null);
|
|
757
|
+
setFeedback(null);
|
|
758
|
+
}
|
|
759
|
+
function resetDraft() {
|
|
760
|
+
setSnapshot(configForm?.getSnapshot());
|
|
761
|
+
setDraft(null);
|
|
762
|
+
setPassword("");
|
|
763
|
+
setSyncKey("");
|
|
764
|
+
setAddressStatus(null);
|
|
765
|
+
}
|
|
766
|
+
async function saveAddress(event) {
|
|
767
|
+
event.preventDefault();
|
|
768
|
+
if (!configForm || !address || !snapshot?.writable || addressBusy || active.current || !dirty) return;
|
|
769
|
+
setSaving(true);
|
|
770
|
+
setAddressStatus(null);
|
|
771
|
+
setPreview(null);
|
|
772
|
+
setPicker(null);
|
|
773
|
+
setFeedback(null);
|
|
774
|
+
try {
|
|
775
|
+
const parsed = folderAddress(url.trim());
|
|
776
|
+
if (parsed ? parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.search || parsed.hash : Boolean(address.url || auto && !address.auto)) throw new Error(t("addressHint"));
|
|
777
|
+
const user = username.trim();
|
|
778
|
+
if (/[:\x00-\x1f\x7f]/.test(user)) throw new Error(t("invalidUsername"));
|
|
779
|
+
if (password && !user) throw new Error(t("passwordNeedsUser"));
|
|
780
|
+
const key = syncKey.trim();
|
|
781
|
+
if (syncKey && !/^[a-fA-F0-9]{64}$/.test(key)) throw new Error(t("invalidKey"));
|
|
782
|
+
if ((syncKey || password) && keyRef === ref) throw new Error(t("sameRef"));
|
|
783
|
+
const expected = draft ? draft.revision : snapshot.revision;
|
|
784
|
+
if (configForm.getSnapshot().revision !== expected) throw new Error(t("settingsConflict"));
|
|
785
|
+
const ops = [];
|
|
786
|
+
if (parsed && parsed.href !== (address.url ?? "")) ops.push({
|
|
787
|
+
op: "set",
|
|
788
|
+
path: ["sync", "url"],
|
|
789
|
+
value: parsed.href
|
|
790
|
+
});
|
|
791
|
+
if (rulesChanged) ops.push({
|
|
792
|
+
op: "set",
|
|
793
|
+
path: ["sync", "localOnly"],
|
|
794
|
+
value: [...new Set(localOnly)].sort()
|
|
795
|
+
});
|
|
796
|
+
const autoChanged = auto !== (address.auto ?? false);
|
|
797
|
+
const enableAfterCredentials = autoChanged && auto && Boolean(password || syncKey);
|
|
798
|
+
const autoOp = {
|
|
799
|
+
op: "set",
|
|
800
|
+
path: ["sync", "auto"],
|
|
801
|
+
value: auto
|
|
802
|
+
};
|
|
803
|
+
if (autoChanged && !enableAfterCredentials) ops.push(autoOp);
|
|
804
|
+
if (user !== (address.username ?? "")) ops.push({
|
|
805
|
+
op: "set",
|
|
806
|
+
path: ["sync", "username"],
|
|
807
|
+
value: user
|
|
808
|
+
});
|
|
809
|
+
if (ops.length) {
|
|
810
|
+
if (!await configForm.mutate(ops, expected)) throw new Error(t("settingsConflict"));
|
|
811
|
+
if (mounted.current) setDraft(null);
|
|
812
|
+
}
|
|
813
|
+
if (password) {
|
|
814
|
+
if (!credentials || credentialInfo?.[ref]?.writable === false) throw new Error(t("passwordUnavailable"));
|
|
815
|
+
if (!(await credentials.set(ref, password)).ok) throw new Error(t("passwordWriteFailed"));
|
|
816
|
+
if (mounted.current) setPassword("");
|
|
817
|
+
}
|
|
818
|
+
if (key) {
|
|
819
|
+
if (!credentials || credentialInfo?.[keyRef]?.writable === false) throw new Error(t("passwordUnavailable"));
|
|
820
|
+
if (!(await credentials.set(keyRef, key)).ok) throw new Error(t("keyWriteFailed"));
|
|
821
|
+
if (mounted.current) setSyncKey("");
|
|
822
|
+
}
|
|
823
|
+
if (enableAfterCredentials) {
|
|
824
|
+
const latest = configForm.getSnapshot();
|
|
825
|
+
if (latest.value?.sync?.url !== parsed?.href || (latest.value?.sync?.username ?? "") !== user || !await configForm.mutate([autoOp], latest.revision)) throw new Error(t("settingsConflict"));
|
|
826
|
+
}
|
|
827
|
+
if (!mounted.current) return;
|
|
828
|
+
resetDraft();
|
|
829
|
+
setCredentialGeneration((value) => value + 1);
|
|
830
|
+
setAddressStatus({ error: false });
|
|
831
|
+
} catch (error) {
|
|
832
|
+
if (mounted.current) setAddressStatus({
|
|
833
|
+
error: true,
|
|
834
|
+
message: error instanceof TypeError ? t("addressHint") : error instanceof Error ? error.message : void 0
|
|
835
|
+
});
|
|
836
|
+
} finally {
|
|
837
|
+
if (mounted.current) setSaving(false);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
(0, react.useEffect)(() => {
|
|
841
|
+
if (!pending && document.activeElement === document.body) {
|
|
842
|
+
if (preview) previewHeading.current?.focus();
|
|
843
|
+
else if (feedback) feedbackElement.current?.focus();
|
|
844
|
+
}
|
|
845
|
+
}, [
|
|
846
|
+
pending,
|
|
847
|
+
preview,
|
|
848
|
+
feedback
|
|
849
|
+
]);
|
|
850
|
+
/**
|
|
851
|
+
* 一次同步请求:预览、确认、范围列表都走它。凭据现在跟配置同一次走完,
|
|
852
|
+
* 所以这里不再区分「先列凭据再挑」的旧流程。
|
|
853
|
+
*/
|
|
854
|
+
async function request(intent) {
|
|
855
|
+
if (active.current || addressBusy || dirty || !address?.url) return;
|
|
856
|
+
if ("confirmation" in intent && intent !== preview) return;
|
|
857
|
+
const { scope, direction } = intent;
|
|
858
|
+
const target = {
|
|
859
|
+
scope,
|
|
860
|
+
direction
|
|
861
|
+
};
|
|
862
|
+
const confirmation = "confirmation" in intent ? intent.confirmation : void 0;
|
|
863
|
+
if (configForm?.getSnapshot().revision !== snapshot?.revision) return;
|
|
864
|
+
const controller = new AbortController();
|
|
865
|
+
active.current = {
|
|
866
|
+
controller,
|
|
867
|
+
scope,
|
|
868
|
+
applying: Boolean(confirmation)
|
|
869
|
+
};
|
|
870
|
+
setPending({
|
|
871
|
+
...target,
|
|
872
|
+
phase: confirmation ? "applying" : "previewing"
|
|
873
|
+
});
|
|
874
|
+
setFeedback(null);
|
|
875
|
+
if (!confirmation) setPreview(null);
|
|
876
|
+
try {
|
|
877
|
+
const response = await fetch(endpoint, {
|
|
878
|
+
method: "POST",
|
|
879
|
+
credentials: "same-origin",
|
|
880
|
+
signal: controller.signal,
|
|
881
|
+
headers: {
|
|
882
|
+
"content-type": "application/json",
|
|
883
|
+
"x-dsh-settings-sync": "1"
|
|
884
|
+
},
|
|
885
|
+
body: JSON.stringify({
|
|
886
|
+
...target,
|
|
887
|
+
confirmation
|
|
888
|
+
})
|
|
889
|
+
});
|
|
890
|
+
const result = await response.json();
|
|
891
|
+
if (!mounted.current || controller.signal.aborted) return;
|
|
892
|
+
if (!response.ok) {
|
|
893
|
+
const text = isObject(result) && typeof result.error === "string" ? result.error : t("requestFailed");
|
|
894
|
+
setFeedback({
|
|
895
|
+
...target,
|
|
896
|
+
error: true,
|
|
897
|
+
text
|
|
898
|
+
});
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (!isObject(result) || typeof result.summary !== "string") throw new Error("Invalid sync response");
|
|
902
|
+
const { summary } = result;
|
|
903
|
+
if (typeof result.confirmation === "string" && result.confirmation) {
|
|
904
|
+
setPreview({
|
|
905
|
+
...intent,
|
|
906
|
+
confirmation: result.confirmation,
|
|
907
|
+
summary
|
|
908
|
+
});
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
if (!Array.isArray(result.applied) || !Array.isArray(result.changed)) throw new Error("Invalid sync result");
|
|
912
|
+
setPreview(null);
|
|
913
|
+
setFeedback({
|
|
914
|
+
...target,
|
|
915
|
+
error: result.applied.length < result.changed.length,
|
|
916
|
+
text: summary
|
|
917
|
+
});
|
|
918
|
+
if (mounted.current) {
|
|
919
|
+
setEntries(void 0);
|
|
920
|
+
setValues({});
|
|
921
|
+
setStaleRules([]);
|
|
922
|
+
}
|
|
923
|
+
setEntriesAttempt((value) => value + 1);
|
|
924
|
+
} catch {
|
|
925
|
+
if (controller.signal.aborted || !mounted.current) return;
|
|
926
|
+
setPreview(null);
|
|
927
|
+
const retry = confirmation ? "verifyWrite" : void 0;
|
|
928
|
+
setFeedback({
|
|
929
|
+
...target,
|
|
930
|
+
error: true,
|
|
931
|
+
text: t(confirmation ? "outcomeUnknown" : "requestFailed"),
|
|
932
|
+
...retry && { retry }
|
|
933
|
+
});
|
|
934
|
+
} finally {
|
|
935
|
+
active.current = null;
|
|
936
|
+
if (mounted.current) setPending(null);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
function start(event, target) {
|
|
940
|
+
if (active.current) return;
|
|
941
|
+
previewButton.current = event.currentTarget;
|
|
942
|
+
request({
|
|
943
|
+
scope: "settings",
|
|
944
|
+
direction: target.direction
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
function cancel() {
|
|
948
|
+
setPreview(null);
|
|
949
|
+
setFeedback(null);
|
|
950
|
+
previewButton.current?.focus();
|
|
951
|
+
}
|
|
952
|
+
const readOnly = !address || !snapshot?.writable;
|
|
953
|
+
const fieldDisabled = readOnly || Boolean(addressBusy || pending);
|
|
954
|
+
const passwordDisabled = fieldDisabled || !credentials || credentialInfo?.[ref]?.writable === false;
|
|
955
|
+
const passwordHint = !credentials || credentialInfo?.[ref]?.writable === false ? "passwordUnavailable" : "passwordHint";
|
|
956
|
+
function secretState(name) {
|
|
957
|
+
const info = credentialInfo?.[name];
|
|
958
|
+
return info ? {
|
|
959
|
+
configured: info.configured,
|
|
960
|
+
label: t(info.configured ? "configured" : "notConfigured")
|
|
961
|
+
} : void 0;
|
|
962
|
+
}
|
|
963
|
+
const syncDisabled = !address?.url || dirty || Boolean(addressBusy || pending);
|
|
964
|
+
const actionButton = {
|
|
965
|
+
type: "button",
|
|
966
|
+
variant: "outline",
|
|
967
|
+
size: "sm"
|
|
968
|
+
};
|
|
969
|
+
function syncProgress(scope) {
|
|
970
|
+
return pending?.scope === scope && (0, react.createElement)("div", { role: "status" }, (0, react.createElement)("p", null, t(pending.phase)), (0, react.createElement)("progress", { "aria-label": t(pending.phase) }));
|
|
971
|
+
}
|
|
972
|
+
function syncFeedback(status) {
|
|
973
|
+
return (0, react.createElement)("p", {
|
|
974
|
+
ref: feedbackElement,
|
|
975
|
+
tabIndex: -1,
|
|
976
|
+
className: `${prefix}__summary` + (status.error ? ` ${prefix}__error` : ""),
|
|
977
|
+
role: status.error ? "alert" : "status"
|
|
978
|
+
}, status.text);
|
|
979
|
+
}
|
|
980
|
+
function settingsActions() {
|
|
981
|
+
const scope = "settings";
|
|
982
|
+
const heading = `${prefix}-${scope}-actions`;
|
|
983
|
+
return (0, react.createElement)("section", {
|
|
984
|
+
className: `${prefix}__group`,
|
|
985
|
+
"aria-labelledby": heading
|
|
986
|
+
}, (0, react.createElement)("h3", { id: heading }, t("operations")), (0, react.createElement)("p", { className: `${prefix}__hint` }, t("introduction")), address?.auto && autoStatus && (0, react.createElement)("p", {
|
|
987
|
+
className: `dsh-settings-sync__summary`,
|
|
988
|
+
role: "status"
|
|
989
|
+
}, autoStatus), (0, react.createElement)("div", { className: `${prefix}__actions` }, ...["push", "pull"].map((direction) => (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
990
|
+
...actionButton,
|
|
991
|
+
key: direction,
|
|
992
|
+
disabled: syncDisabled,
|
|
993
|
+
onClick: (event) => start(event, {
|
|
994
|
+
scope,
|
|
995
|
+
direction
|
|
996
|
+
})
|
|
997
|
+
}, t(direction)))), syncProgress(scope), preview?.scope === scope && (0, react.createElement)("div", { className: `dsh-settings-sync__preview` }, (0, react.createElement)("h4", {
|
|
998
|
+
tabIndex: -1,
|
|
999
|
+
ref: previewHeading
|
|
1000
|
+
}, t("preview")), (0, react.createElement)("p", {
|
|
1001
|
+
className: `dsh-settings-sync__summary`,
|
|
1002
|
+
role: "status"
|
|
1003
|
+
}, preview.summary), (0, react.createElement)("div", { className: `dsh-settings-sync__actions` }, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
1004
|
+
...actionButton,
|
|
1005
|
+
onClick: cancel
|
|
1006
|
+
}, t("cancel")), (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
1007
|
+
...actionButton,
|
|
1008
|
+
disabled: syncDisabled,
|
|
1009
|
+
onClick: () => void request(preview)
|
|
1010
|
+
}, t(preview.direction === "push" ? "applyPush" : "applyPull")))), feedback?.scope === scope && syncFeedback(feedback));
|
|
1011
|
+
}
|
|
1012
|
+
return (0, react.createElement)("section", {
|
|
1013
|
+
className: prefix,
|
|
1014
|
+
"aria-label": t("title")
|
|
1015
|
+
}, (0, react.createElement)("style", null, styles), (0, react.createElement)("section", {
|
|
1016
|
+
className: `${prefix}__group`,
|
|
1017
|
+
"aria-labelledby": `${prefix}-connection`
|
|
1018
|
+
}, (0, react.createElement)("h3", { id: `${prefix}-connection` }, t("connection")), (0, react.createElement)("form", {
|
|
1019
|
+
className: `${prefix}__form`,
|
|
1020
|
+
onSubmit: saveAddress
|
|
1021
|
+
}, (0, react.createElement)(SettingRow, {
|
|
1022
|
+
id: `${prefix}-address`,
|
|
1023
|
+
label: t("address"),
|
|
1024
|
+
hint: t("addressHint"),
|
|
1025
|
+
input: {
|
|
1026
|
+
type: "url",
|
|
1027
|
+
required: Boolean(address?.url || auto && !address?.auto),
|
|
1028
|
+
value: url,
|
|
1029
|
+
autoComplete: "off",
|
|
1030
|
+
spellCheck: false,
|
|
1031
|
+
disabled: fieldDisabled,
|
|
1032
|
+
placeholder: "https://dav.example.com/dsh/",
|
|
1033
|
+
onChange: (event) => edit("url", event.currentTarget.value)
|
|
1034
|
+
}
|
|
1035
|
+
}), (0, react.createElement)(SettingRow, {
|
|
1036
|
+
id: `${prefix}-username`,
|
|
1037
|
+
label: t("username"),
|
|
1038
|
+
hint: t("usernameHint"),
|
|
1039
|
+
input: {
|
|
1040
|
+
type: "text",
|
|
1041
|
+
autoComplete: "username",
|
|
1042
|
+
value: username,
|
|
1043
|
+
maxLength: 256,
|
|
1044
|
+
disabled: fieldDisabled,
|
|
1045
|
+
onChange: (event) => edit("username", event.currentTarget.value)
|
|
1046
|
+
}
|
|
1047
|
+
}), (0, react.createElement)(SettingRow, {
|
|
1048
|
+
id: `${prefix}-password`,
|
|
1049
|
+
label: t("password"),
|
|
1050
|
+
hint: t(passwordHint),
|
|
1051
|
+
state: secretState(ref),
|
|
1052
|
+
input: {
|
|
1053
|
+
type: "password",
|
|
1054
|
+
autoComplete: "new-password",
|
|
1055
|
+
value: password,
|
|
1056
|
+
maxLength: 1024,
|
|
1057
|
+
disabled: passwordDisabled,
|
|
1058
|
+
onChange: (event) => {
|
|
1059
|
+
setPassword(event.currentTarget.value);
|
|
1060
|
+
setAddressStatus(null);
|
|
1061
|
+
setPreview(null);
|
|
1062
|
+
setPicker(null);
|
|
1063
|
+
setFeedback(null);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}), (0, react.createElement)(SettingRow, {
|
|
1067
|
+
id: `${prefix}-key`,
|
|
1068
|
+
label: t("syncKey"),
|
|
1069
|
+
hint: t(!credentials || credentialInfo?.[keyRef]?.writable === false ? "passwordUnavailable" : "syncKeyHint"),
|
|
1070
|
+
state: secretState(keyRef),
|
|
1071
|
+
input: {
|
|
1072
|
+
type: "password",
|
|
1073
|
+
autoComplete: "new-password",
|
|
1074
|
+
value: syncKey,
|
|
1075
|
+
disabled: fieldDisabled || !credentials || credentialInfo?.[keyRef]?.writable === false,
|
|
1076
|
+
onChange: (event) => {
|
|
1077
|
+
setSyncKey(event.currentTarget.value);
|
|
1078
|
+
setAddressStatus(null);
|
|
1079
|
+
setPreview(null);
|
|
1080
|
+
setPicker(null);
|
|
1081
|
+
setFeedback(null);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}), (0, react.createElement)("div", { className: `${prefix}__row` }, (0, react.createElement)("div", { className: `${prefix}__row-text` }, (0, react.createElement)("div", { className: `${prefix}__label` }, t("auto")), (0, react.createElement)("div", {
|
|
1085
|
+
id: `${prefix}-auto-hint`,
|
|
1086
|
+
className: `${prefix}__note`
|
|
1087
|
+
}, t("autoHint"))), (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Switch, {
|
|
1088
|
+
className: `${prefix}__switch`,
|
|
1089
|
+
checked: auto,
|
|
1090
|
+
disabled: fieldDisabled,
|
|
1091
|
+
label: t("auto"),
|
|
1092
|
+
describedBy: `${prefix}-auto-hint`,
|
|
1093
|
+
onChange: (checked) => edit("auto", checked)
|
|
1094
|
+
})), (0, react.createElement)("section", {
|
|
1095
|
+
className: `${prefix}__preview`,
|
|
1096
|
+
"aria-labelledby": `${prefix}-scope`
|
|
1097
|
+
}, (0, react.createElement)("h4", { id: `${prefix}-scope` }, t("syncScope")), (0, react.createElement)("p", { className: `${prefix}__hint` }, t("syncScopeHint")), entries === void 0 && !entriesError && (0, react.createElement)("p", { role: "status" }, t("syncScopeLoading")), entriesError && (0, react.createElement)("div", { className: `dsh-settings-sync__actions` }, (0, react.createElement)("p", { role: "alert" }, t("syncScopeFailed")), (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
1098
|
+
type: "button",
|
|
1099
|
+
size: "sm",
|
|
1100
|
+
variant: "outline",
|
|
1101
|
+
onClick: () => {
|
|
1102
|
+
setEntries(void 0);
|
|
1103
|
+
setEntriesAttempt((value) => value + 1);
|
|
1104
|
+
}
|
|
1105
|
+
}, t("retry"))), entries !== void 0 && !entries.length && (0, react.createElement)("p", { role: "status" }, t("syncScopeEmpty")), !entriesError && scopeNote && (0, react.createElement)("p", {
|
|
1106
|
+
className: `dsh-settings-sync__hint`,
|
|
1107
|
+
role: "status"
|
|
1108
|
+
}, t(scopeNote)), (0, react.createElement)(SelectionTree, {
|
|
1109
|
+
kind: "localOnly",
|
|
1110
|
+
t,
|
|
1111
|
+
entries: nodes,
|
|
1112
|
+
values,
|
|
1113
|
+
stale: staleRules,
|
|
1114
|
+
rules: localOnly,
|
|
1115
|
+
disabled: fieldDisabled,
|
|
1116
|
+
labelledBy: `${prefix}-scope`,
|
|
1117
|
+
onChange: (next) => edit("localOnly", next)
|
|
1118
|
+
})), (0, react.createElement)("div", { className: `${prefix}__actions` }, (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
1119
|
+
type: "submit",
|
|
1120
|
+
variant: "primary",
|
|
1121
|
+
size: "sm",
|
|
1122
|
+
disabled: fieldDisabled || !dirty
|
|
1123
|
+
}, t(saving ? "saving" : "save")), (dirty || addressStatus?.error) && (0, react.createElement)(_deepseek_ai_dsh_client_ui_primitives_client.Button, {
|
|
1124
|
+
type: "button",
|
|
1125
|
+
variant: "outline",
|
|
1126
|
+
size: "sm",
|
|
1127
|
+
disabled: Boolean(addressBusy || pending),
|
|
1128
|
+
onClick: resetDraft
|
|
1129
|
+
}, t(addressStatus?.error ? "reloadAddress" : "discard")), address && readOnly && (0, react.createElement)("span", { className: `dsh-settings-sync__hint` }, t("readOnly")), dirty && !addressStatus?.error && (0, react.createElement)("span", { className: `dsh-settings-sync__hint` }, t("dirtyAddress"))), addressStatus && (0, react.createElement)("p", {
|
|
1130
|
+
role: addressStatus.error ? "alert" : "status",
|
|
1131
|
+
className: addressStatus.error ? `dsh-settings-sync__error` : void 0
|
|
1132
|
+
}, addressStatus.error ? addressStatus.message || t("addressError") : t("saved")))), settingsActions());
|
|
1133
|
+
}
|
|
1134
|
+
// src/client/index.ts
|
|
1135
|
+
const slot = "plugins.bundle.config";
|
|
1136
|
+
const inject = ["slots", "locale"];
|
|
1137
|
+
function apply(ctx) {
|
|
1138
|
+
ctx.effect(() => ctx.locale.register(namespace, dictionaries));
|
|
1139
|
+
let credentials;
|
|
1140
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1141
|
+
const getCredentials = () => credentials;
|
|
1142
|
+
const subscribeCredentials = (listener) => {
|
|
1143
|
+
listeners.add(listener);
|
|
1144
|
+
return () => {
|
|
1145
|
+
listeners.delete(listener);
|
|
1146
|
+
};
|
|
1147
|
+
};
|
|
1148
|
+
const setCredentials = (value) => {
|
|
1149
|
+
credentials = value;
|
|
1150
|
+
for (const listener of listeners) listener();
|
|
1151
|
+
};
|
|
1152
|
+
ctx.inject(["remote", "remote.credentials"], (scoped) => {
|
|
1153
|
+
setCredentials(scoped.remote.credentials);
|
|
1154
|
+
return () => setCredentials(void 0);
|
|
1155
|
+
});
|
|
1156
|
+
ctx.inject(["configForms"], (scoped) => {
|
|
1157
|
+
scoped.slots.inject(slot, () => scoped.slots.register({
|
|
1158
|
+
name: slot,
|
|
1159
|
+
key: "@he0119/dsh-settings-sync",
|
|
1160
|
+
locale: namespace,
|
|
1161
|
+
inject: () => ({
|
|
1162
|
+
configForm: scoped.configForms.get("settings-sync"),
|
|
1163
|
+
getCredentials,
|
|
1164
|
+
subscribeCredentials
|
|
1165
|
+
})
|
|
1166
|
+
}, SyncPanel));
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
exports.apply = apply;
|
|
1170
|
+
exports.inject = inject;
|
|
1171
|
+
return module.exports;
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
//# sourceMappingURL=client.js.map
|