@kangyishuai/dsh-session-delete 0.4.9 → 0.6.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/README.md +46 -33
- package/README.zh-CN.md +39 -26
- package/lib/agent-tool.js +39 -3
- package/lib/audit.js +1 -1
- package/lib/client.js +2484 -800
- package/lib/operations.js +725 -152
- package/lib/plan.js +24 -0
- package/lib/preferences.js +90 -0
- package/lib/recovery.js +477 -0
- package/lib/refs.js +217 -6
- package/lib/restore.js +187 -0
- package/lib/service.js +165 -0
- package/lib/trash.js +157 -14
- package/lib/workspace-state.js +63 -0
- package/locale/en.json +91 -44
- package/locale/zh.json +92 -45
- package/package.json +4 -2
package/lib/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// client 半:classic script,以 __ModuleLoader__.load 注册 factory,不能使用 import。
|
|
3
|
-
//
|
|
3
|
+
// 注册面:会话「…」菜单项 + 侧栏页脚回收站入口 + shell.overlay(确认框 / 回收站面板 / toast)
|
|
4
|
+
// + 设置页「会话回收站」分节。
|
|
4
5
|
// 宿主调用走 ctx.connection.rpc.call("/api", ...) —— 无构建插件没有 typert 生成的客户端产物,
|
|
5
6
|
// 因此不能用 ctx.reflect.get("remote.xxx")(见 docs/runtime/0.2.1-rc.5.md §6.10)。
|
|
6
7
|
window.__ModuleLoader__.load({
|
|
@@ -24,6 +25,8 @@ window.__ModuleLoader__.load({
|
|
|
24
25
|
var MenuItemButton = primitives.MenuItemButton;
|
|
25
26
|
var Modal = primitives.Modal;
|
|
26
27
|
var IconTrash = primitives.IconTrashOutlineRegular;
|
|
28
|
+
var PrimitiveCheckbox = primitives.Checkbox;
|
|
29
|
+
var PrimitiveSwitch = primitives.Switch;
|
|
27
30
|
|
|
28
31
|
/** 设计变量(宿主主题 token):深色/浅色自动跟随。 */
|
|
29
32
|
var T = {
|
|
@@ -34,6 +37,7 @@ window.__ModuleLoader__.load({
|
|
|
34
37
|
faint: "var(--dsw-alias-label-tertiary, GrayText)",
|
|
35
38
|
border: "var(--dsw-alias-border-l2, rgba(128,128,128,0.35))",
|
|
36
39
|
hover: "var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,0.12))",
|
|
40
|
+
hoverDanger: "var(--dsw-alias-interactive-bg-hover-danger, rgba(217,83,79,0.16))",
|
|
37
41
|
danger: "var(--dsw-alias-state-error-primary, #d9534f)",
|
|
38
42
|
// 与 danger 成对:反色实心填充必须配宿主的前景色 token,不能写死白。
|
|
39
43
|
// 深色主题下宿主 error 是浅红 #f25a5a,白字只有 3.29:1;配 label-primary-foreground 是 5.75:1。
|
|
@@ -41,70 +45,122 @@ window.__ModuleLoader__.load({
|
|
|
41
45
|
mask: "var(--dsw-alias-bg-mask-1, rgba(0,0,0,0.45))",
|
|
42
46
|
toastBg: "var(--dsw-alias-toast-bg, Canvas)",
|
|
43
47
|
toastText: "var(--dsw-alias-toast-label, CanvasText)",
|
|
48
|
+
brand: "var(--dsw-alias-brand-primary, #4f7cff)",
|
|
44
49
|
radius: "10px",
|
|
45
50
|
};
|
|
46
51
|
|
|
47
52
|
/** locale 命名空间;必须与 locale/*.json 顶层键一致。 */
|
|
48
53
|
var NS = "sessionDelete";
|
|
49
54
|
|
|
50
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* 简体中文词典(键集的事实来源)。
|
|
57
|
+
* 精简原则:确认框正文只讲「删什么、多大、能不能恢复」,
|
|
58
|
+
* 技术细节(引用清单、回收站路径、子会话标题)一律进「详情」。
|
|
59
|
+
*/
|
|
51
60
|
var zh = {
|
|
52
61
|
"menu.delete": "删除会话…",
|
|
53
62
|
"menu.trash": "回收站…",
|
|
54
63
|
"footer.trash": "回收站",
|
|
55
|
-
"confirm.title": "
|
|
64
|
+
"confirm.title": "删除会话?",
|
|
65
|
+
"confirm.desc": "移入本机回收站,可以恢复。",
|
|
56
66
|
"confirm.loading": "正在读取影响面…",
|
|
57
|
-
"confirm.
|
|
58
|
-
"confirm.
|
|
59
|
-
"confirm.
|
|
60
|
-
"confirm.
|
|
61
|
-
"confirm.
|
|
62
|
-
"confirm.
|
|
63
|
-
"confirm.
|
|
67
|
+
"confirm.size": "约 {size}",
|
|
68
|
+
"confirm.live": "正在运行,会先停止",
|
|
69
|
+
"confirm.children": "{n} 个子会话",
|
|
70
|
+
"confirm.cascade": "同时删除这 {n} 个子会话(各自进回收站,需分别恢复)",
|
|
71
|
+
"confirm.refs": "将清理 {n} 处引用",
|
|
72
|
+
"confirm.details": "详情",
|
|
73
|
+
"confirm.detail.refs": "引用:{list}",
|
|
74
|
+
"confirm.detail.children": "子会话:{list}",
|
|
75
|
+
"confirm.detail.trashPath": "回收站:{path}",
|
|
76
|
+
"confirm.detail.recoverable": "可恢复:删除后从回收站还原到原位置",
|
|
64
77
|
"confirm.blocked": "暂时无法删除:{reason}",
|
|
65
78
|
"confirm.cancel": "取消",
|
|
66
79
|
"confirm.confirm": "移入回收站",
|
|
67
80
|
"confirm.pending": "正在移入回收站…",
|
|
68
81
|
"confirm.done": "已移入回收站",
|
|
69
82
|
"confirm.undo": "撤销",
|
|
70
|
-
"confirm.failed": "删除失败",
|
|
71
83
|
"panel.title": "会话回收站",
|
|
72
|
-
"panel.tabTrash": "回收站",
|
|
73
|
-
"panel.tabAudit": "审计",
|
|
74
|
-
"panel.tabHealth": "体检",
|
|
75
|
-
"panel.tabReceipts": "回执",
|
|
76
|
-
"trash.selectAll": "全选",
|
|
77
|
-
"trash.clear": "清空",
|
|
78
|
-
"trash.restoreMany": "批量恢复({n})",
|
|
79
|
-
"trash.purgeMany": "批量彻底删除({n})",
|
|
80
|
-
"trash.purgeManyConfirm": "确认彻底删除 {n} 个?不可恢复",
|
|
81
|
-
"batch.done": "完成:{ok}/{total} 成功",
|
|
82
|
-
"receipts.empty": "还没有操作回执。",
|
|
83
|
-
"receipts.restored": "已移回原位置",
|
|
84
|
-
"health.loading": "正在检查…",
|
|
85
|
-
"health.inventory":
|
|
86
|
-
"已存 {stored} · live {live} · 归档 {archived} · 回收站 {trash} · 待处理 {pending}",
|
|
87
|
-
"health.ok": "未发现失效引用。",
|
|
88
|
-
"health.items": "{n} 条",
|
|
89
|
-
"health.agentTool": "模型工具 session_delete:{state}",
|
|
90
|
-
"health.agentToolOn": "已注册",
|
|
91
|
-
"health.agentToolOff": "未注册(宿主未提供 tools 运行时)",
|
|
92
|
-
"health.unavailable": "无法体检:{reason}",
|
|
93
|
-
"health.clean": "清理失效引用({n})",
|
|
94
|
-
"health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
|
|
95
|
-
"health.cleanDone": "已清理 {n} 条",
|
|
96
84
|
"panel.empty": "回收站是空的。",
|
|
97
|
-
"panel.auditEmpty": "还没有审计记录。",
|
|
98
85
|
"panel.restore": "恢复",
|
|
99
86
|
"panel.purge": "彻底删除",
|
|
100
|
-
"panel.purgeConfirm": "
|
|
101
|
-
"panel.
|
|
102
|
-
"panel.
|
|
87
|
+
"panel.purgeConfirm": "不可恢复,确认",
|
|
88
|
+
"panel.cancelConfirm": "取消",
|
|
89
|
+
"panel.size": "{size}",
|
|
90
|
+
"panel.trashedAt": "{time}",
|
|
103
91
|
"panel.unknown": "{n} 个无法识别的目录已保留",
|
|
104
|
-
"panel.pending": "{n}
|
|
92
|
+
"panel.pending": "{n} 个未完成的操作(重启后自动对账;仍未处理需人工核对)",
|
|
105
93
|
"panel.readOnly": "只读模式:当前 DSH 版本缺少依赖接口,删除功能已禁用。",
|
|
106
94
|
"panel.close": "关闭",
|
|
95
|
+
"receipt.refs": "引用",
|
|
96
|
+
"receipt.removed": "已清理的引用",
|
|
97
|
+
"receipt.checks": "校验",
|
|
98
|
+
"receipt.summary.ok": "全部通过",
|
|
99
|
+
"receipt.summary.partial": "{n} 处未通过",
|
|
100
|
+
"restore.detail.title": "未通过的引用与校验",
|
|
101
|
+
"restore.detail.retry": "重试未通过的引用",
|
|
102
|
+
"restore.detail.retrying": "正在重试…",
|
|
103
|
+
"restore.detail.retried": "已自动重试一次",
|
|
104
|
+
"restore.retry.ok": "重检通过:引用与校验全部恢复",
|
|
105
|
+
"restore.retry.partial": "重检后仍有 {n} 处未通过",
|
|
106
|
+
"restore.busyHint":
|
|
107
|
+
"若发送被拒(提示 session/agent-busy),说明宿主还把这个会话标记为忙碌:重启 DSH,或新建会话继续。",
|
|
108
|
+
"trash.selectAll": "全选",
|
|
109
|
+
"trash.selectCount": "已选 {n}/{total}",
|
|
110
|
+
"trash.restoreMany": "恢复({n})",
|
|
111
|
+
"trash.purgeMany": "彻底删除({n})",
|
|
112
|
+
"trash.purgeManyConfirm": "彻底删除 {n} 个?不可恢复",
|
|
113
|
+
"batch.progress": "处理中 {done}/{total}",
|
|
114
|
+
"batch.stop": "停止",
|
|
115
|
+
"batch.done": "完成:{ok}/{total} 成功",
|
|
116
|
+
"batch.failed": "{n} 个失败,已保留选中",
|
|
117
|
+
"batch.partial": "其中 {n} 条引用未还原",
|
|
107
118
|
"toast.failed": "操作失败:{message}",
|
|
119
|
+
"toast.trashPartial": "已移入回收站,但收尾未完成:{message}(会话可在回收站恢复)",
|
|
120
|
+
"toast.restorePartial": "会话已恢复,但 {n} 处引用/校验未通过(详见操作回执)",
|
|
121
|
+
"toast.undoFailed": "撤销失败:{message}",
|
|
122
|
+
"toast.trashedCurrent": "已移入回收站,可在回收站恢复",
|
|
123
|
+
"toast.restored": "会话已恢复,正在重新打开",
|
|
124
|
+
"toast.restoredMany": "已恢复 {n} 个会话,正在刷新列表",
|
|
125
|
+
"settings.nav": "会话回收站",
|
|
126
|
+
"settings.group.delete": "删除偏好",
|
|
127
|
+
"settings.cascade.title": "记住「同时删除子会话」",
|
|
128
|
+
"settings.cascade.desc": "下次打开删除确认框时沿用上次的勾选状态。",
|
|
129
|
+
"settings.cascade.reset": "重置为默认(不勾选)",
|
|
130
|
+
"settings.cascade.resetDone": "已重置",
|
|
131
|
+
"settings.group.trash": "回收站",
|
|
132
|
+
"settings.trash.summary": "{n} 个会话 · 占用 {size}",
|
|
133
|
+
"settings.trash.open": "打开回收站",
|
|
134
|
+
"settings.group.maintenance": "维护",
|
|
135
|
+
"settings.health.title": "体检",
|
|
136
|
+
"settings.health.desc": "检查指向已不存在会话的登记条目(只读;需要时手动运行)。",
|
|
137
|
+
"settings.health.ok": "未发现失效引用。",
|
|
138
|
+
"settings.health.idle": "尚未体检。点「运行体检」会扫描全库会话(只读)。",
|
|
139
|
+
"settings.health.run": "运行体检",
|
|
140
|
+
"settings.health.items": "{n} 条待清理",
|
|
141
|
+
"settings.health.unavailable": "无法体检:{reason}",
|
|
142
|
+
"settings.health.clean": "清理 {n} 条",
|
|
143
|
+
"settings.health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
|
|
144
|
+
"settings.health.cleaned": "已清理 {n} 条",
|
|
145
|
+
"settings.receipts.title": "操作回执",
|
|
146
|
+
"settings.receipts.empty": "还没有操作回执。",
|
|
147
|
+
"settings.audit.title": "审计日志",
|
|
148
|
+
"settings.audit.empty": "还没有审计记录。",
|
|
149
|
+
"settings.audit.path": "日志文件:{path}",
|
|
150
|
+
"settings.loading": "读取中…",
|
|
151
|
+
"confirm.workspace.title": "删除「{name}」里的全部会话?",
|
|
152
|
+
"confirm.workspace.summary": "{n} 个会话 · 约 {size}",
|
|
153
|
+
"confirm.workspace.live": "{n} 个正在运行,会先停止",
|
|
154
|
+
"confirm.workspace.blocked": "{n} 个暂时无法删除,会逐条报出来",
|
|
155
|
+
"confirm.workspace.missing": "{n} 个登记条目已失效,已忽略",
|
|
156
|
+
"confirm.workspace.confirm": "移入回收站({n})",
|
|
157
|
+
"confirm.detail.workspaceSessions": "会话:{list}",
|
|
158
|
+
"menu.workspaceTrash": "删除此工作区的全部会话…",
|
|
159
|
+
"toast.workspace.done": "已移入回收站 {ok}/{total} 个会话",
|
|
160
|
+
"shortcut.delete": "删除当前会话…",
|
|
161
|
+
"shortcut.workspace": "删除当前工作区的全部会话…",
|
|
162
|
+
"shortcut.noSession": "没有可以删除的当前会话",
|
|
163
|
+
"shortcut.busy": "删除确认框已经打开",
|
|
108
164
|
};
|
|
109
165
|
|
|
110
166
|
/** English dictionary(键集与 zh 完全一致)。 */
|
|
@@ -112,60 +168,112 @@ window.__ModuleLoader__.load({
|
|
|
112
168
|
"menu.delete": "Delete session…",
|
|
113
169
|
"menu.trash": "Trash…",
|
|
114
170
|
"footer.trash": "Trash",
|
|
115
|
-
"confirm.title": "Delete
|
|
171
|
+
"confirm.title": "Delete session?",
|
|
172
|
+
"confirm.desc": "Moves to the local trash and can be restored.",
|
|
116
173
|
"confirm.loading": "Reading what will be removed…",
|
|
117
|
-
"confirm.
|
|
118
|
-
"confirm.
|
|
119
|
-
"confirm.
|
|
120
|
-
"confirm.children": "{n} subagent session(s) come along",
|
|
174
|
+
"confirm.size": "about {size}",
|
|
175
|
+
"confirm.live": "running; its work stops first",
|
|
176
|
+
"confirm.children": "{n} subagent session(s)",
|
|
121
177
|
"confirm.cascade": "Also delete these {n} child session(s) (each goes to trash separately)",
|
|
122
|
-
"confirm.refs": "
|
|
123
|
-
"confirm.
|
|
178
|
+
"confirm.refs": "Cleans {n} reference(s)",
|
|
179
|
+
"confirm.details": "Details",
|
|
180
|
+
"confirm.detail.refs": "References: {list}",
|
|
181
|
+
"confirm.detail.children": "Child sessions: {list}",
|
|
182
|
+
"confirm.detail.trashPath": "Trash: {path}",
|
|
183
|
+
"confirm.detail.recoverable":
|
|
184
|
+
"Recoverable: restore from the trash back to its original place",
|
|
124
185
|
"confirm.blocked": "Cannot delete right now: {reason}",
|
|
125
186
|
"confirm.cancel": "Cancel",
|
|
126
187
|
"confirm.confirm": "Move to trash",
|
|
127
188
|
"confirm.pending": "Moving to trash…",
|
|
128
189
|
"confirm.done": "Moved to trash",
|
|
129
190
|
"confirm.undo": "Undo",
|
|
130
|
-
"confirm.failed": "Deletion failed",
|
|
131
191
|
"panel.title": "Session trash",
|
|
132
|
-
"panel.tabTrash": "Trash",
|
|
133
|
-
"panel.tabAudit": "Audit",
|
|
134
|
-
"panel.tabHealth": "Health",
|
|
135
|
-
"panel.tabReceipts": "Receipts",
|
|
136
|
-
"trash.selectAll": "Select all",
|
|
137
|
-
"trash.clear": "Clear",
|
|
138
|
-
"trash.restoreMany": "Restore {n}",
|
|
139
|
-
"trash.purgeMany": "Delete {n} permanently",
|
|
140
|
-
"trash.purgeManyConfirm": "Permanently delete {n}? This cannot be undone",
|
|
141
|
-
"batch.done": "Done: {ok}/{total} succeeded",
|
|
142
|
-
"receipts.empty": "No operation receipts yet.",
|
|
143
|
-
"receipts.restored": "restored",
|
|
144
|
-
"health.loading": "Checking…",
|
|
145
|
-
"health.inventory":
|
|
146
|
-
"stored {stored} · live {live} · archived {archived} · trash {trash} · pending {pending}",
|
|
147
|
-
"health.ok": "No dangling references found.",
|
|
148
|
-
"health.items": "{n} item(s)",
|
|
149
|
-
"health.agentTool": "Agent tool session_delete: {state}",
|
|
150
|
-
"health.agentToolOn": "registered",
|
|
151
|
-
"health.agentToolOff": "not registered (host has no tools runtime)",
|
|
152
|
-
"health.unavailable": "Cannot run the check: {reason}",
|
|
153
|
-
"health.clean": "Clean dangling references ({n})",
|
|
154
|
-
"health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only, no session files.",
|
|
155
|
-
"health.cleanDone": "Cleaned {n}",
|
|
156
192
|
"panel.empty": "The trash is empty.",
|
|
157
|
-
"panel.auditEmpty": "No audit entries yet.",
|
|
158
193
|
"panel.restore": "Restore",
|
|
159
194
|
"panel.purge": "Delete for good",
|
|
160
|
-
"panel.purgeConfirm": "
|
|
195
|
+
"panel.purgeConfirm": "Cannot be undone — confirm",
|
|
196
|
+
"panel.cancelConfirm": "Cancel",
|
|
161
197
|
"panel.size": "{size}",
|
|
162
|
-
"panel.trashedAt": "
|
|
198
|
+
"panel.trashedAt": "{time}",
|
|
163
199
|
"panel.unknown": "{n} unrecognized director(ies) kept",
|
|
164
|
-
"panel.pending":
|
|
200
|
+
"panel.pending":
|
|
201
|
+
"{n} unfinished operation(s) (reconciled on next start; leftovers need review)",
|
|
165
202
|
"panel.readOnly":
|
|
166
203
|
"Read-only: this DSH version is missing required APIs; deletion is disabled.",
|
|
167
204
|
"panel.close": "Close",
|
|
205
|
+
"receipt.refs": "References",
|
|
206
|
+
"receipt.removed": "References cleaned",
|
|
207
|
+
"receipt.checks": "Checks",
|
|
208
|
+
"receipt.summary.ok": "all passed",
|
|
209
|
+
"receipt.summary.partial": "{n} did not pass",
|
|
210
|
+
"restore.detail.title": "References and checks that did not pass",
|
|
211
|
+
"restore.detail.retry": "Retry the failed references",
|
|
212
|
+
"restore.detail.retrying": "Retrying…",
|
|
213
|
+
"restore.detail.retried": "retried once automatically",
|
|
214
|
+
"restore.retry.ok": "Re-check passed: every reference and check recovered",
|
|
215
|
+
"restore.retry.partial": "{n} still did not pass after the re-check",
|
|
216
|
+
"restore.busyHint":
|
|
217
|
+
"If sending is rejected (session/agent-busy), the host still marks this session busy: restart DSH, or continue in a new session.",
|
|
218
|
+
"trash.selectAll": "Select all",
|
|
219
|
+
"trash.selectCount": "{n}/{total} selected",
|
|
220
|
+
"trash.restoreMany": "Restore ({n})",
|
|
221
|
+
"trash.purgeMany": "Delete {n} permanently",
|
|
222
|
+
"trash.purgeManyConfirm": "Permanently delete {n}? This cannot be undone",
|
|
223
|
+
"batch.progress": "{done}/{total} done",
|
|
224
|
+
"batch.stop": "Stop",
|
|
225
|
+
"batch.done": "Done: {ok}/{total} succeeded",
|
|
226
|
+
"batch.failed": "{n} failed; kept selected",
|
|
227
|
+
"batch.partial": "{n} restored with incomplete references",
|
|
168
228
|
"toast.failed": "Operation failed: {message}",
|
|
229
|
+
"toast.trashPartial":
|
|
230
|
+
"Moved to the trash, but cleanup did not finish: {message} (the session is restorable)",
|
|
231
|
+
"toast.restorePartial":
|
|
232
|
+
"Session restored, but {n} reference/check(s) did not pass (see the receipt)",
|
|
233
|
+
"toast.undoFailed": "Undo failed: {message}",
|
|
234
|
+
"toast.trashedCurrent": "Moved to the trash — restore it from there",
|
|
235
|
+
"toast.restored": "Session restored — reopening it",
|
|
236
|
+
"toast.restoredMany": "Restored {n} session(s); refreshing the list",
|
|
237
|
+
"settings.nav": "Session trash",
|
|
238
|
+
"settings.group.delete": "Deletion preferences",
|
|
239
|
+
"settings.cascade.title": 'Remember "also delete child sessions"',
|
|
240
|
+
"settings.cascade.desc": "The next delete confirmation starts from your last choice.",
|
|
241
|
+
"settings.cascade.reset": "Reset to default (unchecked)",
|
|
242
|
+
"settings.cascade.resetDone": "Reset",
|
|
243
|
+
"settings.group.trash": "Trash",
|
|
244
|
+
"settings.trash.summary": "{n} session(s) · {size}",
|
|
245
|
+
"settings.trash.open": "Open trash",
|
|
246
|
+
"settings.group.maintenance": "Maintenance",
|
|
247
|
+
"settings.health.title": "Health",
|
|
248
|
+
"settings.health.desc":
|
|
249
|
+
"Checks bookkeeping that points at sessions that no longer exist (read-only; run it on demand).",
|
|
250
|
+
"settings.health.ok": "No dangling references found.",
|
|
251
|
+
"settings.health.idle": "No check yet. Run it to scan the whole library (read-only).",
|
|
252
|
+
"settings.health.run": "Run check",
|
|
253
|
+
"settings.health.items": "{n} to clean",
|
|
254
|
+
"settings.health.unavailable": "Cannot run the check: {reason}",
|
|
255
|
+
"settings.health.clean": "Clean {n}",
|
|
256
|
+
"settings.health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only.",
|
|
257
|
+
"settings.health.cleaned": "Cleaned {n}",
|
|
258
|
+
"settings.receipts.title": "Receipts",
|
|
259
|
+
"settings.receipts.empty": "No operation receipts yet.",
|
|
260
|
+
"settings.audit.title": "Audit log",
|
|
261
|
+
"settings.audit.empty": "No audit entries yet.",
|
|
262
|
+
"settings.audit.path": "Log file: {path}",
|
|
263
|
+
"settings.loading": "Loading…",
|
|
264
|
+
"confirm.workspace.title": 'Delete every session in "{name}"?',
|
|
265
|
+
"confirm.workspace.summary": "{n} session(s) · about {size}",
|
|
266
|
+
"confirm.workspace.live": "{n} running; their work stops first",
|
|
267
|
+
"confirm.workspace.blocked": "{n} cannot be deleted right now and will be reported",
|
|
268
|
+
"confirm.workspace.missing": "{n} stale bookkeeping entr(ies) ignored",
|
|
269
|
+
"confirm.workspace.confirm": "Move {n} to trash",
|
|
270
|
+
"confirm.detail.workspaceSessions": "Sessions: {list}",
|
|
271
|
+
"menu.workspaceTrash": "Delete all sessions in this workspace…",
|
|
272
|
+
"toast.workspace.done": "Moved {ok}/{total} session(s) to the trash",
|
|
273
|
+
"shortcut.delete": "Delete current session…",
|
|
274
|
+
"shortcut.workspace": "Delete every session in the current workspace…",
|
|
275
|
+
"shortcut.noSession": "No current session to delete",
|
|
276
|
+
"shortcut.busy": "A delete confirmation is already open",
|
|
169
277
|
};
|
|
170
278
|
|
|
171
279
|
/** @param {any} initial @returns {any} */
|
|
@@ -193,21 +301,28 @@ window.__ModuleLoader__.load({
|
|
|
193
301
|
return [React.useSyncExternalStore(store.subscribe, store.getSnapshot), store.set];
|
|
194
302
|
}
|
|
195
303
|
|
|
196
|
-
/**
|
|
304
|
+
/** 主题化按钮:hover / active / focus-visible 由注入的 CSS 类提供,不依赖合成事件。 */
|
|
197
305
|
/** 主题化按钮:hover / active / focus-visible 由注入的 CSS 类提供,不依赖合成事件。 */
|
|
198
306
|
function Btn(/** @type {any} */ props) {
|
|
307
|
+
var variant = props.variant === "danger" ? " dsh-sdel-btn--danger" : "";
|
|
308
|
+
var quiet = props.variant === "quiet" ? " dsh-sdel-btn--quiet" : "";
|
|
199
309
|
return h(
|
|
200
310
|
"button",
|
|
201
311
|
{
|
|
202
312
|
type: "button",
|
|
203
|
-
|
|
313
|
+
ref: props.innerRef,
|
|
204
314
|
disabled: props.disabled,
|
|
315
|
+
title: props.title,
|
|
316
|
+
"aria-label": props.ariaLabel,
|
|
317
|
+
"data-modal-autofocus": props.modalAutofocus ? "" : undefined,
|
|
318
|
+
// 稳定的动作锚点:冒烟/桌面回归按它定位,不再依赖 CSS class 或文案。
|
|
319
|
+
"data-session-delete-action": props.action,
|
|
205
320
|
onClick: props.onClick,
|
|
206
|
-
className: `dsh-sdel-btn${props.
|
|
321
|
+
className: `dsh-sdel-btn${variant}${quiet}${props.tight ? " dsh-sdel-btn--tight" : ""}`,
|
|
207
322
|
style: {
|
|
208
|
-
padding: "6px 14px",
|
|
323
|
+
padding: props.tight ? "2px 8px" : "6px 14px",
|
|
209
324
|
borderRadius: "8px",
|
|
210
|
-
fontSize: "13px",
|
|
325
|
+
fontSize: props.tight ? "12px" : "13px",
|
|
211
326
|
cursor: props.disabled ? "not-allowed" : "pointer",
|
|
212
327
|
opacity: props.disabled ? 0.45 : 1,
|
|
213
328
|
},
|
|
@@ -216,6 +331,122 @@ window.__ModuleLoader__.load({
|
|
|
216
331
|
);
|
|
217
332
|
}
|
|
218
333
|
|
|
334
|
+
/** 复选框:优先宿主原语(尺寸/焦点环与设置页一致),缺失时回退到原生 input。 */
|
|
335
|
+
function Check(/** @type {any} */ props) {
|
|
336
|
+
if (typeof PrimitiveCheckbox === "function") {
|
|
337
|
+
return h(PrimitiveCheckbox, {
|
|
338
|
+
checked: props.checked === true,
|
|
339
|
+
disabled: props.disabled === true,
|
|
340
|
+
label: props.label,
|
|
341
|
+
onChange: props.onChange,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return h(
|
|
345
|
+
"label",
|
|
346
|
+
{ style: { display: "inline-flex", alignItems: "center", gap: "6px", cursor: "pointer" } },
|
|
347
|
+
h("input", {
|
|
348
|
+
type: "checkbox",
|
|
349
|
+
checked: props.checked === true,
|
|
350
|
+
disabled: props.disabled === true,
|
|
351
|
+
onChange: (/** @type {any} */ event) => props.onChange?.(event.target.checked),
|
|
352
|
+
}),
|
|
353
|
+
props.label ? h("span", null, props.label) : null,
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** 开关:优先宿主原语,缺失时回退到复选框。 */
|
|
358
|
+
function Toggle(/** @type {any} */ props) {
|
|
359
|
+
if (typeof PrimitiveSwitch === "function") {
|
|
360
|
+
return h(PrimitiveSwitch, {
|
|
361
|
+
checked: props.checked === true,
|
|
362
|
+
disabled: props.disabled === true,
|
|
363
|
+
label: props.label,
|
|
364
|
+
onChange: props.onChange,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
return h(Check, props);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** 折叠三角:纯文本字形,避免依赖宿主图标名(缺失时不会变成空白)。 */
|
|
371
|
+
function Caret(/** @type {any} */ props) {
|
|
372
|
+
return h(
|
|
373
|
+
"span",
|
|
374
|
+
{
|
|
375
|
+
"aria-hidden": "true",
|
|
376
|
+
style: {
|
|
377
|
+
display: "inline-block",
|
|
378
|
+
width: "10px",
|
|
379
|
+
color: T.faint,
|
|
380
|
+
transform: props.open ? "rotate(90deg)" : "none",
|
|
381
|
+
transition: "transform 120ms ease",
|
|
382
|
+
fontSize: "10px",
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
"▶",
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** 一行可折叠的「标题 + 说明 + 右侧控件」。 */
|
|
390
|
+
function SettingRow(/** @type {any} */ props) {
|
|
391
|
+
return h(
|
|
392
|
+
"div",
|
|
393
|
+
{
|
|
394
|
+
className: "dsh-sdel-setting-row",
|
|
395
|
+
"data-session-delete-setting-row": props.anchor,
|
|
396
|
+
},
|
|
397
|
+
h(
|
|
398
|
+
"div",
|
|
399
|
+
{ className: "dsh-sdel-setting-text" },
|
|
400
|
+
h("div", { className: "dsh-sdel-setting-title" }, props.title),
|
|
401
|
+
props.description
|
|
402
|
+
? h("div", { className: "dsh-sdel-setting-desc" }, props.description)
|
|
403
|
+
: null,
|
|
404
|
+
props.children,
|
|
405
|
+
),
|
|
406
|
+
props.action ? h("div", { className: "dsh-sdel-setting-action" }, props.action) : null,
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** 折叠区:默认关闭,展开后限高滚动 —— 长列表不会把弹窗/设置页撑长。 */
|
|
411
|
+
function Disclosure(/** @type {any} */ props) {
|
|
412
|
+
var state = React.useState(false);
|
|
413
|
+
var open = state[0];
|
|
414
|
+
var setOpen = state[1];
|
|
415
|
+
return h(
|
|
416
|
+
React.Fragment,
|
|
417
|
+
null,
|
|
418
|
+
h(
|
|
419
|
+
"button",
|
|
420
|
+
{
|
|
421
|
+
type: "button",
|
|
422
|
+
className: "dsh-sdel-disclosure",
|
|
423
|
+
"data-session-delete-disclosure": props.anchor,
|
|
424
|
+
"aria-expanded": open ? "true" : "false",
|
|
425
|
+
onClick: () => setOpen(!open),
|
|
426
|
+
},
|
|
427
|
+
h(Caret, { open: open }),
|
|
428
|
+
h("span", null, props.label),
|
|
429
|
+
props.meta ? h("span", { className: "dsh-sdel-disclosure-meta" }, props.meta) : null,
|
|
430
|
+
),
|
|
431
|
+
open
|
|
432
|
+
? h(
|
|
433
|
+
"div",
|
|
434
|
+
{
|
|
435
|
+
style: {
|
|
436
|
+
maxHeight: props.maxHeight || "220px",
|
|
437
|
+
overflowY: "auto",
|
|
438
|
+
padding: "2px 0 8px 16px",
|
|
439
|
+
color: T.dim,
|
|
440
|
+
fontSize: "12px",
|
|
441
|
+
lineHeight: 1.7,
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
props.children,
|
|
445
|
+
)
|
|
446
|
+
: null,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
219
450
|
/** 挂载时淡入的容器:官方 Modal 没有明确的入场过渡时,用它补齐。 */
|
|
220
451
|
function Reveal(/** @type {any} */ props) {
|
|
221
452
|
const state = React.useState(false);
|
|
@@ -258,11 +489,7 @@ window.__ModuleLoader__.load({
|
|
|
258
489
|
description: props.description,
|
|
259
490
|
footer: props.footer,
|
|
260
491
|
},
|
|
261
|
-
h(
|
|
262
|
-
Reveal,
|
|
263
|
-
{ style: { maxHeight: "60vh", overflowY: "auto", paddingRight: "4px" } },
|
|
264
|
-
props.children,
|
|
265
|
-
),
|
|
492
|
+
h(Reveal, null, props.children),
|
|
266
493
|
);
|
|
267
494
|
}
|
|
268
495
|
return h(
|
|
@@ -283,7 +510,7 @@ window.__ModuleLoader__.load({
|
|
|
283
510
|
},
|
|
284
511
|
h(
|
|
285
512
|
Reveal,
|
|
286
|
-
{ style: { width: "min(
|
|
513
|
+
{ style: { width: "min(480px, 92vw)" } },
|
|
287
514
|
h(
|
|
288
515
|
"div",
|
|
289
516
|
{
|
|
@@ -334,6 +561,58 @@ window.__ModuleLoader__.load({
|
|
|
334
561
|
);
|
|
335
562
|
}
|
|
336
563
|
|
|
564
|
+
/**
|
|
565
|
+
* 中文/英文共用的列表连接符:把数组拼成一行,超过 max 条时补省略号。
|
|
566
|
+
* @param {any[]} items
|
|
567
|
+
* @param {number} [max]
|
|
568
|
+
* @returns {string}
|
|
569
|
+
*/
|
|
570
|
+
function joinList(items, max = 6) {
|
|
571
|
+
var list = (Array.isArray(items) ? items : []).map((/** @type {any} */ item) =>
|
|
572
|
+
String(
|
|
573
|
+
item && typeof item === "object" ? (item.label ?? item.title ?? item.id ?? "") : item,
|
|
574
|
+
),
|
|
575
|
+
);
|
|
576
|
+
var shown = list.slice(0, max);
|
|
577
|
+
return shown.join(" · ") + (list.length > max ? " …" : "");
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* 把数组切成固定大小的批次:回收站 80 条时一次 RPC 会被宿主上限拒绝,
|
|
582
|
+
* 界面必须分批并把进度显示出来(0.4.x 的 bug:整单被拒,看起来像没反应)。
|
|
583
|
+
* @param {any[]} items
|
|
584
|
+
* @param {number} size
|
|
585
|
+
* @returns {any[][]}
|
|
586
|
+
*/
|
|
587
|
+
function chunk(items, size) {
|
|
588
|
+
var step = Math.max(1, Math.floor(size) || 1);
|
|
589
|
+
/** @type {any[][]} */
|
|
590
|
+
var out = [];
|
|
591
|
+
for (let index = 0; index < (items || []).length; index += step) {
|
|
592
|
+
out.push(items.slice(index, index + step));
|
|
593
|
+
}
|
|
594
|
+
return out;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* 确认框正文的一行影响面:只拼成立的事实,用 `·` 分隔。
|
|
599
|
+
* 空值不进数组 —— 这是「不显示占位行」这条规则的单点实现。
|
|
600
|
+
* @param {{ sizeBytes?: number, live?: boolean, children?: any[] }} plan
|
|
601
|
+
* @param {(key: string, values?: any) => string} t
|
|
602
|
+
* @returns {string}
|
|
603
|
+
*/
|
|
604
|
+
function impactLine(plan, t) {
|
|
605
|
+
/** @type {string[]} */
|
|
606
|
+
var facts = [];
|
|
607
|
+
if (plan && typeof plan.sizeBytes === "number") {
|
|
608
|
+
facts.push(t("confirm.size", { size: formatBytes(plan.sizeBytes) }));
|
|
609
|
+
}
|
|
610
|
+
var children = Array.isArray(plan?.children) ? plan.children.length : 0;
|
|
611
|
+
if (children > 0) facts.push(t("confirm.children", { n: children }));
|
|
612
|
+
if (plan?.live) facts.push(t("confirm.live"));
|
|
613
|
+
return facts.join(" · ");
|
|
614
|
+
}
|
|
615
|
+
|
|
337
616
|
function formatBytes(/** @type {any} */ bytes) {
|
|
338
617
|
if (typeof bytes !== "number" || bytes < 0) return "?";
|
|
339
618
|
if (bytes < 1024) return `${Math.round(bytes)} B`;
|
|
@@ -367,6 +646,137 @@ window.__ModuleLoader__.load({
|
|
|
367
646
|
return String(error);
|
|
368
647
|
}
|
|
369
648
|
|
|
649
|
+
/**
|
|
650
|
+
* 「会话已进回收站、只是收尾没做完」(AUD-SD-03)。
|
|
651
|
+
* RPC 的 RemoteError 会保留 details;同时容忍 partial 直接挂在错误上。
|
|
652
|
+
* @param {any} reason
|
|
653
|
+
*/
|
|
654
|
+
function isPartialFailure(reason) {
|
|
655
|
+
if (!reason || typeof reason !== "object") return false;
|
|
656
|
+
if (reason.code === "session-delete/partial") return true;
|
|
657
|
+
if (reason.partial === true) return true;
|
|
658
|
+
return reason.details?.partial === true;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* 删除失败要按磁盘事实说话:已进回收站但收尾失败 ≠ 删除失败。
|
|
663
|
+
* @param {any} reason
|
|
664
|
+
* @param {(key: string, values?: any) => string} t
|
|
665
|
+
*/
|
|
666
|
+
function trashFailureText(reason, t) {
|
|
667
|
+
if (isPartialFailure(reason)) return t("toast.trashPartial", { message: errorText(reason) });
|
|
668
|
+
return errorText(reason);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* 恢复的收尾提示:引用/校验没全过时返回一句「哪里不完整」,全过时返回 null。
|
|
673
|
+
* @param {any} result
|
|
674
|
+
* @param {(key: string, values?: any) => string} t
|
|
675
|
+
* @returns {string | null}
|
|
676
|
+
*/
|
|
677
|
+
function restoreNotice(result, t) {
|
|
678
|
+
var failedRefs = Array.isArray(result?.refs)
|
|
679
|
+
? result.refs.filter((/** @type {any} */ item) => item.status === "failed").length
|
|
680
|
+
: 0;
|
|
681
|
+
var failedChecks = Array.isArray(result?.checks)
|
|
682
|
+
? result.checks.filter((/** @type {any} */ item) => item.status === "failed").length
|
|
683
|
+
: 0;
|
|
684
|
+
var count = failedRefs + failedChecks;
|
|
685
|
+
if (result?.partial === true && count === 0) count = 1;
|
|
686
|
+
if (count === 0) return null;
|
|
687
|
+
return t("toast.restorePartial", { n: count });
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* 恢复结果里「没通过」的逐项清单(USIM-U3-05):引用在前、校验在后。
|
|
692
|
+
* 新宿主直接给 `failures`(带 label/detail);老宿主只有 refs/checks,
|
|
693
|
+
* 这里按同一形状兜底,界面不用关心宿主版本。
|
|
694
|
+
* @param {any} result
|
|
695
|
+
* @returns {{ id: string, label: string, detail: string, kind: "ref" | "check" }[]}
|
|
696
|
+
*/
|
|
697
|
+
function restoreFailures(result) {
|
|
698
|
+
/** @type {{ id: string, label: string, detail: string, kind: "ref" | "check" }[]} */
|
|
699
|
+
var out = [];
|
|
700
|
+
var failures = Array.isArray(result?.failures) ? result.failures : null;
|
|
701
|
+
/** @type {any} */
|
|
702
|
+
var item;
|
|
703
|
+
/** @type {any} */
|
|
704
|
+
var group;
|
|
705
|
+
/** @type {any} */
|
|
706
|
+
var entry;
|
|
707
|
+
if (failures) {
|
|
708
|
+
for (let index = 0; index < failures.length; index += 1) {
|
|
709
|
+
item = failures[index] || {};
|
|
710
|
+
out.push({
|
|
711
|
+
id: String(item.id || ""),
|
|
712
|
+
label: String(item.label || item.id || ""),
|
|
713
|
+
detail: String(item.detail || ""),
|
|
714
|
+
kind: "ref",
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
return out;
|
|
718
|
+
}
|
|
719
|
+
/** @type {{ list: any[] | undefined, kind: "ref" | "check" }[]} */
|
|
720
|
+
var groups = [
|
|
721
|
+
{ list: result?.refs, kind: "ref" },
|
|
722
|
+
{ list: result?.checks, kind: "check" },
|
|
723
|
+
];
|
|
724
|
+
for (let groupIndex = 0; groupIndex < groups.length; groupIndex += 1) {
|
|
725
|
+
group = groups[groupIndex];
|
|
726
|
+
if (!Array.isArray(group.list)) continue;
|
|
727
|
+
for (let itemIndex = 0; itemIndex < group.list.length; itemIndex += 1) {
|
|
728
|
+
entry = group.list[itemIndex] || {};
|
|
729
|
+
if (entry.status !== "failed") continue;
|
|
730
|
+
out.push({
|
|
731
|
+
id: String(entry.id || ""),
|
|
732
|
+
label: String(entry.label || entry.id || ""),
|
|
733
|
+
detail: String(entry.detail || ""),
|
|
734
|
+
kind: group.kind,
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return out;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* 恢复失败时给界面看的多行文本:哪一处没通过 + 下一步做什么。
|
|
743
|
+
* @param {{ label: string, detail: string }[]} failures
|
|
744
|
+
* @returns {string | null}
|
|
745
|
+
*/
|
|
746
|
+
function restoreDetailText(failures) {
|
|
747
|
+
if (!Array.isArray(failures) || failures.length === 0) return null;
|
|
748
|
+
var lines = [];
|
|
749
|
+
/** @type {any} */
|
|
750
|
+
var item;
|
|
751
|
+
for (let index = 0; index < failures.length; index += 1) {
|
|
752
|
+
item = failures[index];
|
|
753
|
+
lines.push(item.label ? `${item.label}:${item.detail}` : item.detail);
|
|
754
|
+
}
|
|
755
|
+
return lines.join("\n");
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* 删除当前正在看的会话后该去哪(USIM-U2-05):优先下一个可用会话,没有就回新会话页。
|
|
760
|
+
* 纯函数,便于单测钉住「不要把人留在已删除的会话上」。
|
|
761
|
+
* @param {{ deletedId?: string | null, currentId?: string | null, candidates?: string[] }} input
|
|
762
|
+
* @returns {{ navigate: boolean, target: "session" | "home" | "none", id?: string }}
|
|
763
|
+
*/
|
|
764
|
+
function afterTrashNavigation(input) {
|
|
765
|
+
var deletedId = typeof input?.deletedId === "string" ? input.deletedId : "";
|
|
766
|
+
var currentId = typeof input?.currentId === "string" ? input.currentId : "";
|
|
767
|
+
if (!deletedId || currentId !== deletedId) return { navigate: false, target: "none" };
|
|
768
|
+
var candidates = Array.isArray(input?.candidates) ? input.candidates : [];
|
|
769
|
+
/** @type {any} */
|
|
770
|
+
var id;
|
|
771
|
+
for (let index = 0; index < candidates.length; index += 1) {
|
|
772
|
+
id = candidates[index];
|
|
773
|
+
if (typeof id === "string" && id.length > 0 && id !== deletedId) {
|
|
774
|
+
return { navigate: true, target: "session", id: id };
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return { navigate: true, target: "home" };
|
|
778
|
+
}
|
|
779
|
+
|
|
370
780
|
function DeleteSessionMenuItem(/** @type {any} */ props) {
|
|
371
781
|
var menuState =
|
|
372
782
|
typeof props.useMenuOpenState === "function" ? props.useMenuOpenState() : [false, () => {}];
|
|
@@ -392,19 +802,8 @@ window.__ModuleLoader__.load({
|
|
|
392
802
|
{
|
|
393
803
|
type: "button",
|
|
394
804
|
onClick: onSelect,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
width: "100%",
|
|
398
|
-
textAlign: "left",
|
|
399
|
-
padding: "6px 12px",
|
|
400
|
-
border: "none",
|
|
401
|
-
borderRadius: "6px",
|
|
402
|
-
background: "transparent",
|
|
403
|
-
color: T.danger,
|
|
404
|
-
cursor: "pointer",
|
|
405
|
-
fontSize: "13px",
|
|
406
|
-
transition: "background-color .15s ease",
|
|
407
|
-
},
|
|
805
|
+
className: "dsh-sdel-btn dsh-sdel-btn--danger",
|
|
806
|
+
style: { display: "block", width: "100%", textAlign: "left", padding: "6px 12px" },
|
|
408
807
|
},
|
|
409
808
|
props.t("menu.delete"),
|
|
410
809
|
);
|
|
@@ -423,7 +822,10 @@ window.__ModuleLoader__.load({
|
|
|
423
822
|
.then((/** @type {any} */ value) => {
|
|
424
823
|
setCount(value?.entries ? value.entries.length : 0);
|
|
425
824
|
})
|
|
426
|
-
.catch(() =>
|
|
825
|
+
.catch(() => {
|
|
826
|
+
// 计数拿不到就退回不带数字的入口,但别让 rejection 无声无息。
|
|
827
|
+
setCount(null);
|
|
828
|
+
});
|
|
427
829
|
};
|
|
428
830
|
React.useEffect(() => {
|
|
429
831
|
fetchCount();
|
|
@@ -446,6 +848,7 @@ window.__ModuleLoader__.load({
|
|
|
446
848
|
"aria-label": label,
|
|
447
849
|
onClick: () => props.openPanel(),
|
|
448
850
|
className: "dsh-sdel-footer",
|
|
851
|
+
"data-session-delete-footer": "",
|
|
449
852
|
style: {
|
|
450
853
|
display: "flex",
|
|
451
854
|
alignItems: "center",
|
|
@@ -464,6 +867,8 @@ window.__ModuleLoader__.load({
|
|
|
464
867
|
? h(
|
|
465
868
|
"span",
|
|
466
869
|
{
|
|
870
|
+
"data-session-delete-count": "",
|
|
871
|
+
"data-session-delete-count-value": String(count),
|
|
467
872
|
style: {
|
|
468
873
|
marginLeft: props.wide ? "auto" : 0,
|
|
469
874
|
minWidth: "16px",
|
|
@@ -482,6 +887,11 @@ window.__ModuleLoader__.load({
|
|
|
482
887
|
);
|
|
483
888
|
}
|
|
484
889
|
|
|
890
|
+
/**
|
|
891
|
+
* 删除确认框:会话与「整个工作区」共用一套。
|
|
892
|
+
* 正文三行(标题 / 影响面 / 需要留意的一行)+ 一行级联勾选 + 折叠详情;
|
|
893
|
+
* 默认焦点在「移入回收站」上(回车即生效),Esc 取消,不可删除时焦点回落到「取消」。
|
|
894
|
+
*/
|
|
485
895
|
function DeleteConfirm(/** @type {any} */ props) {
|
|
486
896
|
var requestState = useStore(props.requestStore);
|
|
487
897
|
var request = requestState[0];
|
|
@@ -494,24 +904,41 @@ window.__ModuleLoader__.load({
|
|
|
494
904
|
var busyState = React.useState(false);
|
|
495
905
|
var busy = busyState[0];
|
|
496
906
|
var setBusy = busyState[1];
|
|
497
|
-
var requestId = request ? request.sessionId : null;
|
|
498
907
|
var cascadeState = React.useState(false);
|
|
499
908
|
var cascade = cascadeState[0];
|
|
500
909
|
var setCascade = cascadeState[1];
|
|
910
|
+
var confirmRef = React.useRef(null);
|
|
911
|
+
var cancelRef = React.useRef(null);
|
|
912
|
+
var workspaceId = request?.workspaceId ? String(request.workspaceId) : null;
|
|
913
|
+
var isWorkspace = workspaceId !== null;
|
|
914
|
+
var requestKey = request
|
|
915
|
+
? isWorkspace
|
|
916
|
+
? `workspace:${workspaceId}`
|
|
917
|
+
: `session:${request.sessionId}`
|
|
918
|
+
: null;
|
|
919
|
+
|
|
920
|
+
/** 偏好只决定「初值」:用户这次勾了什么,下次就带过来。 */
|
|
921
|
+
var rememberCascade = (/** @type {any} */ next) => {
|
|
922
|
+
setCascade(next);
|
|
923
|
+
props.prefsStore.set({ cascadeChildren: next });
|
|
924
|
+
props.call("setPrefs", { cascadeChildren: next }).catch(() => {});
|
|
925
|
+
};
|
|
501
926
|
|
|
502
927
|
React.useEffect(() => {
|
|
503
|
-
if (!
|
|
928
|
+
if (!requestKey) {
|
|
504
929
|
setPlan(null);
|
|
505
930
|
setError(null);
|
|
506
931
|
setBusy(false);
|
|
507
|
-
setCascade(false);
|
|
508
932
|
return undefined;
|
|
509
933
|
}
|
|
510
934
|
var alive = true;
|
|
511
935
|
setPlan(null);
|
|
512
936
|
setError(null);
|
|
513
|
-
props
|
|
514
|
-
|
|
937
|
+
setCascade(props.prefsStore.getSnapshot()?.cascadeChildren === true);
|
|
938
|
+
var pending = workspaceId
|
|
939
|
+
? props.call("planWorkspace", { workspaceId: workspaceId })
|
|
940
|
+
: props.call("plan", { sessionId: request.sessionId });
|
|
941
|
+
pending
|
|
515
942
|
.then((/** @type {any} */ value) => {
|
|
516
943
|
if (alive) setPlan(value);
|
|
517
944
|
})
|
|
@@ -521,7 +948,24 @@ window.__ModuleLoader__.load({
|
|
|
521
948
|
return () => {
|
|
522
949
|
alive = false;
|
|
523
950
|
};
|
|
524
|
-
}, [
|
|
951
|
+
}, [requestKey]);
|
|
952
|
+
|
|
953
|
+
// hooks 必须在任何 return 之前:确认框组件常驻挂载,提前 return 会让 hook 数量在
|
|
954
|
+
// 「有请求 / 无请求」两种渲染之间变化,React 会直接抛 rendered more hooks 错误。
|
|
955
|
+
var blocked = isWorkspace ? false : (plan?.blockers?.length ?? 0) > 0;
|
|
956
|
+
var children = isWorkspace || !plan ? [] : Array.isArray(plan.children) ? plan.children : [];
|
|
957
|
+
var removes = isWorkspace || !plan ? [] : Array.isArray(plan.removes) ? plan.removes : [];
|
|
958
|
+
// 工作区预览里的 children 是**汇总数字**,会话计划里是数组,这里统一成数量。
|
|
959
|
+
var childCount = isWorkspace ? Number(plan?.children ?? 0) : children.length;
|
|
960
|
+
var sessionTotal = isWorkspace ? Number(plan?.total ?? 0) : 0;
|
|
961
|
+
var canConfirm = !!plan && !blocked && !busy && (!isWorkspace || sessionTotal > 0);
|
|
962
|
+
|
|
963
|
+
/** 焦点策略:可确认时落在破坏性按钮(回车即删),否则落在「取消」。 */
|
|
964
|
+
React.useEffect(() => {
|
|
965
|
+
if (!request) return;
|
|
966
|
+
var target = canConfirm ? confirmRef.current : cancelRef.current;
|
|
967
|
+
if (target && typeof target.focus === "function") target.focus();
|
|
968
|
+
}, [canConfirm, plan, request]);
|
|
525
969
|
|
|
526
970
|
if (!request) return null;
|
|
527
971
|
|
|
@@ -532,89 +976,196 @@ window.__ModuleLoader__.load({
|
|
|
532
976
|
var confirm = () => {
|
|
533
977
|
if (!plan || busy) return;
|
|
534
978
|
setBusy(true);
|
|
535
|
-
|
|
536
|
-
.call("
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
979
|
+
var pending = isWorkspace
|
|
980
|
+
? props.call("trashWorkspace", {
|
|
981
|
+
workspaceId: workspaceId,
|
|
982
|
+
digest: plan.digest,
|
|
983
|
+
cascade: cascade && childCount > 0,
|
|
984
|
+
})
|
|
985
|
+
: props.call("trash", {
|
|
986
|
+
sessionId: request.sessionId,
|
|
987
|
+
digest: plan.digest,
|
|
988
|
+
title: request.title || null,
|
|
989
|
+
cascade: cascade && children.length > 0,
|
|
990
|
+
});
|
|
991
|
+
pending
|
|
542
992
|
.then((/** @type {any} */ result) => {
|
|
543
993
|
props.requestStore.set(null);
|
|
544
|
-
props.
|
|
994
|
+
if (isWorkspace) props.onTrashedMany?.(result);
|
|
995
|
+
else
|
|
996
|
+
props.onTrashed?.(
|
|
997
|
+
Object.assign({}, result, {
|
|
998
|
+
wasCurrent: request.currentId === request.sessionId,
|
|
999
|
+
workspaceId: request.workspaceId ?? null,
|
|
1000
|
+
}),
|
|
1001
|
+
);
|
|
545
1002
|
})
|
|
546
1003
|
.catch((/** @type {any} */ reason) => {
|
|
547
1004
|
setBusy(false);
|
|
548
|
-
|
|
1005
|
+
if (!isWorkspace && isPartialFailure(reason)) {
|
|
1006
|
+
// 已移入回收站但收尾失败(AUD-SD-03):磁盘事实变了,别让用户以为「删除失败」
|
|
1007
|
+
// 再点一次(重试只会得到 not-found)。关框、按事实提示、照常刷新列表。
|
|
1008
|
+
props.requestStore.set(null);
|
|
1009
|
+
const partialEntryId = reason?.details?.entryId ?? null;
|
|
1010
|
+
props.onTrashed?.({
|
|
1011
|
+
sessionId: request.sessionId,
|
|
1012
|
+
entryId: partialEntryId,
|
|
1013
|
+
title: request.title || null,
|
|
1014
|
+
wasCurrent: request.currentId === request.sessionId,
|
|
1015
|
+
workspaceId: request.workspaceId ?? null,
|
|
1016
|
+
});
|
|
1017
|
+
// 错误 toast 也带上 entryId:partial 的「已进回收站」仍然给撤销入口,
|
|
1018
|
+
// 否则用户只剩面板一条路(复审 F12)。
|
|
1019
|
+
props.toastStore?.set({
|
|
1020
|
+
entryId: partialEntryId,
|
|
1021
|
+
title: request.title || null,
|
|
1022
|
+
text: trashFailureText(reason, props.t),
|
|
1023
|
+
error: true,
|
|
1024
|
+
});
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
setError(trashFailureText(reason, props.t));
|
|
549
1028
|
});
|
|
550
1029
|
};
|
|
551
1030
|
|
|
552
|
-
var
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
list: plan.removes.map((/** @type {any} */ item) => item.label).join(" · "),
|
|
563
|
-
}),
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
if (plan.blockers && plan.blockers.length > 0)
|
|
567
|
-
lines.push(props.t("confirm.blocked", { reason: plan.blockers[0].message }));
|
|
568
|
-
}
|
|
569
|
-
var blocked = !!(plan?.blockers && plan.blockers.length > 0);
|
|
1031
|
+
var impact = isWorkspace
|
|
1032
|
+
? plan
|
|
1033
|
+
? props.t("confirm.workspace.summary", {
|
|
1034
|
+
n: sessionTotal,
|
|
1035
|
+
size: formatBytes(plan.sizeBytes),
|
|
1036
|
+
})
|
|
1037
|
+
: props.t("confirm.loading")
|
|
1038
|
+
: plan
|
|
1039
|
+
? impactLine(plan, props.t) || props.t("confirm.size", { size: "?" })
|
|
1040
|
+
: props.t("confirm.loading");
|
|
570
1041
|
|
|
571
1042
|
var body = h(
|
|
572
1043
|
React.Fragment,
|
|
573
1044
|
null,
|
|
574
|
-
request.title
|
|
575
|
-
? h(
|
|
1045
|
+
!isWorkspace && request.title
|
|
1046
|
+
? h(
|
|
1047
|
+
"div",
|
|
1048
|
+
{
|
|
1049
|
+
className: "dsh-sdel-truncate",
|
|
1050
|
+
style: { fontWeight: 600, marginBottom: "4px" },
|
|
1051
|
+
title: request.title,
|
|
1052
|
+
},
|
|
1053
|
+
request.title,
|
|
1054
|
+
)
|
|
576
1055
|
: null,
|
|
577
|
-
|
|
1056
|
+
h("div", { style: { color: T.dim }, "data-session-delete-impact": "" }, impact),
|
|
1057
|
+
!isWorkspace && removes.length > 0
|
|
578
1058
|
? h(
|
|
579
|
-
"
|
|
1059
|
+
"div",
|
|
580
1060
|
{
|
|
581
|
-
style: {
|
|
582
|
-
|
|
583
|
-
alignItems: "flex-start",
|
|
584
|
-
gap: "8px",
|
|
585
|
-
margin: "8px 0 4px",
|
|
586
|
-
cursor: "pointer",
|
|
587
|
-
},
|
|
1061
|
+
style: { color: T.faint, fontSize: "12px", marginTop: "2px" },
|
|
1062
|
+
"data-session-delete-refs": "",
|
|
588
1063
|
},
|
|
589
|
-
|
|
590
|
-
|
|
1064
|
+
props.t("confirm.refs", { n: removes.length }),
|
|
1065
|
+
)
|
|
1066
|
+
: null,
|
|
1067
|
+
isWorkspace && plan && plan.live > 0
|
|
1068
|
+
? h(
|
|
1069
|
+
"div",
|
|
1070
|
+
{ style: { color: T.faint, fontSize: "12px", marginTop: "2px" } },
|
|
1071
|
+
props.t("confirm.workspace.live", { n: plan.live }),
|
|
1072
|
+
)
|
|
1073
|
+
: null,
|
|
1074
|
+
isWorkspace && plan && plan.blocked > 0
|
|
1075
|
+
? h(
|
|
1076
|
+
"div",
|
|
1077
|
+
{ style: { color: T.danger, fontSize: "12px", marginTop: "2px" } },
|
|
1078
|
+
props.t("confirm.workspace.blocked", { n: plan.blocked }),
|
|
1079
|
+
)
|
|
1080
|
+
: null,
|
|
1081
|
+
childCount > 0
|
|
1082
|
+
? h(
|
|
1083
|
+
"div",
|
|
1084
|
+
{ style: { marginTop: "10px" } },
|
|
1085
|
+
h(Check, {
|
|
591
1086
|
checked: cascade,
|
|
592
1087
|
disabled: busy,
|
|
593
|
-
|
|
594
|
-
|
|
1088
|
+
label: props.t("confirm.cascade", { n: childCount }),
|
|
1089
|
+
onChange: rememberCascade,
|
|
595
1090
|
}),
|
|
1091
|
+
)
|
|
1092
|
+
: null,
|
|
1093
|
+
blocked
|
|
1094
|
+
? h(
|
|
1095
|
+
"div",
|
|
1096
|
+
{
|
|
1097
|
+
style: { color: T.danger, marginTop: "10px" },
|
|
1098
|
+
role: "alert",
|
|
1099
|
+
"data-session-delete-blocked": "",
|
|
1100
|
+
},
|
|
1101
|
+
props.t("confirm.blocked", { reason: plan.blockers[0].message }),
|
|
1102
|
+
)
|
|
1103
|
+
: null,
|
|
1104
|
+
error
|
|
1105
|
+
? h(
|
|
1106
|
+
"div",
|
|
1107
|
+
{ style: { color: T.danger, marginTop: "8px" }, "data-session-delete-error": "" },
|
|
1108
|
+
error,
|
|
1109
|
+
)
|
|
1110
|
+
: null,
|
|
1111
|
+
plan
|
|
1112
|
+
? h(
|
|
1113
|
+
"div",
|
|
1114
|
+
{ style: { marginTop: "10px" } },
|
|
596
1115
|
h(
|
|
597
|
-
|
|
598
|
-
null,
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
1116
|
+
Disclosure,
|
|
1117
|
+
{ label: props.t("confirm.details"), meta: null, maxHeight: "180px" },
|
|
1118
|
+
isWorkspace
|
|
1119
|
+
? h(
|
|
1120
|
+
React.Fragment,
|
|
1121
|
+
null,
|
|
1122
|
+
sessionTotal > 0
|
|
1123
|
+
? h(
|
|
1124
|
+
"div",
|
|
1125
|
+
null,
|
|
1126
|
+
props.t("confirm.detail.workspaceSessions", {
|
|
1127
|
+
list: joinList(plan.sessions, 8),
|
|
1128
|
+
}),
|
|
1129
|
+
)
|
|
1130
|
+
: null,
|
|
1131
|
+
plan.missing && plan.missing.length > 0
|
|
1132
|
+
? h(
|
|
1133
|
+
"div",
|
|
1134
|
+
null,
|
|
1135
|
+
props.t("confirm.workspace.missing", { n: plan.missing.length }),
|
|
1136
|
+
)
|
|
1137
|
+
: null,
|
|
1138
|
+
h("div", null, props.t("confirm.detail.recoverable")),
|
|
1139
|
+
)
|
|
1140
|
+
: h(
|
|
1141
|
+
React.Fragment,
|
|
1142
|
+
null,
|
|
1143
|
+
removes.length > 0
|
|
1144
|
+
? h(
|
|
1145
|
+
"div",
|
|
1146
|
+
null,
|
|
1147
|
+
props.t("confirm.detail.refs", { list: joinList(removes) }),
|
|
1148
|
+
)
|
|
1149
|
+
: null,
|
|
1150
|
+
children.length > 0
|
|
1151
|
+
? h(
|
|
1152
|
+
"div",
|
|
1153
|
+
null,
|
|
1154
|
+
props.t("confirm.detail.children", { list: joinList(children) }),
|
|
1155
|
+
)
|
|
1156
|
+
: null,
|
|
1157
|
+
plan.trashPath
|
|
1158
|
+
? h(
|
|
1159
|
+
"div",
|
|
1160
|
+
null,
|
|
1161
|
+
props.t("confirm.detail.trashPath", { path: plan.trashPath }),
|
|
1162
|
+
)
|
|
1163
|
+
: null,
|
|
1164
|
+
h("div", null, props.t("confirm.detail.recoverable")),
|
|
1165
|
+
),
|
|
610
1166
|
),
|
|
611
1167
|
)
|
|
612
1168
|
: null,
|
|
613
|
-
lines.map((/** @type {any} */ line, /** @type {any} */ index) =>
|
|
614
|
-
h("div", { key: `line-${index}`, style: { marginBottom: "4px" } }, line),
|
|
615
|
-
),
|
|
616
|
-
!plan && !error ? h("div", { style: { color: T.dim } }, props.t("confirm.loading")) : null,
|
|
617
|
-
error ? h("div", { style: { color: T.danger, marginTop: "8px" } }, error) : null,
|
|
618
1169
|
);
|
|
619
1170
|
|
|
620
1171
|
return h(
|
|
@@ -622,16 +1173,35 @@ window.__ModuleLoader__.load({
|
|
|
622
1173
|
{
|
|
623
1174
|
onClose: close,
|
|
624
1175
|
closeLabel: props.t("confirm.cancel"),
|
|
625
|
-
title:
|
|
1176
|
+
title: isWorkspace
|
|
1177
|
+
? props.t("confirm.workspace.title", {
|
|
1178
|
+
name: request.title || plan?.title || workspaceId,
|
|
1179
|
+
})
|
|
1180
|
+
: props.t("confirm.title"),
|
|
626
1181
|
description: props.t("confirm.desc"),
|
|
627
1182
|
footer: h(
|
|
628
1183
|
React.Fragment,
|
|
629
1184
|
null,
|
|
630
|
-
h(Btn, { autoFocus: true, onClick: close, disabled: busy }, props.t("confirm.cancel")),
|
|
631
1185
|
h(
|
|
632
1186
|
Btn,
|
|
633
|
-
{
|
|
634
|
-
|
|
1187
|
+
{ innerRef: cancelRef, action: "cancel", onClick: close, disabled: busy },
|
|
1188
|
+
props.t("confirm.cancel"),
|
|
1189
|
+
),
|
|
1190
|
+
h(
|
|
1191
|
+
Btn,
|
|
1192
|
+
{
|
|
1193
|
+
innerRef: confirmRef,
|
|
1194
|
+
action: "confirm",
|
|
1195
|
+
modalAutofocus: true,
|
|
1196
|
+
onClick: confirm,
|
|
1197
|
+
variant: "danger",
|
|
1198
|
+
disabled: !canConfirm,
|
|
1199
|
+
},
|
|
1200
|
+
busy
|
|
1201
|
+
? props.t("confirm.pending")
|
|
1202
|
+
: isWorkspace
|
|
1203
|
+
? props.t("confirm.workspace.confirm", { n: sessionTotal })
|
|
1204
|
+
: props.t("confirm.confirm"),
|
|
635
1205
|
),
|
|
636
1206
|
),
|
|
637
1207
|
},
|
|
@@ -639,111 +1209,64 @@ window.__ModuleLoader__.load({
|
|
|
639
1209
|
);
|
|
640
1210
|
}
|
|
641
1211
|
|
|
1212
|
+
/**
|
|
1213
|
+
* 回收站面板:只有一件事 —— 看列表、选条目、恢复或彻底删除。
|
|
1214
|
+
* 批量条固定在列表上方(不随内容滚动),80 条时也不会「找不到按钮」。
|
|
1215
|
+
*/
|
|
642
1216
|
function TrashPanel(/** @type {any} */ props) {
|
|
643
1217
|
var panelState = useStore(props.panelStore);
|
|
644
1218
|
var open = panelState[0];
|
|
645
|
-
var tabState = React.useState("trash");
|
|
646
|
-
var tab = tabState[0];
|
|
647
|
-
var setTab = tabState[1];
|
|
648
1219
|
var dataState = React.useState(null);
|
|
649
1220
|
var data = dataState[0];
|
|
650
1221
|
var setData = dataState[1];
|
|
651
|
-
var auditState = React.useState(null);
|
|
652
|
-
var audit = auditState[0];
|
|
653
|
-
var setAudit = auditState[1];
|
|
654
|
-
var healthState = React.useState(null);
|
|
655
|
-
var health = healthState[0];
|
|
656
|
-
var setHealth = healthState[1];
|
|
657
1222
|
var errorState = React.useState(null);
|
|
658
1223
|
var error = errorState[0];
|
|
659
1224
|
var setError = errorState[1];
|
|
660
|
-
var
|
|
661
|
-
var busyId =
|
|
662
|
-
var setBusyId =
|
|
663
|
-
var
|
|
664
|
-
var confirmPurge =
|
|
665
|
-
var setConfirmPurge =
|
|
666
|
-
var
|
|
667
|
-
var
|
|
668
|
-
var
|
|
669
|
-
var
|
|
670
|
-
var
|
|
671
|
-
var
|
|
672
|
-
var
|
|
673
|
-
var
|
|
674
|
-
var
|
|
675
|
-
|
|
676
|
-
var
|
|
677
|
-
var
|
|
678
|
-
var
|
|
679
|
-
var
|
|
680
|
-
var
|
|
681
|
-
var
|
|
682
|
-
var
|
|
683
|
-
var setCleaning = cleanState[1];
|
|
684
|
-
var cleanMsgState = React.useState("");
|
|
685
|
-
var cleanMsg = cleanMsgState[0];
|
|
686
|
-
var setCleanMsg = cleanMsgState[1];
|
|
687
|
-
var receiptsState = React.useState(null);
|
|
688
|
-
var receipts = receiptsState[0];
|
|
689
|
-
var setReceipts = receiptsState[1];
|
|
690
|
-
|
|
691
|
-
const loadReceipts = React.useCallback(() => {
|
|
692
|
-
props
|
|
693
|
-
.call("receipts", { limit: 50 })
|
|
694
|
-
.then((/** @type {any} */ value) => {
|
|
695
|
-
setReceipts(value?.entries ? value.entries : []);
|
|
696
|
-
})
|
|
697
|
-
.catch(() => setReceipts([]));
|
|
698
|
-
}, []);
|
|
699
|
-
|
|
700
|
-
const loadHealth = React.useCallback(() => {
|
|
701
|
-
setScan(null);
|
|
702
|
-
setScanError(null);
|
|
703
|
-
props
|
|
704
|
-
.call("healthScan")
|
|
705
|
-
.then((/** @type {any} */ value) => {
|
|
706
|
-
setScan(value);
|
|
707
|
-
})
|
|
708
|
-
.catch((/** @type {any} */ reason) => {
|
|
709
|
-
setScanError(errorText(reason));
|
|
710
|
-
});
|
|
711
|
-
}, []);
|
|
712
|
-
|
|
713
|
-
const loadAudit = React.useCallback(() => {
|
|
714
|
-
props
|
|
715
|
-
.call("audit", { limit: 100 })
|
|
716
|
-
.then((/** @type {any} */ value) => {
|
|
717
|
-
setAudit(value?.entries ? value.entries : []);
|
|
718
|
-
})
|
|
719
|
-
.catch(() => {});
|
|
720
|
-
}, []);
|
|
1225
|
+
var busyIdState = React.useState(null);
|
|
1226
|
+
var busyId = busyIdState[0];
|
|
1227
|
+
var setBusyId = busyIdState[1];
|
|
1228
|
+
var confirmPurgeState = React.useState(null);
|
|
1229
|
+
var confirmPurge = confirmPurgeState[0];
|
|
1230
|
+
var setConfirmPurge = confirmPurgeState[1];
|
|
1231
|
+
var selectedState = React.useState({});
|
|
1232
|
+
var selected = selectedState[0];
|
|
1233
|
+
var setSelected = selectedState[1];
|
|
1234
|
+
var batchState = React.useState(null);
|
|
1235
|
+
var batch = batchState[0];
|
|
1236
|
+
var setBatch = batchState[1];
|
|
1237
|
+
var readOnlyState = React.useState(false);
|
|
1238
|
+
var readOnly = readOnlyState[0];
|
|
1239
|
+
var setReadOnly = readOnlyState[1];
|
|
1240
|
+
// 恢复结果里没通过的引用(USIM-U3-05):留住清单,界面才能「可展开 + 可重试」。
|
|
1241
|
+
var restoreDetailState = React.useState(null);
|
|
1242
|
+
var restoreDetail = restoreDetailState[0];
|
|
1243
|
+
var setRestoreDetail = restoreDetailState[1];
|
|
1244
|
+
var retryingState = React.useState(false);
|
|
1245
|
+
var retrying = retryingState[0];
|
|
1246
|
+
var setRetrying = retryingState[1];
|
|
1247
|
+
var batchControl = React.useRef({ stop: false });
|
|
721
1248
|
|
|
1249
|
+
var loader = React.useMemo(
|
|
1250
|
+
() =>
|
|
1251
|
+
createPanelLoader(props.call, {
|
|
1252
|
+
setData: setData,
|
|
1253
|
+
setReadOnly: setReadOnly,
|
|
1254
|
+
setError: setError,
|
|
1255
|
+
}),
|
|
1256
|
+
[],
|
|
1257
|
+
);
|
|
722
1258
|
var refresh = React.useCallback(() => {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
.then((/** @type {any} */ value) => {
|
|
726
|
-
setData(value);
|
|
727
|
-
})
|
|
728
|
-
.catch((/** @type {any} */ reason) => {
|
|
729
|
-
setError(errorText(reason));
|
|
730
|
-
});
|
|
731
|
-
}, []);
|
|
1259
|
+
void loader.load();
|
|
1260
|
+
}, [loader]);
|
|
732
1261
|
|
|
733
1262
|
React.useEffect(() => {
|
|
734
1263
|
if (!open) return undefined;
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
.then((/** @type {any} */ value) => {
|
|
739
|
-
setHealth(value);
|
|
740
|
-
})
|
|
741
|
-
.catch(() => {});
|
|
742
|
-
loadAudit();
|
|
743
|
-
// 面板打开期间自动同步,不需要手动刷新按钮。
|
|
1264
|
+
void loader.load();
|
|
1265
|
+
void loader.loadHealth();
|
|
1266
|
+
// 面板打开期间自动同步:agent 工具、另一个窗口都可能改动回收站。
|
|
744
1267
|
const timer = setInterval(() => {
|
|
745
1268
|
if (document.visibilityState === "visible") refresh();
|
|
746
|
-
},
|
|
1269
|
+
}, PANEL_POLL_MS);
|
|
747
1270
|
const onVisible = () => {
|
|
748
1271
|
if (document.visibilityState === "visible") refresh();
|
|
749
1272
|
};
|
|
@@ -754,47 +1277,86 @@ window.__ModuleLoader__.load({
|
|
|
754
1277
|
};
|
|
755
1278
|
}, [open]);
|
|
756
1279
|
|
|
757
|
-
const listRef = React.useRef(null);
|
|
758
|
-
const onListKeyDown = (/** @type {any} */ event) => {
|
|
759
|
-
if (event.key === "Escape") {
|
|
760
|
-
event.preventDefault();
|
|
761
|
-
props.panelStore.set(false);
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
const keys = ["ArrowDown", "ArrowUp", "Home", "End"];
|
|
765
|
-
if (!keys.includes(event.key)) return;
|
|
766
|
-
const root = listRef.current;
|
|
767
|
-
if (!root) return;
|
|
768
|
-
const items = [...root.querySelectorAll("button:not([disabled])")];
|
|
769
|
-
if (items.length === 0) return;
|
|
770
|
-
const current = items.indexOf(document.activeElement);
|
|
771
|
-
let next = 0;
|
|
772
|
-
if (event.key === "Home") next = 0;
|
|
773
|
-
else if (event.key === "End") next = items.length - 1;
|
|
774
|
-
else if (event.key === "ArrowDown")
|
|
775
|
-
next = current < 0 ? 0 : Math.min(items.length - 1, current + 1);
|
|
776
|
-
else next = current <= 0 ? 0 : current - 1;
|
|
777
|
-
event.preventDefault();
|
|
778
|
-
items[next].focus();
|
|
779
|
-
};
|
|
780
|
-
|
|
781
1280
|
if (!open) return null;
|
|
782
1281
|
|
|
1282
|
+
var entries = data?.entries || [];
|
|
1283
|
+
var selectedIds = Object.keys(selected).filter(
|
|
1284
|
+
(/** @type {string} */ entryId) => selected[entryId],
|
|
1285
|
+
);
|
|
1286
|
+
var allSelected = entries.length > 0 && selectedIds.length === entries.length;
|
|
1287
|
+
var batchRunning = batch?.running === true;
|
|
1288
|
+
|
|
783
1289
|
var doRestore = (/** @type {any} */ entryId, /** @type {any} */ sessionId) => {
|
|
784
1290
|
setBusyId(entryId);
|
|
1291
|
+
setRestoreDetail(null);
|
|
785
1292
|
props
|
|
786
1293
|
.call("restore", { entryId: entryId })
|
|
787
|
-
.then(() => {
|
|
1294
|
+
.then((/** @type {any} */ result) => {
|
|
788
1295
|
setBusyId(null);
|
|
789
1296
|
refresh();
|
|
790
1297
|
props.bump?.();
|
|
791
|
-
|
|
1298
|
+
var failures = restoreFailures(result);
|
|
1299
|
+
if (failures.length === 0) {
|
|
1300
|
+
// 恢复成功的终点就是「回到会话里」:先关框再重开(USIM-U2-17)。
|
|
1301
|
+
// 成功路径只走 onRestoreComplete 一处(N2:以前这里还会再调一次
|
|
1302
|
+
// onRestored,导致 refreshRows + openSession 各跑两遍)。
|
|
1303
|
+
setError(null);
|
|
1304
|
+
setRestoreDetail(null);
|
|
1305
|
+
props.onRestoreComplete?.(result);
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
// 没全过:仍要把 retired 清掉并刷新列表,再把话说清楚(AUD-SD-02)。
|
|
1309
|
+
props.onRestored?.(result?.sessionId || sessionId, { open: false });
|
|
1310
|
+
setError(restoreNotice(result, props.t));
|
|
1311
|
+
setRestoreDetail({
|
|
1312
|
+
sessionId: result?.sessionId || sessionId,
|
|
1313
|
+
result: result,
|
|
1314
|
+
failures: failures,
|
|
1315
|
+
});
|
|
792
1316
|
})
|
|
793
1317
|
.catch((/** @type {any} */ reason) => {
|
|
794
1318
|
setBusyId(null);
|
|
795
1319
|
setError(errorText(reason));
|
|
796
1320
|
});
|
|
797
1321
|
};
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* 重检未通过的引用(USIM-U3-05 的可操作出口):宿主按回执里的快照重放一次。
|
|
1325
|
+
*/
|
|
1326
|
+
var retryFailedRefs = () => {
|
|
1327
|
+
if (!restoreDetail || retrying) return;
|
|
1328
|
+
setRetrying(true);
|
|
1329
|
+
props
|
|
1330
|
+
.call("recheckRestore", {
|
|
1331
|
+
receiptId:
|
|
1332
|
+
typeof restoreDetail.result?.receiptId === "string"
|
|
1333
|
+
? restoreDetail.result.receiptId
|
|
1334
|
+
: undefined,
|
|
1335
|
+
sessionId: restoreDetail.sessionId,
|
|
1336
|
+
})
|
|
1337
|
+
.then((/** @type {any} */ result) => {
|
|
1338
|
+
setRetrying(false);
|
|
1339
|
+
props.bump?.();
|
|
1340
|
+
var left = restoreFailures(result);
|
|
1341
|
+
if (left.length === 0) {
|
|
1342
|
+
setError(props.t("restore.retry.ok"));
|
|
1343
|
+
setRestoreDetail(null);
|
|
1344
|
+
props.onRestored?.(result?.sessionId || restoreDetail.sessionId);
|
|
1345
|
+
refresh();
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
setError(props.t("restore.retry.partial", { n: left.length }));
|
|
1349
|
+
setRestoreDetail({
|
|
1350
|
+
sessionId: result?.sessionId || restoreDetail.sessionId,
|
|
1351
|
+
result: result,
|
|
1352
|
+
failures: left,
|
|
1353
|
+
});
|
|
1354
|
+
})
|
|
1355
|
+
.catch((/** @type {any} */ reason) => {
|
|
1356
|
+
setRetrying(false);
|
|
1357
|
+
setError(errorText(reason));
|
|
1358
|
+
});
|
|
1359
|
+
};
|
|
798
1360
|
var doPurge = (/** @type {any} */ entryId, /** @type {any} */ sessionId) => {
|
|
799
1361
|
setBusyId(entryId);
|
|
800
1362
|
props
|
|
@@ -812,533 +1374,864 @@ window.__ModuleLoader__.load({
|
|
|
812
1374
|
});
|
|
813
1375
|
};
|
|
814
1376
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
setTrashMsg(props.t("batch.done", { ok: result.succeeded, total: result.total }));
|
|
847
|
-
setSelectedTrash({});
|
|
848
|
-
refresh();
|
|
849
|
-
props.bump?.();
|
|
850
|
-
for (const item of result.results) if (item.ok) props.onPurged?.(undefined);
|
|
851
|
-
})
|
|
852
|
-
.catch((/** @type {any} */ reason) => {
|
|
853
|
-
setTrashBusy(false);
|
|
854
|
-
setTrashMsg(errorText(reason));
|
|
1377
|
+
/**
|
|
1378
|
+
* 分批执行批量动作。宿主单次上限是防御性的硬上限,界面按 BATCH_CHUNK 切块,
|
|
1379
|
+
* 每块之间让出一帧:进度可见、可中途停止、部分失败不中断其余批次。
|
|
1380
|
+
* @param {string[]} ids
|
|
1381
|
+
* @param {"purge" | "restore"} kind
|
|
1382
|
+
*/
|
|
1383
|
+
var startBatch = (ids, kind) => {
|
|
1384
|
+
if (ids.length === 0 || batchRunning) return;
|
|
1385
|
+
batchControl.current = { stop: false };
|
|
1386
|
+
setBatch({ kind: kind, running: true, done: 0, total: ids.length, failures: [] });
|
|
1387
|
+
void runBatch({
|
|
1388
|
+
ids: ids,
|
|
1389
|
+
kind: kind,
|
|
1390
|
+
call: props.call,
|
|
1391
|
+
chunkSize: BATCH_CHUNK,
|
|
1392
|
+
onProgress: (/** @type {any} */ state) => {
|
|
1393
|
+
setBatch(state);
|
|
1394
|
+
},
|
|
1395
|
+
shouldStop: () => batchControl.current.stop === true,
|
|
1396
|
+
onRestored: (/** @type {any} */ sessionId, /** @type {any} */ info) =>
|
|
1397
|
+
props.onRestored?.(sessionId, info),
|
|
1398
|
+
}).then((/** @type {any} */ summary) => {
|
|
1399
|
+
setSelected((/** @type {any} */ current) => {
|
|
1400
|
+
/** @type {Record<string, boolean>} */
|
|
1401
|
+
var keep = {};
|
|
1402
|
+
for (let index = 0; index < summary.failures.length; index += 1) {
|
|
1403
|
+
if (current[summary.failures[index].entryId]) {
|
|
1404
|
+
keep[summary.failures[index].entryId] = true;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
return keep;
|
|
855
1408
|
});
|
|
1409
|
+
setConfirmPurge(null);
|
|
1410
|
+
refresh();
|
|
1411
|
+
props.bump?.();
|
|
1412
|
+
if (kind === "purge") props.onPurged?.(undefined);
|
|
1413
|
+
// 批量恢复全绿时同样「完成即关框」(U2-17 的批量版);有失败就留在面板里看清单。
|
|
1414
|
+
if (kind === "restore" && summary.failures.length === 0) {
|
|
1415
|
+
props.onBatchRestoreDone?.(summary);
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
856
1418
|
};
|
|
857
1419
|
|
|
858
|
-
var
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1420
|
+
var toolbar = h(
|
|
1421
|
+
"div",
|
|
1422
|
+
{ className: "dsh-sdel-toolbar", "data-session-delete-toolbar": "" },
|
|
1423
|
+
h(Check, {
|
|
1424
|
+
checked: allSelected,
|
|
1425
|
+
disabled: batchRunning || entries.length === 0,
|
|
1426
|
+
label:
|
|
1427
|
+
selectedIds.length > 0
|
|
1428
|
+
? props.t("trash.selectCount", { n: selectedIds.length, total: entries.length })
|
|
1429
|
+
: props.t("trash.selectAll"),
|
|
1430
|
+
onChange: (/** @type {any} */ next) => {
|
|
1431
|
+
/** @type {Record<string, boolean>} */
|
|
1432
|
+
var map = {};
|
|
1433
|
+
if (next) {
|
|
1434
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
1435
|
+
map[entries[index].entryId] = true;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
setSelected(map);
|
|
1439
|
+
},
|
|
1440
|
+
}),
|
|
1441
|
+
h("span", { style: { flex: 1 } }),
|
|
876
1442
|
h(
|
|
877
|
-
|
|
878
|
-
{
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
},
|
|
895
|
-
},
|
|
896
|
-
props.t("panel.tabAudit"),
|
|
897
|
-
),
|
|
898
|
-
h(
|
|
899
|
-
Btn,
|
|
900
|
-
{
|
|
901
|
-
onClick: () => {
|
|
902
|
-
setTab("health");
|
|
903
|
-
loadHealth();
|
|
904
|
-
},
|
|
905
|
-
},
|
|
906
|
-
props.t("panel.tabHealth"),
|
|
907
|
-
),
|
|
908
|
-
h(
|
|
909
|
-
Btn,
|
|
910
|
-
{
|
|
911
|
-
onClick: () => {
|
|
912
|
-
setTab("receipts");
|
|
913
|
-
loadReceipts();
|
|
914
|
-
},
|
|
915
|
-
},
|
|
916
|
-
props.t("panel.tabReceipts"),
|
|
917
|
-
),
|
|
1443
|
+
Btn,
|
|
1444
|
+
{
|
|
1445
|
+
disabled: batchRunning || selectedIds.length === 0,
|
|
1446
|
+
action: "batch-restore",
|
|
1447
|
+
onClick: () => startBatch(selectedIds, "restore"),
|
|
1448
|
+
},
|
|
1449
|
+
props.t("trash.restoreMany", { n: selectedIds.length }),
|
|
1450
|
+
),
|
|
1451
|
+
h(
|
|
1452
|
+
Btn,
|
|
1453
|
+
{
|
|
1454
|
+
variant: "danger",
|
|
1455
|
+
disabled: batchRunning || selectedIds.length === 0,
|
|
1456
|
+
action: "batch-purge",
|
|
1457
|
+
onClick: () => setConfirmPurge("__batch__"),
|
|
1458
|
+
},
|
|
1459
|
+
props.t("trash.purgeMany", { n: selectedIds.length }),
|
|
918
1460
|
),
|
|
919
1461
|
);
|
|
920
1462
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1463
|
+
var batchLine = batch
|
|
1464
|
+
? h(
|
|
1465
|
+
"div",
|
|
1466
|
+
{ className: "dsh-sdel-batch", "data-session-delete-batch": "" },
|
|
924
1467
|
h(
|
|
925
|
-
"
|
|
926
|
-
{
|
|
927
|
-
|
|
1468
|
+
"span",
|
|
1469
|
+
{ role: "status" },
|
|
1470
|
+
batch.running
|
|
1471
|
+
? props.t("batch.progress", { done: batch.done, total: batch.total })
|
|
1472
|
+
: props.t("batch.done", {
|
|
1473
|
+
ok: batch.total - batch.failures.length,
|
|
1474
|
+
total: batch.total,
|
|
1475
|
+
}),
|
|
928
1476
|
),
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
receipts.forEach((/** @type {any} */ receipt, /** @type {any} */ index) => {
|
|
932
|
-
const removed = receipt.removed || [];
|
|
933
|
-
const okCount = removed.filter(
|
|
934
|
-
(/** @type {any} */ item) => item.status === "ok",
|
|
935
|
-
).length;
|
|
936
|
-
const detail =
|
|
937
|
-
receipt.action === "trash"
|
|
938
|
-
? `${formatBytes(receipt.sizeBytes || 0)} · ${okCount}/${removed.length}`
|
|
939
|
-
: receipt.action === "restore"
|
|
940
|
-
? props.t("receipts.restored")
|
|
941
|
-
: receipt.action === "purge"
|
|
942
|
-
? formatBytes(receipt.bytes || 0)
|
|
943
|
-
: String(receipt.total || 0);
|
|
944
|
-
content.push(
|
|
945
|
-
h(
|
|
946
|
-
"div",
|
|
947
|
-
{
|
|
948
|
-
key: `receipt-${index}`,
|
|
949
|
-
title: String(receipt.sessionId || ""),
|
|
950
|
-
style: {
|
|
951
|
-
borderTop: `1px solid ${T.border}`,
|
|
952
|
-
padding: "7px 0",
|
|
953
|
-
fontSize: "12px",
|
|
954
|
-
display: "flex",
|
|
955
|
-
alignItems: "baseline",
|
|
956
|
-
gap: "6px",
|
|
957
|
-
},
|
|
958
|
-
},
|
|
959
|
-
h(
|
|
960
|
-
"span",
|
|
961
|
-
{ style: { color: T.faint, whiteSpace: "nowrap" } },
|
|
962
|
-
formatTime(receipt.at),
|
|
963
|
-
),
|
|
964
|
-
h(
|
|
1477
|
+
batch.failures.length > 0
|
|
1478
|
+
? h(
|
|
965
1479
|
"span",
|
|
966
|
-
{ style: {
|
|
967
|
-
|
|
968
|
-
)
|
|
969
|
-
|
|
1480
|
+
{ style: { color: T.danger }, "data-session-delete-batch-failed": "" },
|
|
1481
|
+
props.t("batch.failed", { n: batch.failures.length }),
|
|
1482
|
+
)
|
|
1483
|
+
: null,
|
|
1484
|
+
batch.partials > 0
|
|
1485
|
+
? h(
|
|
970
1486
|
"span",
|
|
1487
|
+
{ style: { color: T.danger }, "data-session-delete-batch-partial": "" },
|
|
1488
|
+
props.t("batch.partial", { n: batch.partials }),
|
|
1489
|
+
)
|
|
1490
|
+
: null,
|
|
1491
|
+
batch.running
|
|
1492
|
+
? h(
|
|
1493
|
+
Btn,
|
|
971
1494
|
{
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
color: T.dim,
|
|
976
|
-
overflow: "hidden",
|
|
977
|
-
textOverflow: "ellipsis",
|
|
978
|
-
whiteSpace: "nowrap",
|
|
1495
|
+
tight: true,
|
|
1496
|
+
onClick: () => {
|
|
1497
|
+
batchControl.current.stop = true;
|
|
979
1498
|
},
|
|
980
1499
|
},
|
|
981
|
-
|
|
982
|
-
)
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
content.push(
|
|
991
|
-
h("div", { key: "scan-err", style: { color: T.danger, padding: "8px 0" } }, scanError),
|
|
992
|
-
);
|
|
993
|
-
} else if (!scan) {
|
|
994
|
-
content.push(
|
|
995
|
-
h(
|
|
996
|
-
"div",
|
|
997
|
-
{ key: "scan-loading", style: { color: T.dim, padding: "8px 0" } },
|
|
998
|
-
props.t("health.loading"),
|
|
999
|
-
),
|
|
1000
|
-
);
|
|
1001
|
-
} else if (!scan.ok) {
|
|
1002
|
-
content.push(
|
|
1003
|
-
h(
|
|
1004
|
-
"div",
|
|
1005
|
-
{ key: "scan-na", style: { color: T.dim, padding: "8px 0" } },
|
|
1006
|
-
props.t("health.unavailable", { reason: scan.reason || "" }),
|
|
1007
|
-
),
|
|
1008
|
-
);
|
|
1009
|
-
} else {
|
|
1010
|
-
content.push(
|
|
1011
|
-
h(
|
|
1012
|
-
"div",
|
|
1013
|
-
{ key: "scan-inventory", style: { color: T.dim, fontSize: "12px" } },
|
|
1014
|
-
props.t("health.inventory", scan.inventory || {}),
|
|
1015
|
-
),
|
|
1016
|
-
);
|
|
1017
|
-
content.push(
|
|
1018
|
-
h(
|
|
1500
|
+
props.t("batch.stop"),
|
|
1501
|
+
)
|
|
1502
|
+
: null,
|
|
1503
|
+
)
|
|
1504
|
+
: null;
|
|
1505
|
+
|
|
1506
|
+
var confirmLine =
|
|
1507
|
+
confirmPurge === "__batch__"
|
|
1508
|
+
? h(
|
|
1019
1509
|
"div",
|
|
1020
|
-
{
|
|
1021
|
-
props.t("
|
|
1022
|
-
state: scan.agentTool
|
|
1023
|
-
? props.t("health.agentToolOn")
|
|
1024
|
-
: props.t("health.agentToolOff"),
|
|
1025
|
-
}),
|
|
1026
|
-
),
|
|
1027
|
-
);
|
|
1028
|
-
if (scan.findings.length === 0) {
|
|
1029
|
-
content.push(
|
|
1030
|
-
h("div", { key: "scan-ok", style: { padding: "8px 0" } }, props.t("health.ok")),
|
|
1031
|
-
);
|
|
1032
|
-
}
|
|
1033
|
-
scan.findings.forEach((/** @type {any} */ finding, /** @type {any} */ index) => {
|
|
1034
|
-
content.push(
|
|
1510
|
+
{ className: "dsh-sdel-confirm", "data-session-delete-confirm-row": "" },
|
|
1511
|
+
h("span", null, props.t("trash.purgeManyConfirm", { n: selectedIds.length })),
|
|
1035
1512
|
h(
|
|
1036
|
-
|
|
1037
|
-
{
|
|
1038
|
-
key: `finding-${index}`,
|
|
1039
|
-
style: {
|
|
1040
|
-
borderTop: `1px solid ${T.border}`,
|
|
1041
|
-
padding: "8px 0",
|
|
1042
|
-
color: finding.severity === "warn" ? T.text : T.dim,
|
|
1043
|
-
},
|
|
1044
|
-
},
|
|
1045
|
-
h(
|
|
1046
|
-
"div",
|
|
1047
|
-
{ style: { fontWeight: 600 } },
|
|
1048
|
-
`${finding.label} · ${props.t("health.items", { n: finding.items.length })}`,
|
|
1049
|
-
),
|
|
1050
|
-
h(
|
|
1051
|
-
"div",
|
|
1052
|
-
{ style: { color: T.faint, fontSize: "12px", wordBreak: "break-all" } },
|
|
1053
|
-
finding.items
|
|
1054
|
-
.slice(0, 6)
|
|
1055
|
-
.map((/** @type {any} */ item) =>
|
|
1056
|
-
typeof item === "string" ? item : JSON.stringify(item),
|
|
1057
|
-
)
|
|
1058
|
-
.join(" · "),
|
|
1059
|
-
),
|
|
1060
|
-
),
|
|
1061
|
-
);
|
|
1062
|
-
});
|
|
1063
|
-
if (scan.cleanable && scan.cleanable.total > 0) {
|
|
1064
|
-
content.push(
|
|
1065
|
-
h(
|
|
1066
|
-
"div",
|
|
1513
|
+
Btn,
|
|
1067
1514
|
{
|
|
1068
|
-
|
|
1069
|
-
|
|
1515
|
+
tight: true,
|
|
1516
|
+
variant: "danger",
|
|
1517
|
+
action: "batch-purge-confirm",
|
|
1518
|
+
onClick: () => startBatch(selectedIds, "purge"),
|
|
1070
1519
|
},
|
|
1071
|
-
|
|
1072
|
-
? h(
|
|
1073
|
-
Btn,
|
|
1074
|
-
{
|
|
1075
|
-
danger: true,
|
|
1076
|
-
disabled: cleaning,
|
|
1077
|
-
onClick: () => {
|
|
1078
|
-
setCleaning(true);
|
|
1079
|
-
setCleanMsg("");
|
|
1080
|
-
props
|
|
1081
|
-
.call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
|
|
1082
|
-
.then((/** @type {any} */ result) => {
|
|
1083
|
-
setCleaning(false);
|
|
1084
|
-
setConfirmPurge(null);
|
|
1085
|
-
setCleanMsg(props.t("health.cleanDone", { n: result.total }));
|
|
1086
|
-
loadHealth();
|
|
1087
|
-
props.bump?.();
|
|
1088
|
-
})
|
|
1089
|
-
.catch((/** @type {any} */ reason) => {
|
|
1090
|
-
setCleaning(false);
|
|
1091
|
-
setCleanMsg(errorText(reason));
|
|
1092
|
-
});
|
|
1093
|
-
},
|
|
1094
|
-
},
|
|
1095
|
-
props.t("health.cleanConfirm", { n: scan.cleanable.total }),
|
|
1096
|
-
)
|
|
1097
|
-
: h(
|
|
1098
|
-
Btn,
|
|
1099
|
-
{ onClick: () => setConfirmPurge("__health__") },
|
|
1100
|
-
props.t("health.clean", { n: scan.cleanable.total }),
|
|
1101
|
-
),
|
|
1520
|
+
props.t("panel.purge"),
|
|
1102
1521
|
),
|
|
1103
|
-
);
|
|
1104
|
-
}
|
|
1105
|
-
if (cleanMsg) {
|
|
1106
|
-
content.push(
|
|
1107
1522
|
h(
|
|
1108
|
-
|
|
1109
|
-
{
|
|
1110
|
-
|
|
1523
|
+
Btn,
|
|
1524
|
+
{ tight: true, action: "batch-purge-cancel", onClick: () => setConfirmPurge(null) },
|
|
1525
|
+
props.t("panel.cancelConfirm"),
|
|
1111
1526
|
),
|
|
1112
|
-
)
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1527
|
+
)
|
|
1528
|
+
: null;
|
|
1529
|
+
|
|
1530
|
+
var rows = [];
|
|
1531
|
+
for (let entryIndex = 0; entryIndex < entries.length; entryIndex += 1) {
|
|
1532
|
+
const entry = entries[entryIndex];
|
|
1533
|
+
const confirmThis = confirmPurge === entry.entryId;
|
|
1534
|
+
rows.push(
|
|
1535
|
+
h(
|
|
1536
|
+
"div",
|
|
1537
|
+
{
|
|
1538
|
+
key: entry.entryId,
|
|
1539
|
+
className: "dsh-sdel-row",
|
|
1540
|
+
"data-session-delete-row": String(entry.entryId),
|
|
1541
|
+
"data-session-delete-row-session": String(entry.sessionId ?? ""),
|
|
1542
|
+
},
|
|
1543
|
+
h(Check, {
|
|
1544
|
+
checked: Boolean(selected[entry.entryId]),
|
|
1545
|
+
disabled: batchRunning,
|
|
1546
|
+
onChange: () =>
|
|
1547
|
+
setSelected((/** @type {any} */ current) => ({
|
|
1548
|
+
...current,
|
|
1549
|
+
[entry.entryId]: !current[entry.entryId],
|
|
1550
|
+
})),
|
|
1551
|
+
}),
|
|
1126
1552
|
h(
|
|
1127
|
-
"
|
|
1128
|
-
{
|
|
1129
|
-
key: "trash-tools",
|
|
1130
|
-
style: {
|
|
1131
|
-
display: "flex",
|
|
1132
|
-
gap: "8px",
|
|
1133
|
-
alignItems: "center",
|
|
1134
|
-
marginBottom: "8px",
|
|
1135
|
-
flexWrap: "wrap",
|
|
1136
|
-
},
|
|
1137
|
-
},
|
|
1553
|
+
"span",
|
|
1554
|
+
{ className: "dsh-sdel-row-text" },
|
|
1138
1555
|
h(
|
|
1139
|
-
|
|
1556
|
+
"span",
|
|
1140
1557
|
{
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
for (const item of entries) all[item.entryId] = true;
|
|
1145
|
-
setSelectedTrash(all);
|
|
1146
|
-
},
|
|
1147
|
-
disabled: trashBusy,
|
|
1558
|
+
className: "dsh-sdel-row-title dsh-sdel-truncate",
|
|
1559
|
+
title: entry.title || entry.sessionId,
|
|
1560
|
+
"data-session-delete-row-title": "",
|
|
1148
1561
|
},
|
|
1149
|
-
|
|
1150
|
-
),
|
|
1151
|
-
h(
|
|
1152
|
-
Btn,
|
|
1153
|
-
{ onClick: () => setSelectedTrash({}), disabled: trashBusy },
|
|
1154
|
-
props.t("trash.clear"),
|
|
1562
|
+
entry.title || entry.sessionId,
|
|
1155
1563
|
),
|
|
1156
1564
|
h(
|
|
1157
|
-
|
|
1158
|
-
{
|
|
1159
|
-
|
|
1160
|
-
onClick: doBatchRestore,
|
|
1161
|
-
},
|
|
1162
|
-
props.t("trash.restoreMany", { n: selectedEntryIds.length }),
|
|
1565
|
+
"span",
|
|
1566
|
+
{ className: "dsh-sdel-row-meta", "data-session-delete-row-meta": "" },
|
|
1567
|
+
`${props.t("panel.size", { size: formatBytes(entry.bytes) })} · ${props.t("panel.trashedAt", { time: formatTime(entry.trashedAt) })}`,
|
|
1163
1568
|
),
|
|
1164
|
-
|
|
1165
|
-
|
|
1569
|
+
),
|
|
1570
|
+
confirmThis
|
|
1571
|
+
? h(
|
|
1572
|
+
"span",
|
|
1573
|
+
{
|
|
1574
|
+
className: "dsh-sdel-row-actions dsh-sdel-row-actions--open",
|
|
1575
|
+
"data-session-delete-row-actions": "confirm",
|
|
1576
|
+
},
|
|
1577
|
+
h(
|
|
1166
1578
|
Btn,
|
|
1167
1579
|
{
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1580
|
+
tight: true,
|
|
1581
|
+
variant: "danger",
|
|
1582
|
+
action: "row-purge-confirm",
|
|
1583
|
+
onClick: () => doPurge(entry.entryId, entry.sessionId),
|
|
1171
1584
|
},
|
|
1172
|
-
props.t("
|
|
1173
|
-
)
|
|
1174
|
-
|
|
1585
|
+
props.t("panel.purgeConfirm"),
|
|
1586
|
+
),
|
|
1587
|
+
h(
|
|
1175
1588
|
Btn,
|
|
1176
1589
|
{
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
onClick: () => setConfirmPurge(
|
|
1590
|
+
tight: true,
|
|
1591
|
+
action: "row-purge-cancel",
|
|
1592
|
+
onClick: () => setConfirmPurge(null),
|
|
1180
1593
|
},
|
|
1181
|
-
props.t("
|
|
1594
|
+
props.t("panel.cancelConfirm"),
|
|
1182
1595
|
),
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
h(
|
|
1188
|
-
"div",
|
|
1189
|
-
{
|
|
1190
|
-
key: "trash-msg",
|
|
1191
|
-
style: { color: T.dim, fontSize: "12px", marginBottom: "6px" },
|
|
1192
|
-
},
|
|
1193
|
-
trashMsg,
|
|
1194
|
-
),
|
|
1195
|
-
);
|
|
1196
|
-
}
|
|
1197
|
-
entries.forEach((/** @type {any} */ entry) => {
|
|
1198
|
-
content.push(
|
|
1199
|
-
h(
|
|
1200
|
-
"div",
|
|
1201
|
-
{ key: entry.entryId, style: rowStyle },
|
|
1202
|
-
h(
|
|
1203
|
-
"label",
|
|
1204
|
-
{ style: { display: "flex", alignItems: "baseline", gap: "8px" } },
|
|
1205
|
-
h("input", {
|
|
1206
|
-
type: "checkbox",
|
|
1207
|
-
checked: Boolean(/** @type {any} */ (selectedTrash)[entry.entryId]),
|
|
1208
|
-
disabled: trashBusy,
|
|
1209
|
-
onChange: () =>
|
|
1210
|
-
setSelectedTrash((/** @type {any} */ current) => ({
|
|
1211
|
-
...current,
|
|
1212
|
-
[entry.entryId]: !current[entry.entryId],
|
|
1213
|
-
})),
|
|
1214
|
-
style: { marginTop: "2px" },
|
|
1215
|
-
}),
|
|
1216
|
-
h("span", { style: { fontWeight: 600 } }, entry.title || entry.sessionId),
|
|
1217
|
-
),
|
|
1218
|
-
h(
|
|
1219
|
-
"div",
|
|
1220
|
-
{ style: { color: T.dim, fontSize: "12px" } },
|
|
1221
|
-
props.t("panel.size", { size: formatBytes(entry.bytes) }) +
|
|
1222
|
-
" · " +
|
|
1223
|
-
props.t("panel.trashedAt", { time: formatTime(entry.trashedAt) }),
|
|
1224
|
-
),
|
|
1225
|
-
h(
|
|
1226
|
-
"div",
|
|
1227
|
-
{ style: { display: "flex", gap: "8px", marginTop: "6px" } },
|
|
1596
|
+
)
|
|
1597
|
+
: h(
|
|
1598
|
+
"span",
|
|
1599
|
+
{ className: "dsh-sdel-row-actions", "data-session-delete-row-actions": "" },
|
|
1228
1600
|
h(
|
|
1229
1601
|
Btn,
|
|
1230
1602
|
{
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1603
|
+
tight: true,
|
|
1604
|
+
action: "row-restore",
|
|
1605
|
+
disabled: busyId === entry.entryId || batchRunning,
|
|
1606
|
+
onClick: () => doRestore(entry.entryId, entry.sessionId),
|
|
1235
1607
|
},
|
|
1236
1608
|
props.t("panel.restore"),
|
|
1237
1609
|
),
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
)
|
|
1250
|
-
: h(
|
|
1251
|
-
Btn,
|
|
1252
|
-
{
|
|
1253
|
-
onClick: () => {
|
|
1254
|
-
setConfirmPurge(entry.entryId);
|
|
1255
|
-
},
|
|
1256
|
-
danger: true,
|
|
1257
|
-
},
|
|
1258
|
-
props.t("panel.purge"),
|
|
1259
|
-
),
|
|
1610
|
+
h(
|
|
1611
|
+
Btn,
|
|
1612
|
+
{
|
|
1613
|
+
tight: true,
|
|
1614
|
+
variant: "danger",
|
|
1615
|
+
action: "row-purge",
|
|
1616
|
+
disabled: busyId === entry.entryId || batchRunning,
|
|
1617
|
+
onClick: () => setConfirmPurge(entry.entryId),
|
|
1618
|
+
},
|
|
1619
|
+
props.t("panel.purge"),
|
|
1620
|
+
),
|
|
1260
1621
|
),
|
|
1261
|
-
),
|
|
1262
|
-
);
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
} else if ((audit || []).length === 0) {
|
|
1266
|
-
content.push(
|
|
1267
|
-
h(
|
|
1268
|
-
"div",
|
|
1269
|
-
{ key: "ae", style: { color: T.dim, padding: "12px 0" } },
|
|
1270
|
-
props.t("panel.auditEmpty"),
|
|
1271
1622
|
),
|
|
1272
1623
|
);
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
var body = h(
|
|
1627
|
+
React.Fragment,
|
|
1628
|
+
null,
|
|
1629
|
+
readOnly
|
|
1630
|
+
? h(
|
|
1631
|
+
"div",
|
|
1632
|
+
{
|
|
1633
|
+
style: { color: T.danger, marginBottom: "10px" },
|
|
1634
|
+
"data-session-delete-readonly": "",
|
|
1635
|
+
},
|
|
1636
|
+
props.t("panel.readOnly"),
|
|
1637
|
+
)
|
|
1638
|
+
: null,
|
|
1639
|
+
error
|
|
1640
|
+
? h(
|
|
1641
|
+
"div",
|
|
1642
|
+
{ style: { color: T.danger, marginBottom: "10px" }, "data-session-delete-error": "" },
|
|
1643
|
+
error,
|
|
1644
|
+
)
|
|
1645
|
+
: null,
|
|
1646
|
+
restoreDetail
|
|
1647
|
+
? h(
|
|
1648
|
+
"div",
|
|
1649
|
+
{
|
|
1650
|
+
className: "dsh-sdel-restore-detail",
|
|
1651
|
+
"data-session-delete-restore-detail": "",
|
|
1652
|
+
role: "alert",
|
|
1653
|
+
style: {
|
|
1654
|
+
border: `1px solid ${T.border}`,
|
|
1655
|
+
borderRadius: "8px",
|
|
1656
|
+
padding: "8px 10px",
|
|
1657
|
+
marginBottom: "10px",
|
|
1658
|
+
fontSize: "12px",
|
|
1659
|
+
color: T.dim,
|
|
1660
|
+
},
|
|
1661
|
+
},
|
|
1279
1662
|
h(
|
|
1280
1663
|
"div",
|
|
1281
|
-
{
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
h("span", { style: { color: T.faint } }, `${formatTime(entry.ts)} `),
|
|
1286
|
-
h("span", { style: { fontWeight: 600 } }, `${String(entry.action || "")} `),
|
|
1664
|
+
{ style: { color: T.danger, fontWeight: 600, marginBottom: "4px" } },
|
|
1665
|
+
props.t("restore.detail.title"),
|
|
1666
|
+
),
|
|
1667
|
+
restoreDetail.failures.map((/** @type {any} */ item, /** @type {number} */ index) =>
|
|
1287
1668
|
h(
|
|
1288
|
-
"
|
|
1289
|
-
{
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1669
|
+
"div",
|
|
1670
|
+
{
|
|
1671
|
+
key: `restore-failure-${index}`,
|
|
1672
|
+
className: "dsh-sdel-truncate",
|
|
1673
|
+
title: `${item.label}:${item.detail}`,
|
|
1674
|
+
"data-session-delete-restore-failure": item.id,
|
|
1675
|
+
},
|
|
1676
|
+
`${item.label}:${item.detail}`,
|
|
1293
1677
|
),
|
|
1294
1678
|
),
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1679
|
+
restoreDetail.result?.wasLive === true
|
|
1680
|
+
? h(
|
|
1681
|
+
"div",
|
|
1682
|
+
{ style: { marginTop: "6px", color: T.faint } },
|
|
1683
|
+
props.t("restore.busyHint"),
|
|
1684
|
+
)
|
|
1685
|
+
: null,
|
|
1686
|
+
h(
|
|
1687
|
+
"div",
|
|
1688
|
+
{ style: { marginTop: "8px" } },
|
|
1689
|
+
h(
|
|
1690
|
+
Btn,
|
|
1691
|
+
{
|
|
1692
|
+
tight: true,
|
|
1693
|
+
action: "restore-retry",
|
|
1694
|
+
disabled: retrying,
|
|
1695
|
+
onClick: retryFailedRefs,
|
|
1696
|
+
},
|
|
1697
|
+
retrying ? props.t("restore.detail.retrying") : props.t("restore.detail.retry"),
|
|
1698
|
+
),
|
|
1699
|
+
),
|
|
1700
|
+
)
|
|
1701
|
+
: null,
|
|
1702
|
+
entries.length === 0
|
|
1703
|
+
? h(
|
|
1704
|
+
"div",
|
|
1705
|
+
{ "data-session-delete-panel": "", "data-session-delete-empty": "" },
|
|
1706
|
+
h("div", { style: { color: T.dim, padding: "12px 0" } }, props.t("panel.empty")),
|
|
1707
|
+
)
|
|
1708
|
+
: h(
|
|
1709
|
+
"div",
|
|
1710
|
+
{ className: "dsh-sdel-panel", "data-session-delete-panel": "" },
|
|
1711
|
+
toolbar,
|
|
1712
|
+
confirmLine,
|
|
1713
|
+
batchLine,
|
|
1714
|
+
h("div", { className: "dsh-sdel-list", "data-session-delete-list": "" }, rows),
|
|
1715
|
+
),
|
|
1716
|
+
(data?.unknown?.length ?? 0) > 0
|
|
1717
|
+
? h(
|
|
1718
|
+
"div",
|
|
1719
|
+
{
|
|
1720
|
+
style: { color: T.faint, fontSize: "12px", marginTop: "8px" },
|
|
1721
|
+
"data-session-delete-unknown": "",
|
|
1722
|
+
},
|
|
1723
|
+
props.t("panel.unknown", { n: data.unknown.length }),
|
|
1724
|
+
)
|
|
1725
|
+
: null,
|
|
1726
|
+
(data?.pending?.length ?? 0) > 0
|
|
1727
|
+
? h(
|
|
1728
|
+
"div",
|
|
1729
|
+
{
|
|
1730
|
+
style: { color: T.faint, fontSize: "12px", marginTop: "4px" },
|
|
1731
|
+
"data-session-delete-pending": "",
|
|
1732
|
+
},
|
|
1733
|
+
props.t("panel.pending", { n: data.pending.length }),
|
|
1734
|
+
)
|
|
1735
|
+
: null,
|
|
1736
|
+
);
|
|
1298
1737
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1738
|
+
return h(
|
|
1739
|
+
Dialog,
|
|
1740
|
+
{
|
|
1741
|
+
onClose: () => {
|
|
1742
|
+
if (batchRunning) return;
|
|
1743
|
+
props.panelStore.set(false);
|
|
1744
|
+
},
|
|
1745
|
+
closeLabel: props.t("panel.close"),
|
|
1746
|
+
title: props.t("panel.title"),
|
|
1747
|
+
footer: h(
|
|
1748
|
+
Btn,
|
|
1749
|
+
{
|
|
1750
|
+
onClick: () => {
|
|
1751
|
+
props.panelStore.set(false);
|
|
1752
|
+
},
|
|
1753
|
+
disabled: batchRunning,
|
|
1754
|
+
},
|
|
1755
|
+
props.t("panel.close"),
|
|
1756
|
+
),
|
|
1757
|
+
},
|
|
1758
|
+
body,
|
|
1759
|
+
);
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* 一条操作回执:摘要一行,展开后逐项列出引用/校验结果(USIM-U3-05)。
|
|
1764
|
+
* 用户被 toast 指引来「详见操作回执」,这里就必须真的能查到是哪一处没通过,
|
|
1765
|
+
* 并且对恢复回执提供「重试未通过的引用」。
|
|
1766
|
+
*/
|
|
1767
|
+
function ReceiptRow(/** @type {any} */ props) {
|
|
1768
|
+
var receipt = props.receipt || {};
|
|
1769
|
+
var retryingState = React.useState(false);
|
|
1770
|
+
var retrying = retryingState[0];
|
|
1771
|
+
var setRetrying = retryingState[1];
|
|
1772
|
+
var noteState = React.useState(null);
|
|
1773
|
+
var note = noteState[0];
|
|
1774
|
+
var setNote = noteState[1];
|
|
1775
|
+
var refs = Array.isArray(receipt.refs) ? receipt.refs : [];
|
|
1776
|
+
var checks = Array.isArray(receipt.checks) ? receipt.checks : [];
|
|
1777
|
+
var failures = restoreFailures(receipt);
|
|
1778
|
+
var action = String(receipt.action || "");
|
|
1779
|
+
// B1(复审):没有 `expected` 快照的旧回执不能重检——服务端也会拒绝,
|
|
1780
|
+
// 这里先不给按钮,别让用户点出一个假的「重检通过」。
|
|
1781
|
+
var hasSnapshot = receipt.expected !== null && typeof receipt.expected === "object";
|
|
1782
|
+
var retryable =
|
|
1783
|
+
failures.length > 0 &&
|
|
1784
|
+
(action === "restore" || action === "restore-recheck") &&
|
|
1785
|
+
typeof receipt.sessionId === "string" &&
|
|
1786
|
+
hasSnapshot &&
|
|
1787
|
+
typeof props.call === "function";
|
|
1788
|
+
|
|
1789
|
+
/** @type {any[]} */
|
|
1790
|
+
var detailLines = [];
|
|
1791
|
+
/** @param {string} title @param {any[]} items @param {string} keyPrefix */
|
|
1792
|
+
var pushGroup = (title, items, keyPrefix) => {
|
|
1793
|
+
if (items.length === 0) return;
|
|
1794
|
+
detailLines.push(
|
|
1301
1795
|
h(
|
|
1302
1796
|
"div",
|
|
1303
|
-
{ key:
|
|
1304
|
-
|
|
1797
|
+
{ key: `${keyPrefix}-title`, style: { color: T.faint, marginTop: "4px" } },
|
|
1798
|
+
title,
|
|
1305
1799
|
),
|
|
1306
1800
|
);
|
|
1801
|
+
items.forEach((/** @type {any} */ item, /** @type {number} */ index) => {
|
|
1802
|
+
var status = String(item?.status || "");
|
|
1803
|
+
var label = String(item?.label || item?.id || "");
|
|
1804
|
+
var detail = item?.detail ? String(item.detail) : "";
|
|
1805
|
+
var mark = status === "ok" ? "✓" : status === "failed" ? "✗" : "·";
|
|
1806
|
+
detailLines.push(
|
|
1807
|
+
h(
|
|
1808
|
+
"div",
|
|
1809
|
+
{
|
|
1810
|
+
key: `${keyPrefix}-${index}`,
|
|
1811
|
+
style: { color: status === "failed" ? T.danger : T.dim },
|
|
1812
|
+
"data-session-delete-receipt-item": `${item?.id || ""}:${status}`,
|
|
1813
|
+
},
|
|
1814
|
+
`${mark} ${label}${detail ? `:${detail}` : ""}${item?.retried === true ? `(${props.t("restore.detail.retried")})` : ""}`,
|
|
1815
|
+
),
|
|
1816
|
+
);
|
|
1817
|
+
});
|
|
1818
|
+
};
|
|
1819
|
+
pushGroup(props.t("receipt.refs"), refs, "refs");
|
|
1820
|
+
// trash 回执的引用清单在 `removed` 里(N3):两者都渲染,文案才对得上
|
|
1821
|
+
// README 的「show every reference and check」。
|
|
1822
|
+
var removed = Array.isArray(receipt.removed) ? receipt.removed : [];
|
|
1823
|
+
pushGroup(props.t("receipt.removed"), removed, "removed");
|
|
1824
|
+
pushGroup(props.t("receipt.checks"), checks, "checks");
|
|
1825
|
+
|
|
1826
|
+
var summaryText = `${formatTime(receipt.at)} · ${action} · ${String(receipt.title || receipt.sessionId || "")}`;
|
|
1827
|
+
if (refs.length > 0 || checks.length > 0) {
|
|
1828
|
+
summaryText +=
|
|
1829
|
+
failures.length > 0
|
|
1830
|
+
? ` · ${props.t("receipt.summary.partial", { n: failures.length })}`
|
|
1831
|
+
: ` · ${props.t("receipt.summary.ok")}`;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
return h(
|
|
1835
|
+
"details",
|
|
1836
|
+
{
|
|
1837
|
+
className: "dsh-sdel-receipt",
|
|
1838
|
+
"data-session-delete-receipt": String(receipt.id || ""),
|
|
1839
|
+
style: { padding: "2px 0" },
|
|
1840
|
+
},
|
|
1841
|
+
h("summary", { className: "dsh-sdel-truncate", title: summaryText }, summaryText),
|
|
1842
|
+
detailLines.length > 0
|
|
1843
|
+
? h(
|
|
1844
|
+
"div",
|
|
1845
|
+
{ style: { padding: "4px 0 4px 12px", fontSize: "12px", lineHeight: 1.5 } },
|
|
1846
|
+
detailLines,
|
|
1847
|
+
)
|
|
1848
|
+
: null,
|
|
1849
|
+
receipt.wasLive === true
|
|
1850
|
+
? h(
|
|
1851
|
+
"div",
|
|
1852
|
+
{ style: { padding: "0 0 4px 12px", fontSize: "12px", color: T.faint } },
|
|
1853
|
+
props.t("restore.busyHint"),
|
|
1854
|
+
)
|
|
1855
|
+
: null,
|
|
1856
|
+
retryable
|
|
1857
|
+
? h(
|
|
1858
|
+
"div",
|
|
1859
|
+
{ style: { padding: "0 0 4px 12px" } },
|
|
1860
|
+
h(
|
|
1861
|
+
Btn,
|
|
1862
|
+
{
|
|
1863
|
+
tight: true,
|
|
1864
|
+
action: "receipt-restore-retry",
|
|
1865
|
+
disabled: retrying,
|
|
1866
|
+
onClick: () => {
|
|
1867
|
+
if (retrying) return;
|
|
1868
|
+
setRetrying(true);
|
|
1869
|
+
props
|
|
1870
|
+
.call("recheckRestore", {
|
|
1871
|
+
receiptId: typeof receipt.id === "string" ? receipt.id : undefined,
|
|
1872
|
+
sessionId: receipt.sessionId,
|
|
1873
|
+
})
|
|
1874
|
+
.then((/** @type {any} */ result) => {
|
|
1875
|
+
setRetrying(false);
|
|
1876
|
+
var left = restoreFailures(result);
|
|
1877
|
+
setNote(
|
|
1878
|
+
left.length === 0
|
|
1879
|
+
? props.t("restore.retry.ok")
|
|
1880
|
+
: props.t("restore.retry.partial", { n: left.length }),
|
|
1881
|
+
);
|
|
1882
|
+
props.onChanged?.();
|
|
1883
|
+
})
|
|
1884
|
+
.catch((/** @type {any} */ reason) => {
|
|
1885
|
+
setRetrying(false);
|
|
1886
|
+
setNote(errorText(reason));
|
|
1887
|
+
});
|
|
1888
|
+
},
|
|
1889
|
+
},
|
|
1890
|
+
retrying ? props.t("restore.detail.retrying") : props.t("restore.detail.retry"),
|
|
1891
|
+
),
|
|
1892
|
+
note ? h("div", { style: { color: T.faint, marginTop: "4px" } }, String(note)) : null,
|
|
1893
|
+
)
|
|
1894
|
+
: null,
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
/**
|
|
1899
|
+
* 设置页「会话回收站」:偏好 + 回收站概览 + 维护(体检/回执/审计)。
|
|
1900
|
+
* 原来这四块是回收站面板里的四个页签,搬到这里后主面板只剩一件事。
|
|
1901
|
+
*/
|
|
1902
|
+
/** 设置页体检结论的页面级缓存:重开设置页复用,不重复扫全库(AUD-SD-08)。 */
|
|
1903
|
+
var settingsHealthCache = createSettingsCache();
|
|
1904
|
+
|
|
1905
|
+
function SettingsSection(/** @type {any} */ props) {
|
|
1906
|
+
var prefsState = useStore(props.prefsStore);
|
|
1907
|
+
var prefs = prefsState[0];
|
|
1908
|
+
var infoState = React.useState(null);
|
|
1909
|
+
var info = infoState[0];
|
|
1910
|
+
var setInfo = infoState[1];
|
|
1911
|
+
var healthState = React.useState(settingsHealthCache.health);
|
|
1912
|
+
var health = healthState[0];
|
|
1913
|
+
var setHealth = healthState[1];
|
|
1914
|
+
var healthErrorState = React.useState(null);
|
|
1915
|
+
var healthError = healthErrorState[0];
|
|
1916
|
+
var setHealthError = healthErrorState[1];
|
|
1917
|
+
var receiptsState = React.useState(null);
|
|
1918
|
+
var receipts = receiptsState[0];
|
|
1919
|
+
var setReceipts = receiptsState[1];
|
|
1920
|
+
var auditState = React.useState(null);
|
|
1921
|
+
var audit = auditState[0];
|
|
1922
|
+
var setAudit = auditState[1];
|
|
1923
|
+
var scanningState = React.useState(false);
|
|
1924
|
+
var scanning = scanningState[0];
|
|
1925
|
+
var setScanning = scanningState[1];
|
|
1926
|
+
var cleaningState = React.useState(false);
|
|
1927
|
+
var cleaning = cleaningState[0];
|
|
1928
|
+
var setCleaning = cleaningState[1];
|
|
1929
|
+
var confirmCleanState = React.useState(false);
|
|
1930
|
+
var confirmClean = confirmCleanState[0];
|
|
1931
|
+
var setConfirmClean = confirmCleanState[1];
|
|
1932
|
+
var msgState = React.useState("");
|
|
1933
|
+
var message = msgState[0];
|
|
1934
|
+
var setMessage = msgState[1];
|
|
1935
|
+
|
|
1936
|
+
var loader = React.useMemo(
|
|
1937
|
+
() =>
|
|
1938
|
+
createSettingsLoader(
|
|
1939
|
+
props.call,
|
|
1940
|
+
{
|
|
1941
|
+
setInfo: setInfo,
|
|
1942
|
+
setReceipts: setReceipts,
|
|
1943
|
+
setAudit: setAudit,
|
|
1944
|
+
setHealth: setHealth,
|
|
1945
|
+
setHealthError: setHealthError,
|
|
1946
|
+
setMessage: setMessage,
|
|
1947
|
+
},
|
|
1948
|
+
settingsHealthCache,
|
|
1949
|
+
),
|
|
1950
|
+
[],
|
|
1951
|
+
);
|
|
1952
|
+
|
|
1953
|
+
React.useEffect(() => {
|
|
1954
|
+
// 只拉轻量数据;体检是用户动作(曾经一挂载就跑全库扫描,见 AUD-SD-08)。
|
|
1955
|
+
void loader.load();
|
|
1956
|
+
}, []);
|
|
1957
|
+
|
|
1958
|
+
var entries = info?.entries || [];
|
|
1959
|
+
var totalBytes = 0;
|
|
1960
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
1961
|
+
totalBytes += Number(entries[index].bytes) || 0;
|
|
1307
1962
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1963
|
+
var cascade = prefs ? prefs.cascadeChildren === true : false;
|
|
1964
|
+
|
|
1965
|
+
var setCascade = (/** @type {any} */ next) => {
|
|
1966
|
+
props.prefsStore.set({ cascadeChildren: next });
|
|
1967
|
+
props.call("setPrefs", { cascadeChildren: next }).catch(() => {});
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
var runScan = () => {
|
|
1971
|
+
setScanning(true);
|
|
1972
|
+
loader.scanHealth().then(() => {
|
|
1973
|
+
setScanning(false);
|
|
1974
|
+
});
|
|
1975
|
+
};
|
|
1976
|
+
|
|
1977
|
+
var cleanable = health?.ok ? health.cleanable : null;
|
|
1978
|
+
var cleanRows = [];
|
|
1979
|
+
if (confirmClean && cleanable && cleanable.total > 0) {
|
|
1980
|
+
cleanRows.push(
|
|
1310
1981
|
h(
|
|
1311
1982
|
"div",
|
|
1312
|
-
{ key: "
|
|
1313
|
-
|
|
1983
|
+
{ key: "confirm", style: { display: "flex", gap: "8px", alignItems: "center" } },
|
|
1984
|
+
h(
|
|
1985
|
+
"span",
|
|
1986
|
+
{ style: { color: T.danger, fontSize: "12px" } },
|
|
1987
|
+
props.t("settings.health.cleanConfirm", { n: cleanable.total }),
|
|
1988
|
+
),
|
|
1989
|
+
h(
|
|
1990
|
+
Btn,
|
|
1991
|
+
{
|
|
1992
|
+
tight: true,
|
|
1993
|
+
variant: "danger",
|
|
1994
|
+
action: "health-clean",
|
|
1995
|
+
disabled: cleaning,
|
|
1996
|
+
onClick: () => {
|
|
1997
|
+
setCleaning(true);
|
|
1998
|
+
props
|
|
1999
|
+
.call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
|
|
2000
|
+
.then((/** @type {any} */ result) => {
|
|
2001
|
+
setCleaning(false);
|
|
2002
|
+
setConfirmClean(false);
|
|
2003
|
+
setMessage(props.t("settings.health.cleaned", { n: result.total }));
|
|
2004
|
+
// 刚清理过,缓存里的数字已经不对了:重新扫一次让结论刷新。
|
|
2005
|
+
return loader.scanHealth();
|
|
2006
|
+
})
|
|
2007
|
+
.catch((/** @type {any} */ reason) => {
|
|
2008
|
+
setCleaning(false);
|
|
2009
|
+
setMessage(errorText(reason));
|
|
2010
|
+
});
|
|
2011
|
+
},
|
|
2012
|
+
},
|
|
2013
|
+
props.t("settings.health.clean", { n: cleanable.total }),
|
|
2014
|
+
),
|
|
2015
|
+
h(
|
|
2016
|
+
Btn,
|
|
2017
|
+
{ tight: true, action: "health-clean-cancel", onClick: () => setConfirmClean(false) },
|
|
2018
|
+
props.t("confirm.cancel"),
|
|
2019
|
+
),
|
|
1314
2020
|
),
|
|
1315
2021
|
);
|
|
1316
2022
|
}
|
|
1317
2023
|
|
|
1318
2024
|
return h(
|
|
1319
|
-
|
|
1320
|
-
{
|
|
1321
|
-
|
|
1322
|
-
|
|
2025
|
+
"div",
|
|
2026
|
+
{ className: "dsh-sdel-settings", "data-session-delete-settings": "" },
|
|
2027
|
+
h(
|
|
2028
|
+
"div",
|
|
2029
|
+
{ className: "dsh-sdel-group", "data-session-delete-group": "delete" },
|
|
2030
|
+
props.t("settings.group.delete"),
|
|
2031
|
+
),
|
|
2032
|
+
h(SettingRow, {
|
|
2033
|
+
anchor: "cascade",
|
|
2034
|
+
title: props.t("settings.cascade.title"),
|
|
2035
|
+
description: props.t("settings.cascade.desc"),
|
|
2036
|
+
action: h(Toggle, {
|
|
2037
|
+
checked: cascade,
|
|
2038
|
+
label: props.t("settings.cascade.title"),
|
|
2039
|
+
onChange: setCascade,
|
|
2040
|
+
}),
|
|
2041
|
+
}),
|
|
2042
|
+
h(SettingRow, {
|
|
2043
|
+
anchor: "cascade-reset",
|
|
2044
|
+
title: "",
|
|
2045
|
+
description: null,
|
|
2046
|
+
action: h(
|
|
2047
|
+
Btn,
|
|
2048
|
+
{
|
|
2049
|
+
tight: true,
|
|
2050
|
+
action: "cascade-reset",
|
|
2051
|
+
disabled: !cascade,
|
|
2052
|
+
onClick: () => {
|
|
2053
|
+
setCascade(false);
|
|
2054
|
+
setMessage(props.t("settings.cascade.resetDone"));
|
|
2055
|
+
},
|
|
2056
|
+
},
|
|
2057
|
+
props.t("settings.cascade.reset"),
|
|
2058
|
+
),
|
|
2059
|
+
}),
|
|
2060
|
+
h(
|
|
2061
|
+
"div",
|
|
2062
|
+
{ className: "dsh-sdel-group", "data-session-delete-group": "trash" },
|
|
2063
|
+
props.t("settings.group.trash"),
|
|
2064
|
+
),
|
|
2065
|
+
h(SettingRow, {
|
|
2066
|
+
anchor: "trash",
|
|
2067
|
+
title: props.t("settings.trash.summary", {
|
|
2068
|
+
n: entries.length,
|
|
2069
|
+
size: formatBytes(totalBytes),
|
|
2070
|
+
}),
|
|
2071
|
+
description: info ? info.trashRoot : null,
|
|
2072
|
+
action: h(
|
|
2073
|
+
Btn,
|
|
2074
|
+
{
|
|
2075
|
+
tight: true,
|
|
2076
|
+
action: "open-trash",
|
|
2077
|
+
onClick: () => {
|
|
2078
|
+
props.close?.();
|
|
2079
|
+
props.panelStore.set(true);
|
|
2080
|
+
},
|
|
2081
|
+
},
|
|
2082
|
+
props.t("settings.trash.open"),
|
|
2083
|
+
),
|
|
2084
|
+
}),
|
|
2085
|
+
h(
|
|
2086
|
+
"div",
|
|
2087
|
+
{ className: "dsh-sdel-group", "data-session-delete-group": "maintenance" },
|
|
2088
|
+
props.t("settings.group.maintenance"),
|
|
2089
|
+
),
|
|
2090
|
+
h(
|
|
2091
|
+
"div",
|
|
2092
|
+
{
|
|
2093
|
+
"data-session-delete-health": "",
|
|
2094
|
+
"data-session-delete-health-state": healthError
|
|
2095
|
+
? "error"
|
|
2096
|
+
: scanning
|
|
2097
|
+
? "scanning"
|
|
2098
|
+
: health
|
|
2099
|
+
? health.ok
|
|
2100
|
+
? "ok"
|
|
2101
|
+
: "unavailable"
|
|
2102
|
+
: "idle",
|
|
2103
|
+
},
|
|
2104
|
+
h(SettingRow, {
|
|
2105
|
+
anchor: "health",
|
|
2106
|
+
title: props.t("settings.health.title"),
|
|
2107
|
+
description: props.t("settings.health.desc"),
|
|
2108
|
+
action: h(
|
|
2109
|
+
React.Fragment,
|
|
2110
|
+
null,
|
|
2111
|
+
h(
|
|
2112
|
+
Btn,
|
|
2113
|
+
{ tight: true, action: "health-run", disabled: scanning, onClick: runScan },
|
|
2114
|
+
props.t("settings.health.run"),
|
|
2115
|
+
),
|
|
2116
|
+
cleanable && cleanable.total > 0
|
|
2117
|
+
? h(
|
|
2118
|
+
Btn,
|
|
2119
|
+
{
|
|
2120
|
+
tight: true,
|
|
2121
|
+
action: "health-clean-confirm",
|
|
2122
|
+
disabled: cleaning,
|
|
2123
|
+
onClick: () => setConfirmClean(true),
|
|
2124
|
+
},
|
|
2125
|
+
props.t("settings.health.items", { n: cleanable.total }),
|
|
2126
|
+
)
|
|
2127
|
+
: null,
|
|
2128
|
+
),
|
|
2129
|
+
children: healthError
|
|
2130
|
+
? h(
|
|
2131
|
+
"div",
|
|
2132
|
+
{ style: { color: T.danger, fontSize: "12px" } },
|
|
2133
|
+
props.t("settings.health.unavailable", { reason: healthError }),
|
|
2134
|
+
)
|
|
2135
|
+
: scanning
|
|
2136
|
+
? h(
|
|
2137
|
+
"div",
|
|
2138
|
+
{ style: { color: T.faint, fontSize: "12px" } },
|
|
2139
|
+
props.t("settings.loading"),
|
|
2140
|
+
)
|
|
2141
|
+
: !health
|
|
2142
|
+
? h(
|
|
2143
|
+
"div",
|
|
2144
|
+
{ style: { color: T.faint, fontSize: "12px" } },
|
|
2145
|
+
props.t("settings.health.idle"),
|
|
2146
|
+
)
|
|
2147
|
+
: !health.ok
|
|
2148
|
+
? h(
|
|
2149
|
+
"div",
|
|
2150
|
+
{ style: { color: T.dim, fontSize: "12px" } },
|
|
2151
|
+
props.t("settings.health.unavailable", { reason: health.reason || "" }),
|
|
2152
|
+
)
|
|
2153
|
+
: health.findings && health.findings.length === 0
|
|
2154
|
+
? h(
|
|
2155
|
+
"div",
|
|
2156
|
+
{ style: { color: T.dim, fontSize: "12px" } },
|
|
2157
|
+
props.t("settings.health.ok"),
|
|
2158
|
+
)
|
|
2159
|
+
: h(
|
|
2160
|
+
"div",
|
|
2161
|
+
{ style: { color: T.dim, fontSize: "12px" } },
|
|
2162
|
+
joinList(
|
|
2163
|
+
(health.findings || []).map(
|
|
2164
|
+
(/** @type {any} */ finding) => finding.label,
|
|
2165
|
+
),
|
|
2166
|
+
4,
|
|
2167
|
+
),
|
|
2168
|
+
),
|
|
2169
|
+
}),
|
|
2170
|
+
),
|
|
2171
|
+
cleanRows.length > 0 ? h("div", { style: { padding: "0 0 12px" } }, cleanRows) : null,
|
|
2172
|
+
h(
|
|
2173
|
+
"div",
|
|
2174
|
+
{
|
|
2175
|
+
className: "dsh-sdel-setting-row dsh-sdel-setting-row--stack",
|
|
2176
|
+
"data-session-delete-receipts": "",
|
|
1323
2177
|
},
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
footer: h(
|
|
1327
|
-
Btn,
|
|
2178
|
+
h(
|
|
2179
|
+
Disclosure,
|
|
1328
2180
|
{
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
},
|
|
2181
|
+
anchor: "receipts",
|
|
2182
|
+
label: props.t("settings.receipts.title"),
|
|
2183
|
+
meta: receipts ? String(receipts.length) : "",
|
|
1333
2184
|
},
|
|
1334
|
-
|
|
2185
|
+
!receipts || receipts.length === 0
|
|
2186
|
+
? h("div", null, props.t("settings.receipts.empty"))
|
|
2187
|
+
: receipts.map((/** @type {any} */ receipt, /** @type {any} */ receiptIndex) =>
|
|
2188
|
+
h(ReceiptRow, {
|
|
2189
|
+
key: `receipt-${receiptIndex}`,
|
|
2190
|
+
receipt: receipt,
|
|
2191
|
+
call: props.call,
|
|
2192
|
+
t: props.t,
|
|
2193
|
+
onChanged: () => {
|
|
2194
|
+
void loader.load();
|
|
2195
|
+
},
|
|
2196
|
+
}),
|
|
2197
|
+
),
|
|
1335
2198
|
),
|
|
1336
|
-
|
|
2199
|
+
),
|
|
1337
2200
|
h(
|
|
1338
2201
|
"div",
|
|
1339
|
-
{
|
|
1340
|
-
|
|
2202
|
+
{
|
|
2203
|
+
className: "dsh-sdel-setting-row dsh-sdel-setting-row--stack",
|
|
2204
|
+
"data-session-delete-audit": "",
|
|
2205
|
+
},
|
|
2206
|
+
h(Disclosure, {
|
|
2207
|
+
anchor: "audit",
|
|
2208
|
+
label: props.t("settings.audit.title"),
|
|
2209
|
+
meta: audit ? String(audit.length) : "",
|
|
2210
|
+
children:
|
|
2211
|
+
!audit || audit.length === 0
|
|
2212
|
+
? h("div", null, props.t("settings.audit.empty"))
|
|
2213
|
+
: audit
|
|
2214
|
+
.slice()
|
|
2215
|
+
.reverse()
|
|
2216
|
+
.map((/** @type {any} */ entry, /** @type {any} */ auditIndex) =>
|
|
2217
|
+
h(
|
|
2218
|
+
"div",
|
|
2219
|
+
{ key: `audit-${auditIndex}`, className: "dsh-sdel-truncate" },
|
|
2220
|
+
`${formatTime(entry.ts)} · ${String(entry.action || "")} · ${String(entry.result || "")}${entry.detail ? ` · ${entry.detail}` : ""}`,
|
|
2221
|
+
),
|
|
2222
|
+
),
|
|
2223
|
+
}),
|
|
1341
2224
|
),
|
|
2225
|
+
message
|
|
2226
|
+
? h(
|
|
2227
|
+
"div",
|
|
2228
|
+
{
|
|
2229
|
+
style: { color: T.dim, fontSize: "12px", paddingTop: "8px" },
|
|
2230
|
+
"data-session-delete-message": "",
|
|
2231
|
+
},
|
|
2232
|
+
message,
|
|
2233
|
+
)
|
|
2234
|
+
: null,
|
|
1342
2235
|
);
|
|
1343
2236
|
}
|
|
1344
2237
|
|
|
@@ -1346,6 +2239,8 @@ window.__ModuleLoader__.load({
|
|
|
1346
2239
|
var toastState = useStore(props.toastStore);
|
|
1347
2240
|
var toast = toastState[0];
|
|
1348
2241
|
var entryId = toast ? toast.entryId : null;
|
|
2242
|
+
var text = toast ? toast.text : null;
|
|
2243
|
+
var isError = toast?.error === true;
|
|
1349
2244
|
var shownState = React.useState(false);
|
|
1350
2245
|
var shown = shownState[0];
|
|
1351
2246
|
var setShown = shownState[1];
|
|
@@ -1354,34 +2249,40 @@ window.__ModuleLoader__.load({
|
|
|
1354
2249
|
var setRestoring = restoreState[1];
|
|
1355
2250
|
|
|
1356
2251
|
React.useEffect(() => {
|
|
1357
|
-
if (!
|
|
2252
|
+
if (!toast) {
|
|
1358
2253
|
setShown(false);
|
|
1359
2254
|
return undefined;
|
|
1360
2255
|
}
|
|
1361
2256
|
var raise = setTimeout(() => {
|
|
1362
2257
|
setShown(true);
|
|
1363
2258
|
}, 10);
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
2259
|
+
// 失败要能读到:错误 toast 不自动消失(AUD-SD-09 之前 6 秒就没了)。
|
|
2260
|
+
var timer =
|
|
2261
|
+
toast.error === true
|
|
2262
|
+
? null
|
|
2263
|
+
: setTimeout(() => {
|
|
2264
|
+
props.toastStore.set(null);
|
|
2265
|
+
}, 6000);
|
|
1367
2266
|
return () => {
|
|
1368
2267
|
clearTimeout(raise);
|
|
1369
|
-
clearTimeout(timer);
|
|
2268
|
+
if (timer !== null) clearTimeout(timer);
|
|
1370
2269
|
};
|
|
1371
|
-
}, [
|
|
2270
|
+
}, [toast]);
|
|
1372
2271
|
|
|
1373
2272
|
if (!toast) return null;
|
|
1374
2273
|
return h(
|
|
1375
2274
|
"div",
|
|
1376
2275
|
{
|
|
2276
|
+
"data-session-delete-toast": isError ? "error" : "ok",
|
|
2277
|
+
role: isError ? "alert" : "status",
|
|
1377
2278
|
style: {
|
|
1378
2279
|
position: "fixed",
|
|
1379
2280
|
bottom: "24px",
|
|
1380
2281
|
right: "24px",
|
|
1381
2282
|
zIndex: 2147000000,
|
|
1382
2283
|
background: T.toastBg,
|
|
1383
|
-
color: T.toastText,
|
|
1384
|
-
border: `1px solid ${T.border}`,
|
|
2284
|
+
color: isError ? T.danger : T.toastText,
|
|
2285
|
+
border: `1px solid ${isError ? T.danger : T.border}`,
|
|
1385
2286
|
borderRadius: "10px",
|
|
1386
2287
|
padding: "10px 14px",
|
|
1387
2288
|
fontSize: "13px",
|
|
@@ -1389,34 +2290,285 @@ window.__ModuleLoader__.load({
|
|
|
1389
2290
|
display: "flex",
|
|
1390
2291
|
alignItems: "center",
|
|
1391
2292
|
gap: "12px",
|
|
2293
|
+
maxWidth: "min(520px, 92vw)",
|
|
1392
2294
|
opacity: shown ? 1 : 0,
|
|
1393
2295
|
transform: shown ? "translateY(0)" : "translateY(8px)",
|
|
1394
2296
|
transition: "opacity .18s ease, transform .18s ease",
|
|
1395
2297
|
},
|
|
1396
2298
|
},
|
|
1397
|
-
h("span",
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
2299
|
+
h("span", { "data-session-delete-toast-text": "" }, text ? text : props.t("confirm.done")),
|
|
2300
|
+
isError
|
|
2301
|
+
? h(
|
|
2302
|
+
Btn,
|
|
2303
|
+
{
|
|
2304
|
+
tight: true,
|
|
2305
|
+
action: "toast-dismiss",
|
|
2306
|
+
onClick: () => props.toastStore.set(null),
|
|
2307
|
+
},
|
|
2308
|
+
props.t("panel.close"),
|
|
2309
|
+
)
|
|
2310
|
+
: null,
|
|
2311
|
+
entryId
|
|
2312
|
+
? h(
|
|
2313
|
+
Btn,
|
|
2314
|
+
{
|
|
2315
|
+
disabled: restoring,
|
|
2316
|
+
action: "undo",
|
|
2317
|
+
onClick: () => {
|
|
2318
|
+
setRestoring(true);
|
|
2319
|
+
props
|
|
2320
|
+
.call("restore", { entryId: toast.entryId })
|
|
2321
|
+
.then((/** @type {any} */ result) => {
|
|
2322
|
+
setRestoring(false);
|
|
2323
|
+
var notice = restoreNotice(result, props.t);
|
|
2324
|
+
if (notice) {
|
|
2325
|
+
// 会话回来了但引用没全回来:说清楚,别让人以为完整撤销了。
|
|
2326
|
+
props.toastStore.set({ text: notice, error: true });
|
|
2327
|
+
return;
|
|
2328
|
+
}
|
|
2329
|
+
props.toastStore.set(null);
|
|
2330
|
+
props.onRestored?.(result?.sessionId);
|
|
2331
|
+
props.bump?.();
|
|
2332
|
+
})
|
|
2333
|
+
.catch((/** @type {any} */ reason) => {
|
|
2334
|
+
setRestoring(false);
|
|
2335
|
+
// 撤销失败曾经完全静默(AUD-SD-09):现在留在 toast 里直到用户关掉。
|
|
2336
|
+
props.toastStore.set({
|
|
2337
|
+
text: props.t("toast.undoFailed", { message: errorText(reason) }),
|
|
2338
|
+
error: true,
|
|
2339
|
+
});
|
|
2340
|
+
});
|
|
2341
|
+
},
|
|
2342
|
+
},
|
|
2343
|
+
props.t("confirm.undo"),
|
|
2344
|
+
)
|
|
2345
|
+
: null,
|
|
1417
2346
|
);
|
|
1418
2347
|
}
|
|
1419
2348
|
|
|
2349
|
+
/** 面板打开后的轮询间隔:外部(agent 工具 / 另一个窗口)改了回收站也要跟上。 */
|
|
2350
|
+
var PANEL_POLL_MS = 5000;
|
|
2351
|
+
|
|
2352
|
+
/**
|
|
2353
|
+
* 加载回收站面板的数据。抽出来是为了单测能直接驱动它 —— 面板的加载失败
|
|
2354
|
+
* 不许把整个浮层(确认框、toast)一起拖死,这个行为必须在没有浏览器的地方也能验证。
|
|
2355
|
+
* @param {(method: string, request?: any) => Promise<any>} call
|
|
2356
|
+
* @param {{ setData?: (value: any) => void, setReadOnly?: (value: boolean) => void,
|
|
2357
|
+
* setError?: (value: string | null) => void }} sinks
|
|
2358
|
+
* @returns {{ load: () => Promise<any>, loadHealth: () => Promise<void> }}
|
|
2359
|
+
*/
|
|
2360
|
+
function createPanelLoader(call, sinks) {
|
|
2361
|
+
var report = (/** @type {any} */ reason) => {
|
|
2362
|
+
try {
|
|
2363
|
+
sinks.setError?.(errorText(reason));
|
|
2364
|
+
} catch (_error) {
|
|
2365
|
+
/* 渲染层挂了也不该让 RPC 的 rejection 逃逸成未捕获异常 */
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
var load = () =>
|
|
2369
|
+
Promise.resolve()
|
|
2370
|
+
.then(() => call("list"))
|
|
2371
|
+
.then(
|
|
2372
|
+
(/** @type {any} */ value) => {
|
|
2373
|
+
try {
|
|
2374
|
+
sinks.setData?.(value);
|
|
2375
|
+
} catch (_error) {}
|
|
2376
|
+
return value;
|
|
2377
|
+
},
|
|
2378
|
+
(/** @type {any} */ reason) => {
|
|
2379
|
+
report(reason);
|
|
2380
|
+
return null;
|
|
2381
|
+
},
|
|
2382
|
+
);
|
|
2383
|
+
var loadHealth = () =>
|
|
2384
|
+
Promise.resolve()
|
|
2385
|
+
.then(() => call("health"))
|
|
2386
|
+
.then(
|
|
2387
|
+
(/** @type {any} */ value) => {
|
|
2388
|
+
try {
|
|
2389
|
+
sinks.setReadOnly?.(value?.readOnly === true);
|
|
2390
|
+
} catch (_error) {}
|
|
2391
|
+
},
|
|
2392
|
+
() => {
|
|
2393
|
+
/* 能力快照拿不到只影响只读横幅,不报错 */
|
|
2394
|
+
},
|
|
2395
|
+
);
|
|
2396
|
+
return { load: load, loadHealth: loadHealth };
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
/**
|
|
2400
|
+
* 设置页体检结论的缓存(AUD-SD-08):页面会话内复用,重开设置页不再扫全库。
|
|
2401
|
+
*/
|
|
2402
|
+
function createSettingsCache() {
|
|
2403
|
+
return { health: /** @type {any} */ (null), healthAt: 0 };
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
/**
|
|
2407
|
+
* 设置页加载器。设计目标(ADR 0004 §7):
|
|
2408
|
+
* - 挂载时只拉轻量数据(list / receipts / audit),**绝不**自动跑全库体检;
|
|
2409
|
+
* - 体检是用户动作(`scanHealth()`),结果写进缓存供下次打开复用;
|
|
2410
|
+
* - 任何一个请求失败都只影响自己那一块,不许把设置页整体打挂。
|
|
2411
|
+
* @param {(method: string, request?: any) => Promise<any>} call
|
|
2412
|
+
* @param {{ setInfo?: (value: any) => void, setReceipts?: (value: any) => void,
|
|
2413
|
+
* setAudit?: (value: any) => void, setHealth?: (value: any) => void,
|
|
2414
|
+
* setHealthError?: (value: any) => void, setMessage?: (value: string) => void }} sinks
|
|
2415
|
+
* @param {{ health: any, healthAt: number }} [cache]
|
|
2416
|
+
*/
|
|
2417
|
+
function createSettingsLoader(call, sinks, cache) {
|
|
2418
|
+
var shared = cache || createSettingsCache();
|
|
2419
|
+
/**
|
|
2420
|
+
* @param {((value: any) => void) | undefined} setter
|
|
2421
|
+
* @param {any} value
|
|
2422
|
+
*/
|
|
2423
|
+
var push = (setter, value) => {
|
|
2424
|
+
try {
|
|
2425
|
+
setter?.(value);
|
|
2426
|
+
} catch (_error) {
|
|
2427
|
+
/* 渲染层挂了不该让 RPC 的 rejection 逃逸 */
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
/**
|
|
2431
|
+
* @param {string} method
|
|
2432
|
+
* @param {((value: any) => void) | undefined} setter
|
|
2433
|
+
* @param {(value: any) => any} pick
|
|
2434
|
+
*/
|
|
2435
|
+
var fetchInto = (method, setter, pick) =>
|
|
2436
|
+
Promise.resolve()
|
|
2437
|
+
.then(() => call(method))
|
|
2438
|
+
.then(
|
|
2439
|
+
(/** @type {any} */ value) => {
|
|
2440
|
+
push(setter, pick(value));
|
|
2441
|
+
return value;
|
|
2442
|
+
},
|
|
2443
|
+
(/** @type {any} */ reason) => {
|
|
2444
|
+
push(sinks.setMessage, errorText(reason));
|
|
2445
|
+
return null;
|
|
2446
|
+
},
|
|
2447
|
+
);
|
|
2448
|
+
|
|
2449
|
+
var load = () => {
|
|
2450
|
+
// 先显示上次的体检结论(或 null = 尚未体检),不触发任何扫描。
|
|
2451
|
+
push(sinks.setHealth, shared.health);
|
|
2452
|
+
return Promise.all([
|
|
2453
|
+
fetchInto("list", sinks.setInfo, (/** @type {any} */ value) => value),
|
|
2454
|
+
fetchInto(
|
|
2455
|
+
"receipts",
|
|
2456
|
+
sinks.setReceipts,
|
|
2457
|
+
(/** @type {any} */ value) => value?.entries || [],
|
|
2458
|
+
),
|
|
2459
|
+
fetchInto("audit", sinks.setAudit, (/** @type {any} */ value) => value?.entries || []),
|
|
2460
|
+
]);
|
|
2461
|
+
};
|
|
2462
|
+
|
|
2463
|
+
var scanHealth = () =>
|
|
2464
|
+
Promise.resolve()
|
|
2465
|
+
.then(() => call("healthScan"))
|
|
2466
|
+
.then(
|
|
2467
|
+
(/** @type {any} */ value) => {
|
|
2468
|
+
shared.health = value;
|
|
2469
|
+
shared.healthAt = Date.now();
|
|
2470
|
+
push(sinks.setHealth, value);
|
|
2471
|
+
push(sinks.setHealthError, null);
|
|
2472
|
+
return value;
|
|
2473
|
+
},
|
|
2474
|
+
(/** @type {any} */ reason) => {
|
|
2475
|
+
// 扫描失败只影响体检那一行:把原因放在那里,别抛进 React。
|
|
2476
|
+
shared.health = null;
|
|
2477
|
+
shared.healthAt = 0;
|
|
2478
|
+
push(sinks.setHealth, null);
|
|
2479
|
+
push(sinks.setHealthError, errorText(reason));
|
|
2480
|
+
return null;
|
|
2481
|
+
},
|
|
2482
|
+
);
|
|
2483
|
+
|
|
2484
|
+
var invalidate = () => {
|
|
2485
|
+
shared.health = null;
|
|
2486
|
+
shared.healthAt = 0;
|
|
2487
|
+
push(sinks.setHealth, null);
|
|
2488
|
+
};
|
|
2489
|
+
|
|
2490
|
+
return { load: load, scanHealth: scanHealth, invalidate: invalidate, cache: shared };
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* 分批执行批量动作。宿主单次上限是防御性硬上限,界面按 chunkSize 切块;
|
|
2495
|
+
* 每块之间让出一帧:进度可见、可中途停止、部分失败不中断其余批次。
|
|
2496
|
+
* 抽成纯函数是为了在单测里用假 call 直接验证「>50 条不会被整单拒绝」与
|
|
2497
|
+
* 「部分失败被汇总、成功的也不再算失败」。
|
|
2498
|
+
* @param {{ ids: string[], kind: "purge" | "restore", call: (method: string, request?: any) => Promise<any>,
|
|
2499
|
+
* chunkSize?: number, onProgress?: (state: any) => void, shouldStop?: () => boolean,
|
|
2500
|
+
* onRestored?: (sessionId: string, options?: { open?: boolean }) => void }} options
|
|
2501
|
+
* @returns {Promise<{ kind: string, total: number, done: number, ok: number, failures: any[],
|
|
2502
|
+
* partials: number, stopped: boolean }>}
|
|
2503
|
+
*/
|
|
2504
|
+
async function runBatch(options) {
|
|
2505
|
+
var ids = options.ids || [];
|
|
2506
|
+
var kind = options.kind === "restore" ? "restore" : "purge";
|
|
2507
|
+
var chunkSize = options.chunkSize || BATCH_CHUNK;
|
|
2508
|
+
var groups = chunk(ids, chunkSize);
|
|
2509
|
+
/** @type {any[]} */
|
|
2510
|
+
var failures = [];
|
|
2511
|
+
var partials = 0;
|
|
2512
|
+
var done = 0;
|
|
2513
|
+
var stopped = false;
|
|
2514
|
+
const emit = (/** @type {boolean} */ running) => {
|
|
2515
|
+
try {
|
|
2516
|
+
options.onProgress?.({
|
|
2517
|
+
kind: kind,
|
|
2518
|
+
running: running,
|
|
2519
|
+
done: done,
|
|
2520
|
+
total: ids.length,
|
|
2521
|
+
failures: failures.slice(),
|
|
2522
|
+
partials: partials,
|
|
2523
|
+
});
|
|
2524
|
+
} catch (_error) {}
|
|
2525
|
+
};
|
|
2526
|
+
for (let index = 0; index < groups.length; index += 1) {
|
|
2527
|
+
if (options.shouldStop?.()) {
|
|
2528
|
+
stopped = true;
|
|
2529
|
+
break;
|
|
2530
|
+
}
|
|
2531
|
+
const group = groups[index];
|
|
2532
|
+
try {
|
|
2533
|
+
const result = await options.call(kind === "purge" ? "purgeMany" : "restoreMany", {
|
|
2534
|
+
entryIds: group,
|
|
2535
|
+
});
|
|
2536
|
+
const results = result?.results || [];
|
|
2537
|
+
for (let itemIndex = 0; itemIndex < results.length; itemIndex += 1) {
|
|
2538
|
+
const item = results[itemIndex];
|
|
2539
|
+
if (!item.ok) failures.push(item);
|
|
2540
|
+
else {
|
|
2541
|
+
// 条目回来了但引用没全回来:单独计数,批量行里要说出来(AUD-SD-02)。
|
|
2542
|
+
if (item.partial === true) partials += 1;
|
|
2543
|
+
// N1:批量恢复不逐条导航——宿主 replaceMain 会互相 supersede,
|
|
2544
|
+
// 最终停在任意一条还会闪;批量结束后统一交给 onBatchRestoreDone。
|
|
2545
|
+
if (kind === "restore" && item.sessionId) {
|
|
2546
|
+
options.onRestored?.(item.sessionId, { open: false });
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
} catch (reason) {
|
|
2551
|
+
for (let groupIndex = 0; groupIndex < group.length; groupIndex += 1) {
|
|
2552
|
+
failures.push({ entryId: group[groupIndex], ok: false, error: errorText(reason) });
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
done += group.length;
|
|
2556
|
+
emit(true);
|
|
2557
|
+
// 让出一帧:让「处理中 n/total」和「停止」真的可见、可点。
|
|
2558
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
2559
|
+
}
|
|
2560
|
+
emit(false);
|
|
2561
|
+
return {
|
|
2562
|
+
kind: kind,
|
|
2563
|
+
total: ids.length,
|
|
2564
|
+
done: done,
|
|
2565
|
+
ok: done - failures.length,
|
|
2566
|
+
failures: failures,
|
|
2567
|
+
partials: partials,
|
|
2568
|
+
stopped: stopped,
|
|
2569
|
+
};
|
|
2570
|
+
}
|
|
2571
|
+
|
|
1420
2572
|
/** 一个浮层里渲染确认框 + 面板 + toast,因为 shell.overlay 是单实例 slot。 */
|
|
1421
2573
|
function SessionDeleteOverlay(/** @type {any} */ props) {
|
|
1422
2574
|
return h(
|
|
@@ -1426,8 +2578,10 @@ window.__ModuleLoader__.load({
|
|
|
1426
2578
|
DeleteConfirm,
|
|
1427
2579
|
Object.assign({}, props, {
|
|
1428
2580
|
requestStore: props.requestStore,
|
|
2581
|
+
prefsStore: props.prefsStore,
|
|
1429
2582
|
call: props.call,
|
|
1430
2583
|
onTrashed: props.onTrashed,
|
|
2584
|
+
onTrashedMany: props.onTrashedMany,
|
|
1431
2585
|
}),
|
|
1432
2586
|
),
|
|
1433
2587
|
h(
|
|
@@ -1437,6 +2591,8 @@ window.__ModuleLoader__.load({
|
|
|
1437
2591
|
call: props.call,
|
|
1438
2592
|
onPurged: props.onPurged,
|
|
1439
2593
|
onRestored: props.onRestored,
|
|
2594
|
+
onRestoreComplete: props.onRestoreComplete,
|
|
2595
|
+
onBatchRestoreDone: props.onBatchRestoreDone,
|
|
1440
2596
|
tickStore: props.tickStore,
|
|
1441
2597
|
bump: props.bump,
|
|
1442
2598
|
}),
|
|
@@ -1445,25 +2601,83 @@ window.__ModuleLoader__.load({
|
|
|
1445
2601
|
);
|
|
1446
2602
|
}
|
|
1447
2603
|
|
|
2604
|
+
/** 单批条目数:既让「处理中 n/total」有节奏,也避免一次 RPC 太久没有反馈。 */
|
|
2605
|
+
var BATCH_CHUNK = 20;
|
|
2606
|
+
|
|
2607
|
+
/**
|
|
2608
|
+
* 等 contextMenus 服务就绪的宽限期(毫秒)。Cordis 的 inject 只有「必须」语义,
|
|
2609
|
+
* 没有可选依赖:老宿主永远不会提供这个服务,等下去就等于「会话菜单里没有删除项」。
|
|
2610
|
+
* 所以超时就认为没有该服务,退回到旧的 slot 渲染。
|
|
2611
|
+
*/
|
|
2612
|
+
var MENU_FALLBACK = { ms: 1200 };
|
|
2613
|
+
|
|
2614
|
+
/** 菜单图标键:注册到宿主的 contextMenu.icon keyed slot 上。 */
|
|
2615
|
+
var TRASH_ICON = "session-delete.trash";
|
|
2616
|
+
|
|
2617
|
+
/** 快捷键命令 id:菜单行的 commandId 必须与它一致,键位提示才会显示。 */
|
|
2618
|
+
var COMMAND_DELETE = "session.delete";
|
|
2619
|
+
var COMMAND_DELETE_WORKSPACE = "session.deleteWorkspace";
|
|
2620
|
+
|
|
1448
2621
|
exports.inject = ["slots", "locale", "connection"];
|
|
1449
2622
|
exports.apply = function apply(/** @type {any} */ ctx) {
|
|
1450
2623
|
ctx.effect(() => ctx.locale.register(NS, { zh: zh, en: en }), "session-delete: dictionaries");
|
|
1451
2624
|
|
|
2625
|
+
/** @type {(key: string, values?: any) => string} */
|
|
2626
|
+
var translate;
|
|
2627
|
+
var fallbackTranslate = (/** @type {string} */ key) =>
|
|
2628
|
+
/** @type {Record<string, string>} */ (zh)[key] || key;
|
|
2629
|
+
try {
|
|
2630
|
+
translate =
|
|
2631
|
+
ctx.locale && typeof ctx.locale.bind === "function"
|
|
2632
|
+
? ctx.locale.bind(NS)
|
|
2633
|
+
: fallbackTranslate;
|
|
2634
|
+
} catch (_error) {
|
|
2635
|
+
translate = fallbackTranslate;
|
|
2636
|
+
}
|
|
2637
|
+
|
|
1452
2638
|
// 用真实的 :hover / :focus-visible 伪类,避免依赖 React 合成事件与内联样式。
|
|
2639
|
+
// 原则:控件外观只调宿主 token;行高与间距对齐设置页(16px 竖向留白、.5px 分隔线)。
|
|
1453
2640
|
ctx.effect(() => {
|
|
1454
2641
|
const style = document.createElement("style");
|
|
1455
2642
|
// 标注归属:便于在 DevTools 里认出这段样式、也方便测试断言插件确实加载了。
|
|
1456
2643
|
style.setAttribute("data-plugin", "@kangyishuai/dsh-session-delete");
|
|
1457
2644
|
style.textContent = [
|
|
1458
|
-
".dsh-sdel-btn{background:transparent;color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));transition:background-color 150ms ease,border-color 150ms ease,transform 80ms ease,color 150ms ease;}",
|
|
1459
|
-
".dsh-sdel-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));}",
|
|
1460
|
-
".dsh-sdel-btn:active{transform:scale(.98);}",
|
|
2645
|
+
".dsh-sdel-btn{background:transparent;color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));transition:background-color 150ms ease,border-color 150ms ease,transform 80ms ease,color 150ms ease;white-space:nowrap;}",
|
|
2646
|
+
".dsh-sdel-btn:hover:enabled{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));}",
|
|
2647
|
+
".dsh-sdel-btn:active:enabled{transform:scale(.98);}",
|
|
1461
2648
|
".dsh-sdel-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:1px;}",
|
|
1462
2649
|
".dsh-sdel-btn--danger{color:var(--dsw-alias-state-error-primary,#d9534f);}",
|
|
1463
|
-
".dsh-sdel-btn--danger:hover{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.16));}",
|
|
2650
|
+
".dsh-sdel-btn--danger:hover:enabled{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.16));}",
|
|
2651
|
+
".dsh-sdel-btn--quiet{border-color:transparent;}",
|
|
2652
|
+
".dsh-sdel-btn--tight{padding:2px 8px;border-radius:6px;font-size:12px;}",
|
|
1464
2653
|
".dsh-sdel-footer{background:transparent;color:var(--dsw-alias-label-secondary,GrayText);border:1px solid transparent;border-radius:8px;transition:background-color 150ms ease,color 150ms ease;}",
|
|
1465
2654
|
".dsh-sdel-footer:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.16));color:var(--dsw-alias-label-primary,inherit);}",
|
|
1466
2655
|
".dsh-sdel-footer:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:1px;}",
|
|
2656
|
+
".dsh-sdel-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;}",
|
|
2657
|
+
".dsh-sdel-panel{display:flex;flex-direction:column;gap:8px;min-height:0;}",
|
|
2658
|
+
".dsh-sdel-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}",
|
|
2659
|
+
".dsh-sdel-list{max-height:min(56vh,520px);overflow-y:auto;border-top:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));}",
|
|
2660
|
+
".dsh-sdel-row{display:flex;align-items:center;gap:10px;padding:7px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));min-width:0;}",
|
|
2661
|
+
".dsh-sdel-row:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.08));}",
|
|
2662
|
+
".dsh-sdel-row-text{display:flex;flex-direction:column;gap:1px;flex:1 1 auto;min-width:0;}",
|
|
2663
|
+
".dsh-sdel-row-title{font-size:13px;line-height:18px;min-width:0;}",
|
|
2664
|
+
".dsh-sdel-row-meta{color:var(--dsw-alias-label-tertiary,GrayText);font-size:11px;line-height:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}",
|
|
2665
|
+
".dsh-sdel-row-actions{display:flex;gap:6px;flex:none;opacity:0;transition:opacity 120ms ease;}",
|
|
2666
|
+
".dsh-sdel-row:hover .dsh-sdel-row-actions,.dsh-sdel-row:focus-within .dsh-sdel-row-actions,.dsh-sdel-row-actions--open{opacity:1;}",
|
|
2667
|
+
".dsh-sdel-batch{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--dsw-alias-label-secondary,GrayText);}",
|
|
2668
|
+
".dsh-sdel-confirm{display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px;background:var(--dsw-alias-interactive-bg-hover-danger,rgba(217,83,79,.12));font-size:12px;color:var(--dsw-alias-state-error-primary,#d9534f);}",
|
|
2669
|
+
".dsh-sdel-disclosure{display:flex;align-items:center;gap:6px;background:transparent;border:none;padding:2px 0;cursor:pointer;color:var(--dsw-alias-label-secondary,GrayText);font-size:12px;font-family:inherit;}",
|
|
2670
|
+
".dsh-sdel-disclosure:hover{color:var(--dsw-alias-label-primary,inherit);}",
|
|
2671
|
+
".dsh-sdel-disclosure:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f7cff);outline-offset:2px;border-radius:4px;}",
|
|
2672
|
+
".dsh-sdel-disclosure-meta{margin-left:auto;color:var(--dsw-alias-label-tertiary,GrayText);}",
|
|
2673
|
+
".dsh-sdel-settings{display:flex;flex-direction:column;width:100%;}",
|
|
2674
|
+
".dsh-sdel-group{color:var(--dsw-alias-label-secondary,GrayText);font-size:12px;font-weight:600;padding:20px 0 4px;}",
|
|
2675
|
+
".dsh-sdel-setting-row{display:flex;align-items:center;justify-content:space-between;gap:24px;padding:16px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,rgba(128,128,128,.35));}",
|
|
2676
|
+
".dsh-sdel-setting-row--stack{display:block;}",
|
|
2677
|
+
".dsh-sdel-setting-text{min-width:0;flex:1;}",
|
|
2678
|
+
".dsh-sdel-setting-title{color:var(--dsw-alias-label-primary,inherit);font-size:14px;line-height:22px;}",
|
|
2679
|
+
".dsh-sdel-setting-desc{color:var(--dsw-alias-label-tertiary,GrayText);font-size:12px;line-height:18px;margin-top:4px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}",
|
|
2680
|
+
".dsh-sdel-setting-action{display:flex;align-items:center;gap:8px;flex:none;}",
|
|
1467
2681
|
].join("\n");
|
|
1468
2682
|
document.head.appendChild(style);
|
|
1469
2683
|
return () => style.remove();
|
|
@@ -1473,12 +2687,13 @@ window.__ModuleLoader__.load({
|
|
|
1473
2687
|
var panelStore = createStore(false);
|
|
1474
2688
|
var toastStore = createStore(null);
|
|
1475
2689
|
var tickStore = createStore(0);
|
|
2690
|
+
var prefsStore = createStore(null);
|
|
1476
2691
|
|
|
1477
2692
|
/**
|
|
1478
2693
|
* 调宿主 sessionDelete 的 Remote 方法。走 /api 的普通 RPC 通道:
|
|
1479
2694
|
* 无构建插件没有 typert 生成的客户端产物,不能用 ctx.reflect.get。
|
|
1480
2695
|
* @param {string} method
|
|
1481
|
-
* @param {any} request
|
|
2696
|
+
* @param {any} [request]
|
|
1482
2697
|
* @returns {Promise<any>}
|
|
1483
2698
|
*/
|
|
1484
2699
|
function call(method, request) {
|
|
@@ -1502,6 +2717,18 @@ window.__ModuleLoader__.load({
|
|
|
1502
2717
|
);
|
|
1503
2718
|
}
|
|
1504
2719
|
|
|
2720
|
+
/** 偏好只加载一次:确认框与设置页共享同一份快照。 */
|
|
2721
|
+
var loadPrefs = () => {
|
|
2722
|
+
call("getPrefs")
|
|
2723
|
+
.then((/** @type {any} */ value) => {
|
|
2724
|
+
prefsStore.set(value || { cascadeChildren: false });
|
|
2725
|
+
})
|
|
2726
|
+
.catch(() => {
|
|
2727
|
+
prefsStore.set({ cascadeChildren: false });
|
|
2728
|
+
});
|
|
2729
|
+
};
|
|
2730
|
+
loadPrefs();
|
|
2731
|
+
|
|
1505
2732
|
// 宿主列表 = persistence ∪ live:刷新会把宿主内存里还没释放的会话折回来。
|
|
1506
2733
|
// 所以删掉的 id 要记住,并在每次 refresh 后重放移除事件(参考实现同款做法)。
|
|
1507
2734
|
const retired = new Set();
|
|
@@ -1529,6 +2756,105 @@ window.__ModuleLoader__.load({
|
|
|
1529
2756
|
}
|
|
1530
2757
|
});
|
|
1531
2758
|
};
|
|
2759
|
+
|
|
2760
|
+
/**
|
|
2761
|
+
* 宿主的界面导航服务(Client 半的 `uiWorkspace`)。
|
|
2762
|
+
* 不是公开契约,所以按「有就用、没有就降级」处理,绝不因为缺它抛错。
|
|
2763
|
+
*/
|
|
2764
|
+
const uiWorkspace = () => {
|
|
2765
|
+
try {
|
|
2766
|
+
return ctx.get ? ctx.get("uiWorkspace") : undefined;
|
|
2767
|
+
} catch (_error) {
|
|
2768
|
+
return undefined;
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
/** 当前列表里第一个可切换的会话 id(用于删除当前会话后自动跳走)。 */
|
|
2773
|
+
const availableSessionIds = () => {
|
|
2774
|
+
const sessions = hostSessions();
|
|
2775
|
+
const list = sessions?.list?.getSnapshot?.();
|
|
2776
|
+
if (!list) return [];
|
|
2777
|
+
const ids = Array.isArray(list.ids) ? list.ids : Object.keys(list.byId || {});
|
|
2778
|
+
/** @type {string[]} */
|
|
2779
|
+
const out = [];
|
|
2780
|
+
for (let index = 0; index < ids.length; index += 1) {
|
|
2781
|
+
const id = String(ids[index]);
|
|
2782
|
+
if (retired.has(id)) continue;
|
|
2783
|
+
out.push(id);
|
|
2784
|
+
}
|
|
2785
|
+
return out;
|
|
2786
|
+
};
|
|
2787
|
+
|
|
2788
|
+
/**
|
|
2789
|
+
* 重新把视图绑到某个会话上(USIM-U2-05 / USIM-U3-02 ②)。
|
|
2790
|
+
*
|
|
2791
|
+
* 删除时宿主客户端会 dispose 这个会话的作用域;恢复/删除之后光刷新列表**不会**
|
|
2792
|
+
* 重建主视图的绑定,页面就停在「会话不可用」上(要切走再切回才好)。
|
|
2793
|
+
* `uiWorkspace.openSession` 是「选中会话并显示它的对话」这一条正式导航动作,
|
|
2794
|
+
* 会重新 retain 一份引用,正好补上这一步。
|
|
2795
|
+
* @param {string} sessionId
|
|
2796
|
+
* @returns {boolean}
|
|
2797
|
+
*/
|
|
2798
|
+
const reopenSession = (sessionId) => {
|
|
2799
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) return false;
|
|
2800
|
+
const workspace = uiWorkspace();
|
|
2801
|
+
if (workspace && typeof workspace.openSession === "function") {
|
|
2802
|
+
try {
|
|
2803
|
+
workspace.openSession(sessionId);
|
|
2804
|
+
return true;
|
|
2805
|
+
} catch (error) {
|
|
2806
|
+
ctx.logger?.warn?.(
|
|
2807
|
+
`session-delete: openSession failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
// 退化路径:至少把投影缓存刷一遍,标题与消息不至于停在旧值。
|
|
2812
|
+
try {
|
|
2813
|
+
const sessions = hostSessions();
|
|
2814
|
+
void sessions?.refreshProjections?.(sessionId);
|
|
2815
|
+
} catch (_error) {
|
|
2816
|
+
/* 老宿主没有该通道时忽略 */
|
|
2817
|
+
}
|
|
2818
|
+
return false;
|
|
2819
|
+
};
|
|
2820
|
+
|
|
2821
|
+
/**
|
|
2822
|
+
* 删除的是当前正在看的会话时,别把人留在「已删除的会话」页上(USIM-U2-05):
|
|
2823
|
+
* 切到下一个可用会话,没有就回新会话页。
|
|
2824
|
+
* @param {string | null | undefined} deletedId
|
|
2825
|
+
* @param {string | null} workspaceId
|
|
2826
|
+
*/
|
|
2827
|
+
const leaveDeletedSessionView = (deletedId, workspaceId) => {
|
|
2828
|
+
if (typeof deletedId !== "string" || deletedId.length === 0) return false;
|
|
2829
|
+
const decision = afterTrashNavigation({
|
|
2830
|
+
deletedId: deletedId,
|
|
2831
|
+
currentId: deletedId,
|
|
2832
|
+
candidates: availableSessionIds(),
|
|
2833
|
+
});
|
|
2834
|
+
if (!decision.navigate) return false;
|
|
2835
|
+
const workspace = uiWorkspace();
|
|
2836
|
+
if (decision.target === "session" && decision.id) {
|
|
2837
|
+
if (reopenSession(decision.id)) return true;
|
|
2838
|
+
}
|
|
2839
|
+
if (workspace && typeof workspace.startSession === "function") {
|
|
2840
|
+
try {
|
|
2841
|
+
// 带上原工作区:否则宿主可能落到「选择一个工作区开始」的空态。
|
|
2842
|
+
if (typeof workspaceId === "string" && workspaceId.length > 0) {
|
|
2843
|
+
workspace.startSession(workspaceId);
|
|
2844
|
+
} else {
|
|
2845
|
+
workspace.startSession();
|
|
2846
|
+
}
|
|
2847
|
+
return true;
|
|
2848
|
+
} catch (error) {
|
|
2849
|
+
ctx.logger?.warn?.(
|
|
2850
|
+
`session-delete: startSession failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
2851
|
+
);
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
// 宿主没有导航服务:至少让列表重算,README 里写明需要手动切换。
|
|
2855
|
+
void refreshRows(undefined);
|
|
2856
|
+
return false;
|
|
2857
|
+
};
|
|
1532
2858
|
// 快捷键只做「打开回收站」这种非破坏性动作;删除始终需要菜单 + 确认框。
|
|
1533
2859
|
window.addEventListener("keydown", (/** @type {any} */ event) => {
|
|
1534
2860
|
if (!(event.metaKey || event.ctrlKey) || !event.altKey) return;
|
|
@@ -1541,12 +2867,89 @@ window.__ModuleLoader__.load({
|
|
|
1541
2867
|
});
|
|
1542
2868
|
|
|
1543
2869
|
const onTrashed = (/** @type {any} */ result) => {
|
|
1544
|
-
|
|
1545
|
-
|
|
2870
|
+
const deletedId = typeof result?.sessionId === "string" ? result.sessionId : null;
|
|
2871
|
+
// 优先用打开确认框时记下的判断(宿主删完就把行摘了),老路径再退回实时判断。
|
|
2872
|
+
const wasCurrent =
|
|
2873
|
+
result?.wasCurrent === true || (Boolean(deletedId) && currentSession()?.id === deletedId);
|
|
2874
|
+
toastStore.set({
|
|
2875
|
+
entryId: result?.entryId ?? null,
|
|
2876
|
+
title: result?.title || null,
|
|
2877
|
+
// 删除当前会话时把「还能恢复」说在明处(USIM-U2-05)。
|
|
2878
|
+
text: wasCurrent ? translate("toast.trashedCurrent") : undefined,
|
|
2879
|
+
});
|
|
2880
|
+
void refreshRows(deletedId ?? undefined).then(() => {
|
|
2881
|
+
tickStore.set(tickStore.getSnapshot() + 1);
|
|
2882
|
+
if (wasCurrent) leaveDeletedSessionView(deletedId, result?.workspaceId ?? null);
|
|
2883
|
+
});
|
|
2884
|
+
};
|
|
2885
|
+
/**
|
|
2886
|
+
* 工作区批量的收尾:逐条结果汇总成一句 toast,并把删掉的 id 记进 retired,
|
|
2887
|
+
* 让下一次 refreshRows 重放移除事件(否则刷新会把 live 会话折回来)。
|
|
2888
|
+
* @param {any} result
|
|
2889
|
+
*/
|
|
2890
|
+
const onTrashedMany = (result) => {
|
|
2891
|
+
var ok = 0;
|
|
2892
|
+
var total = 0;
|
|
2893
|
+
const current = currentSession();
|
|
2894
|
+
/** @type {string | null} */
|
|
2895
|
+
var currentDeleted = null;
|
|
2896
|
+
if (result && Array.isArray(result.results)) {
|
|
2897
|
+
total = result.results.length;
|
|
2898
|
+
for (let index = 0; index < total; index += 1) {
|
|
2899
|
+
const item = result.results[index];
|
|
2900
|
+
if (!item.ok) continue;
|
|
2901
|
+
ok += 1;
|
|
2902
|
+
if (item.sessionId) {
|
|
2903
|
+
retired.add(String(item.sessionId));
|
|
2904
|
+
if (current?.id === item.sessionId) currentDeleted = String(item.sessionId);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
1546
2907
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
2908
|
+
toastStore.set({ text: translate("toast.workspace.done", { ok: ok, total: total }) });
|
|
2909
|
+
void refreshRows(undefined).then(() => {
|
|
2910
|
+
tickStore.set(tickStore.getSnapshot() + 1);
|
|
2911
|
+
if (currentDeleted) leaveDeletedSessionView(currentDeleted, null);
|
|
2912
|
+
});
|
|
1549
2913
|
};
|
|
2914
|
+
|
|
2915
|
+
/** 当前会话(主视图持有的那一条)。快捷键的语义就是「这个会话」。 */
|
|
2916
|
+
const currentSession = () => {
|
|
2917
|
+
try {
|
|
2918
|
+
const sessions = ctx.get ? ctx.get("sessions") : undefined;
|
|
2919
|
+
const list = sessions?.list?.getSnapshot?.();
|
|
2920
|
+
if (!list?.byId) return undefined;
|
|
2921
|
+
const ids = Array.isArray(list.ids) ? list.ids : Object.keys(list.byId);
|
|
2922
|
+
for (let index = 0; index < ids.length; index += 1) {
|
|
2923
|
+
const row = list.byId[ids[index]];
|
|
2924
|
+
if ((row?.retainedBy?.mainView ?? 0) > 0) return row;
|
|
2925
|
+
}
|
|
2926
|
+
} catch (_error) {
|
|
2927
|
+
return undefined;
|
|
2928
|
+
}
|
|
2929
|
+
return undefined;
|
|
2930
|
+
};
|
|
2931
|
+
|
|
2932
|
+
/** 当前会话所属的工作区(工作区记账里包含它,或路径与它的 cwd 相同)。 */
|
|
2933
|
+
const currentWorkspace = () => {
|
|
2934
|
+
var row = currentSession();
|
|
2935
|
+
if (!row) return undefined;
|
|
2936
|
+
try {
|
|
2937
|
+
const workspaces = ctx.get ? ctx.get("workspaces") : undefined;
|
|
2938
|
+
const snapshot = workspaces?.list?.getSnapshot?.();
|
|
2939
|
+
const items = snapshot?.items || [];
|
|
2940
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
2941
|
+
const item = items[index];
|
|
2942
|
+
if (Array.isArray(item.sessionIds) && item.sessionIds.includes(row.id)) return item;
|
|
2943
|
+
}
|
|
2944
|
+
for (let cursor = 0; cursor < items.length; cursor += 1) {
|
|
2945
|
+
if (typeof row.cwd === "string" && items[cursor].path === row.cwd) return items[cursor];
|
|
2946
|
+
}
|
|
2947
|
+
} catch (_error) {
|
|
2948
|
+
return undefined;
|
|
2949
|
+
}
|
|
2950
|
+
return undefined;
|
|
2951
|
+
};
|
|
2952
|
+
|
|
1550
2953
|
// 外部变更(agent 工具、另一个窗口、CLI)不会通知本页面,
|
|
1551
2954
|
// 定期拉一次会话列表;页面重新可见时也立刻拉一次。
|
|
1552
2955
|
ctx.effect(() => {
|
|
@@ -1568,31 +2971,261 @@ window.__ModuleLoader__.load({
|
|
|
1568
2971
|
const onPurged = (/** @type {any} */ sessionId) => {
|
|
1569
2972
|
void refreshRows(sessionId || undefined);
|
|
1570
2973
|
};
|
|
1571
|
-
|
|
2974
|
+
/**
|
|
2975
|
+
* 恢复后的列表收尾。
|
|
2976
|
+
* @param {any} sessionId
|
|
2977
|
+
* @param {{ open?: boolean }} [options] open=false 用于批量恢复:只刷新,不逐条导航(N1)
|
|
2978
|
+
*/
|
|
2979
|
+
const onRestored = (sessionId, options = {}) => {
|
|
1572
2980
|
if (sessionId) retired.delete(sessionId);
|
|
2981
|
+
// 恢复是「把会话还给我」:列表刷新之外还必须重建主视图绑定,
|
|
2982
|
+
// 否则当前视图停在「会话不可用」上(USIM-U3-02 ②)。
|
|
2983
|
+
void refreshRows(undefined).then(() => {
|
|
2984
|
+
if (options.open === false) return;
|
|
2985
|
+
reopenSession(typeof sessionId === "string" ? sessionId : "");
|
|
2986
|
+
});
|
|
2987
|
+
};
|
|
2988
|
+
|
|
2989
|
+
/** 恢复成功的收尾:关框 + 说一句 + 重新打开会话(USIM-U2-17)。 */
|
|
2990
|
+
const onRestoreComplete = (/** @type {any} */ result) => {
|
|
2991
|
+
panelStore.set(false);
|
|
2992
|
+
toastStore.set({ text: translate("toast.restored") });
|
|
2993
|
+
onRestored(result?.sessionId, { open: true });
|
|
2994
|
+
};
|
|
2995
|
+
|
|
2996
|
+
/** 批量恢复全绿的收尾:关框 + 汇总 toast,只刷新一次、不逐条导航(N1)。 */
|
|
2997
|
+
const onBatchRestoreDone = (/** @type {any} */ summary) => {
|
|
2998
|
+
panelStore.set(false);
|
|
2999
|
+
var ok = summary && typeof summary.ok === "number" ? summary.ok : 0;
|
|
3000
|
+
toastStore.set({ text: translate("toast.restoredMany", { n: ok }) });
|
|
1573
3001
|
void refreshRows(undefined);
|
|
3002
|
+
tickStore.set(tickStore.getSnapshot() + 1);
|
|
1574
3003
|
};
|
|
1575
3004
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
3005
|
+
/**
|
|
3006
|
+
* 菜单:优先走官方的 contextMenus 贡献。
|
|
3007
|
+
* 好处有三点:能参与官方排序(不再是「兼容位置」的附加行)、能显示快捷键、
|
|
3008
|
+
* 工作区「…」菜单也有正式入口。拿不到服务(老宿主)时退回旧 slot,功能不减。
|
|
3009
|
+
*/
|
|
3010
|
+
const openSessionConfirm = (/** @type {any} */ sessionId, /** @type {any} */ title) => {
|
|
3011
|
+
// 打开确认框这一刻的「当前会话 / 当前工作区」必须记下来:
|
|
3012
|
+
// 删除成功后宿主会把这一行从列表里摘掉,事后再问「删的是当前会话吗」就问不到了。
|
|
3013
|
+
requestStore.set({
|
|
3014
|
+
sessionId: sessionId,
|
|
3015
|
+
title: title || null,
|
|
3016
|
+
currentId: currentSession()?.id ?? null,
|
|
3017
|
+
workspaceId: currentWorkspace()?.id ?? null,
|
|
3018
|
+
});
|
|
3019
|
+
};
|
|
3020
|
+
const openWorkspaceConfirm = (/** @type {any} */ workspaceId, /** @type {any} */ title) => {
|
|
3021
|
+
requestStore.set({ workspaceId: String(workspaceId), title: title || null });
|
|
3022
|
+
};
|
|
3023
|
+
|
|
3024
|
+
/** @param {any} contextMenus */
|
|
3025
|
+
const installMenuContributions = (contextMenus) => {
|
|
3026
|
+
if (!contextMenus || typeof contextMenus.register !== "function") return false;
|
|
3027
|
+
try {
|
|
3028
|
+
ctx.effect(
|
|
3029
|
+
() =>
|
|
3030
|
+
contextMenus.register({
|
|
3031
|
+
id: COMMAND_DELETE,
|
|
3032
|
+
target: "session",
|
|
3033
|
+
order: 560,
|
|
3034
|
+
resolve: (/** @type {any} */ target) => [
|
|
3035
|
+
{
|
|
3036
|
+
id: "delete",
|
|
3037
|
+
label: translate("menu.delete"),
|
|
3038
|
+
danger: true,
|
|
3039
|
+
separatorBefore: true,
|
|
3040
|
+
...(typeof IconTrash === "function" ? { icon: { key: TRASH_ICON } } : {}),
|
|
3041
|
+
commandId: COMMAND_DELETE,
|
|
3042
|
+
run: () => openSessionConfirm(target.sessionId, target.displayTitle),
|
|
1588
3043
|
},
|
|
1589
|
-
|
|
1590
|
-
},
|
|
1591
|
-
|
|
3044
|
+
],
|
|
3045
|
+
}),
|
|
3046
|
+
"session-delete: session menu action",
|
|
3047
|
+
);
|
|
3048
|
+
ctx.effect(
|
|
3049
|
+
() =>
|
|
3050
|
+
contextMenus.register({
|
|
3051
|
+
id: COMMAND_DELETE_WORKSPACE,
|
|
3052
|
+
target: "workspace",
|
|
3053
|
+
order: 250,
|
|
3054
|
+
resolve: (/** @type {any} */ target) => [
|
|
3055
|
+
{
|
|
3056
|
+
id: "delete-workspace-sessions",
|
|
3057
|
+
label: translate("menu.workspaceTrash"),
|
|
3058
|
+
danger: true,
|
|
3059
|
+
separatorBefore: true,
|
|
3060
|
+
...(typeof IconTrash === "function" ? { icon: { key: TRASH_ICON } } : {}),
|
|
3061
|
+
commandId: COMMAND_DELETE_WORKSPACE,
|
|
3062
|
+
run: () => openWorkspaceConfirm(target.workspaceId, target.displayTitle),
|
|
3063
|
+
},
|
|
3064
|
+
],
|
|
3065
|
+
}),
|
|
3066
|
+
"session-delete: workspace menu action",
|
|
3067
|
+
);
|
|
3068
|
+
if (typeof IconTrash === "function") {
|
|
3069
|
+
try {
|
|
3070
|
+
ctx.effect(
|
|
3071
|
+
() =>
|
|
3072
|
+
ctx.slots.inject("contextMenu.icon", () =>
|
|
3073
|
+
ctx.slots.register(
|
|
3074
|
+
{ name: "contextMenu.icon", key: TRASH_ICON },
|
|
3075
|
+
function TrashMenuIcon() {
|
|
3076
|
+
return h(IconTrash, { size: 14 });
|
|
3077
|
+
},
|
|
3078
|
+
),
|
|
3079
|
+
),
|
|
3080
|
+
"session-delete: menu icon",
|
|
3081
|
+
);
|
|
3082
|
+
} catch (_error) {
|
|
3083
|
+
/* 图标 slot 不存在时菜单仍然可用(宿主的 icon key 匹配不到就不画) */
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
return true;
|
|
3087
|
+
} catch (error) {
|
|
3088
|
+
ctx.logger?.warn?.(
|
|
3089
|
+
`session-delete: cannot register menu contributions: ${errorText(error)}`,
|
|
3090
|
+
);
|
|
3091
|
+
return false;
|
|
3092
|
+
}
|
|
3093
|
+
};
|
|
3094
|
+
|
|
3095
|
+
/** @returns {any} ctx.effect 的释放函数(contextMenus 迟到时用它撤掉旧 slot,避免两行)。 */
|
|
3096
|
+
const registerLegacyMenuItem = () =>
|
|
3097
|
+
ctx.effect(
|
|
3098
|
+
() =>
|
|
3099
|
+
ctx.slots.inject("sidebar.workspaces.session.menu.item", () =>
|
|
3100
|
+
ctx.slots.register(
|
|
3101
|
+
{
|
|
3102
|
+
name: "sidebar.workspaces.session.menu.item",
|
|
3103
|
+
id: "session-delete",
|
|
3104
|
+
order: 420,
|
|
3105
|
+
locale: NS,
|
|
3106
|
+
inject: () => ({
|
|
3107
|
+
requestDelete: (/** @type {any} */ request) => {
|
|
3108
|
+
requestStore.set(request);
|
|
3109
|
+
},
|
|
3110
|
+
}),
|
|
3111
|
+
},
|
|
3112
|
+
DeleteSessionMenuItem,
|
|
3113
|
+
),
|
|
1592
3114
|
),
|
|
1593
|
-
),
|
|
1594
|
-
|
|
1595
|
-
|
|
3115
|
+
"session-delete: session menu item (legacy slot)",
|
|
3116
|
+
);
|
|
3117
|
+
|
|
3118
|
+
/**
|
|
3119
|
+
* 快捷键:删除「当前会话」与「当前工作区的全部会话」。
|
|
3120
|
+
* 注册整体包 try/catch —— 与本机已有的自定义键位冲突时宿主会抛错,
|
|
3121
|
+
* 那种情况下只失去快捷键,菜单与确认框照常工作。
|
|
3122
|
+
*/
|
|
3123
|
+
/** @param {any} shortcuts */
|
|
3124
|
+
const installShortcuts = (shortcuts) => {
|
|
3125
|
+
if (!shortcuts || typeof shortcuts.register !== "function") return;
|
|
3126
|
+
const register = (/** @type {any} */ command) => {
|
|
3127
|
+
try {
|
|
3128
|
+
ctx.effect(() => shortcuts.register(command), `session-delete: shortcut ${command.id}`);
|
|
3129
|
+
} catch (error) {
|
|
3130
|
+
ctx.logger?.warn?.(
|
|
3131
|
+
`session-delete: shortcut ${command.id} unavailable: ${errorText(error)}`,
|
|
3132
|
+
);
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
const busy = () =>
|
|
3136
|
+
requestStore.getSnapshot()
|
|
3137
|
+
? { status: "blocked", reason: translate("shortcut.busy") }
|
|
3138
|
+
: null;
|
|
3139
|
+
register({
|
|
3140
|
+
id: COMMAND_DELETE,
|
|
3141
|
+
label: () => translate("shortcut.delete"),
|
|
3142
|
+
aliases: ["delete session", "remove session", "删除会话"],
|
|
3143
|
+
// Linux(桌面与 Web)都不声明默认值:宿主把「修饰键 + Backspace」列为保留组合,
|
|
3144
|
+
// 声明了 register() 会抛错,整条快捷键就没了。用户在设置里可以自己绑。
|
|
3145
|
+
defaults: {
|
|
3146
|
+
"desktop:macos": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
3147
|
+
"desktop:windows": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
3148
|
+
"web:macos": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
3149
|
+
"web:windows": { code: "Backspace", modifiers: ["primary", "alt"] },
|
|
3150
|
+
},
|
|
3151
|
+
// 编辑区也放行:⌘⌥⌫ 不是 macOS/Windows 的文本编辑键(那些是 ⌘⌫ / ⌥⌫ / ⌘⌃⌫),
|
|
3152
|
+
// 而 composer 几乎总是持有焦点,只允许 page 会让快捷键实际上按不出来。
|
|
3153
|
+
// 终端排除在外:那里的删除键有更强的本地语义。
|
|
3154
|
+
regions: ["page", "editable"],
|
|
3155
|
+
modals: [],
|
|
3156
|
+
resolve: () => {
|
|
3157
|
+
const blockedNow = busy();
|
|
3158
|
+
if (blockedNow) return blockedNow;
|
|
3159
|
+
const row = currentSession();
|
|
3160
|
+
if (!row) return { status: "blocked", reason: translate("shortcut.noSession") };
|
|
3161
|
+
return {
|
|
3162
|
+
status: "handled",
|
|
3163
|
+
run: () => openSessionConfirm(row.id, row.displayTitle),
|
|
3164
|
+
};
|
|
3165
|
+
},
|
|
3166
|
+
});
|
|
3167
|
+
// 工作区级清空没有默认键位:误触代价太大,键位留给用户在设置里自己绑。
|
|
3168
|
+
register({
|
|
3169
|
+
id: COMMAND_DELETE_WORKSPACE,
|
|
3170
|
+
label: () => translate("shortcut.workspace"),
|
|
3171
|
+
aliases: ["delete workspace sessions", "清空工作区会话"],
|
|
3172
|
+
defaults: {},
|
|
3173
|
+
regions: ["page"],
|
|
3174
|
+
modals: [],
|
|
3175
|
+
resolve: () => {
|
|
3176
|
+
const blockedNow = busy();
|
|
3177
|
+
if (blockedNow) return blockedNow;
|
|
3178
|
+
const workspace = currentWorkspace();
|
|
3179
|
+
if (!workspace) return { status: "blocked", reason: translate("shortcut.noSession") };
|
|
3180
|
+
return {
|
|
3181
|
+
status: "handled",
|
|
3182
|
+
run: () => openWorkspaceConfirm(workspace.workspaceId, workspace.title),
|
|
3183
|
+
};
|
|
3184
|
+
},
|
|
3185
|
+
});
|
|
3186
|
+
};
|
|
3187
|
+
|
|
3188
|
+
// 两个服务都可能比插件晚就绪:用 ctx.inject 延迟,缺任何一个都不影响插件本身加载。
|
|
3189
|
+
// ctx.inject 只有「必须」语义,所以再加一个宽限期兜底:超时就认定宿主没有
|
|
3190
|
+
// contextMenus,直接上旧的会话菜单 slot(否则老宿主上「删除会话」入口会整个消失)。
|
|
3191
|
+
let menusInstalled = false;
|
|
3192
|
+
/** @type {any} */
|
|
3193
|
+
let legacyDispose = null;
|
|
3194
|
+
const ensureLegacyMenu = () => {
|
|
3195
|
+
if (menusInstalled || legacyDispose) return;
|
|
3196
|
+
legacyDispose = registerLegacyMenuItem();
|
|
3197
|
+
};
|
|
3198
|
+
try {
|
|
3199
|
+
if (typeof ctx.inject === "function") {
|
|
3200
|
+
ctx.inject(["contextMenus"], (/** @type {any} */ scoped) => {
|
|
3201
|
+
const service = scoped?.contextMenus ?? (ctx.get ? ctx.get("contextMenus") : undefined);
|
|
3202
|
+
if (installMenuContributions(service)) {
|
|
3203
|
+
menusInstalled = true;
|
|
3204
|
+
if (legacyDispose) {
|
|
3205
|
+
legacyDispose();
|
|
3206
|
+
legacyDispose = null;
|
|
3207
|
+
}
|
|
3208
|
+
} else {
|
|
3209
|
+
ensureLegacyMenu();
|
|
3210
|
+
}
|
|
3211
|
+
});
|
|
3212
|
+
ctx.inject(["shortcuts"], (/** @type {any} */ scoped) => {
|
|
3213
|
+
installShortcuts(scoped?.shortcuts ?? (ctx.get ? ctx.get("shortcuts") : undefined));
|
|
3214
|
+
});
|
|
3215
|
+
const timer = setTimeout(ensureLegacyMenu, MENU_FALLBACK.ms);
|
|
3216
|
+
ctx.effect(() => () => clearTimeout(timer), "session-delete: menu fallback timer");
|
|
3217
|
+
} else {
|
|
3218
|
+
const menus = ctx.get ? ctx.get("contextMenus") : undefined;
|
|
3219
|
+
if (installMenuContributions(menus)) menusInstalled = true;
|
|
3220
|
+
else ensureLegacyMenu();
|
|
3221
|
+
installShortcuts(ctx.get ? ctx.get("shortcuts") : undefined);
|
|
3222
|
+
}
|
|
3223
|
+
} catch (error) {
|
|
3224
|
+
ctx.logger?.warn?.(
|
|
3225
|
+
`session-delete: menu/shortcut setup failed, falling back: ${errorText(error)}`,
|
|
3226
|
+
);
|
|
3227
|
+
ensureLegacyMenu();
|
|
3228
|
+
}
|
|
1596
3229
|
|
|
1597
3230
|
// 回收站入口固定在侧栏页脚,不出现在每个会话的「…」菜单里。
|
|
1598
3231
|
ctx.effect(
|
|
@@ -1619,6 +3252,34 @@ window.__ModuleLoader__.load({
|
|
|
1619
3252
|
"session-delete: sidebar footer trash entry",
|
|
1620
3253
|
);
|
|
1621
3254
|
|
|
3255
|
+
// 设置页分节:偏好 + 回收站概览 + 维护(体检/回执/审计)。
|
|
3256
|
+
// 宿主没有 settings.section 的版本会静默跳过,不影响主流程。
|
|
3257
|
+
try {
|
|
3258
|
+
ctx.effect(
|
|
3259
|
+
() =>
|
|
3260
|
+
ctx.slots.inject("settings.section", () =>
|
|
3261
|
+
ctx.slots.register(
|
|
3262
|
+
{
|
|
3263
|
+
name: "settings.section",
|
|
3264
|
+
id: "session-delete",
|
|
3265
|
+
order: 90,
|
|
3266
|
+
label: () => translate("settings.nav"),
|
|
3267
|
+
locale: NS,
|
|
3268
|
+
inject: () => ({
|
|
3269
|
+
prefsStore: prefsStore,
|
|
3270
|
+
panelStore: panelStore,
|
|
3271
|
+
call: call,
|
|
3272
|
+
}),
|
|
3273
|
+
},
|
|
3274
|
+
SettingsSection,
|
|
3275
|
+
),
|
|
3276
|
+
),
|
|
3277
|
+
"session-delete: settings section",
|
|
3278
|
+
);
|
|
3279
|
+
} catch (error) {
|
|
3280
|
+
ctx.logger?.warn?.(`session-delete: settings section unavailable: ${errorText(error)}`);
|
|
3281
|
+
}
|
|
3282
|
+
|
|
1622
3283
|
ctx.effect(
|
|
1623
3284
|
() =>
|
|
1624
3285
|
ctx.slots.inject("shell.overlay", () =>
|
|
@@ -1630,11 +3291,15 @@ window.__ModuleLoader__.load({
|
|
|
1630
3291
|
Object.assign({}, props, {
|
|
1631
3292
|
requestStore: requestStore,
|
|
1632
3293
|
panelStore: panelStore,
|
|
3294
|
+
prefsStore: prefsStore,
|
|
1633
3295
|
toastStore: toastStore,
|
|
1634
3296
|
call: call,
|
|
1635
3297
|
onTrashed: onTrashed,
|
|
3298
|
+
onTrashedMany: onTrashedMany,
|
|
1636
3299
|
onPurged: onPurged,
|
|
1637
3300
|
onRestored: onRestored,
|
|
3301
|
+
onRestoreComplete: onRestoreComplete,
|
|
3302
|
+
onBatchRestoreDone: onBatchRestoreDone,
|
|
1638
3303
|
tickStore: tickStore,
|
|
1639
3304
|
bump: () => tickStore.set(tickStore.getSnapshot() + 1),
|
|
1640
3305
|
}),
|
|
@@ -1650,6 +3315,25 @@ window.__ModuleLoader__.load({
|
|
|
1650
3315
|
Object.defineProperty(exports, "__test", {
|
|
1651
3316
|
value: Object.freeze({
|
|
1652
3317
|
tokens: T,
|
|
3318
|
+
chunk: chunk,
|
|
3319
|
+
joinList: joinList,
|
|
3320
|
+
impactLine: impactLine,
|
|
3321
|
+
batchChunk: BATCH_CHUNK,
|
|
3322
|
+
menuFallback: MENU_FALLBACK,
|
|
3323
|
+
createPanelLoader: createPanelLoader,
|
|
3324
|
+
createSettingsLoader: createSettingsLoader,
|
|
3325
|
+
createSettingsCache: createSettingsCache,
|
|
3326
|
+
trashFailureText: trashFailureText,
|
|
3327
|
+
restoreNotice: restoreNotice,
|
|
3328
|
+
restoreFailures: restoreFailures,
|
|
3329
|
+
restoreDetailText: restoreDetailText,
|
|
3330
|
+
afterTrashNavigation: afterTrashNavigation,
|
|
3331
|
+
isPartialFailure: isPartialFailure,
|
|
3332
|
+
runBatch: runBatch,
|
|
3333
|
+
panelPollMs: PANEL_POLL_MS,
|
|
3334
|
+
// 词典也暴露出来:单测要比对「内联词典 / locale/*.json」的键集,防止两处漂移。
|
|
3335
|
+
zh: zh,
|
|
3336
|
+
en: en,
|
|
1653
3337
|
}),
|
|
1654
3338
|
});
|
|
1655
3339
|
|