dsh-modpack-kit 0.0.0-stage → 0.1.3

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/client.js ADDED
@@ -0,0 +1,1275 @@
1
+ /**
2
+ * dsh-modpack —— 客户端半边:左侧栏「整合包」。
3
+ *
4
+ * 三页:打包(挑插件、选版本、看检测报告)、安装(链接/本机包、预览、落地)、
5
+ * 设置与记录(扫描策略、白名单、历史)。数据全部来自 /dsh-modpack/api/*(同源 fetch),
6
+ * 与 host 半端共用同一份状态;这里不碰文件,也不做网络请求。
7
+ *
8
+ * 制作通告:本文件在 DeepSeek Harness(DSH)会话中由 AI 助手与作者 Vesna-Strivozha-cn 协作产出。
9
+ */
10
+ window.__ModuleLoader__.load({
11
+ id: "dsh-modpack-kit",
12
+ factory: (require) => {
13
+ const module = { exports: {} }
14
+ const exports = module.exports
15
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
16
+
17
+ const React = require("react")
18
+ const { createElement: h, useCallback, useEffect, useMemo, useRef, useState } = React
19
+
20
+ const API = "/dsh-modpack-kit/api"
21
+
22
+ const box = { border: "0.5px solid var(--dsw-alias-border-l2)", borderRadius: "8px", padding: "12px 14px" }
23
+ const hint = { color: "var(--dsw-alias-label-tertiary)", fontSize: "11.5px", lineHeight: "17px" }
24
+ const label = { fontSize: "13px", lineHeight: "19px" }
25
+ const strong = { fontSize: "13px", fontWeight: 600, lineHeight: "20px" }
26
+ const btn = { height: "28px", padding: "0 12px", fontSize: "12.5px", borderRadius: "6px", cursor: "pointer", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-primary)" }
27
+ const btnPrimary = { ...btn, background: "var(--dsw-alias-fill-primary, #3b6cf6)", borderColor: "transparent", color: "#fff" }
28
+ const input = { height: "26px", padding: "0 8px", fontSize: "12.5px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-primary)", boxSizing: "border-box" }
29
+ const mono = { fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", fontSize: "11.5px", lineHeight: "17px" }
30
+ const row = { display: "flex", gap: "8px", alignItems: "center", flexWrap: "wrap" }
31
+ const chip = { fontSize: "11px", padding: "1px 6px", borderRadius: "999px", border: "0.5px solid var(--dsw-alias-border-l2)", color: "var(--dsw-alias-label-secondary)" }
32
+ const chipBtn = { ...chip, cursor: "pointer", background: "transparent", fontFamily: "inherit" }
33
+ const chipOn = { ...chipBtn, color: "var(--dsw-alias-label-primary)", borderColor: "var(--dsw-alias-fill-primary, #3b6cf6)" }
34
+
35
+ const LEVEL_COLOR = { high: "#ff6b6b", error: "#ff6b6b", medium: "#ffb020", warn: "#ffb020", low: "#8a8f98", info: "#8a8f98" }
36
+ const FORMAT_TEXT = { full: "完整版(含插件本体)", lite: "轻量版(联网取包)" }
37
+ // 分类以插件市场为准:id 与市场目录一致,中文名由 host 从市场目录里带回来。
38
+ const CATEGORY_LABELS = { all: "全部", other: "其它" }
39
+ const categoryOf = (entry) => (entry && entry.category) || "other"
40
+
41
+ // 三处显示位(设置内 / 侧边栏 / 插件内页签):各自独立开关,点一下立刻重挂载,不用重启。
42
+ const PLACEMENT_KEYS = ["settings", "sidebar", "pluginsTab"]
43
+ const placement = { value: { settings: true, sidebar: true, pluginsTab: false }, subs: new Set() }
44
+ function normalizePlacement(raw) {
45
+ const next = { settings: true, sidebar: true, pluginsTab: false }
46
+ if (raw && typeof raw === "object") for (const key of PLACEMENT_KEYS) if (typeof raw[key] === "boolean") next[key] = raw[key]
47
+ // 三处全关就等于把插件藏起来了,host 也拦;这里再兜一层
48
+ if (!next.settings && !next.sidebar && !next.pluginsTab) next.sidebar = true
49
+ return next
50
+ }
51
+ function setPlacement(raw) {
52
+ const next = normalizePlacement(raw)
53
+ const same = PLACEMENT_KEYS.every((key) => placement.value[key] === next[key])
54
+ placement.value = next
55
+ if (same) return
56
+ for (const fn of [...placement.subs]) { try { fn(next) } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
57
+ }
58
+ function subscribePlacement(fn) {
59
+ placement.subs.add(fn)
60
+ return () => placement.subs.delete(fn)
61
+ }
62
+
63
+ // 打包结果(含下载按钮)放在模块里:切页签、关掉面板都不丢,留到退出程序为止。
64
+ const packStore = { value: null, subs: new Set() }
65
+ function readPackValue() {
66
+ return packStore.value
67
+ }
68
+ function setPackValue(value) {
69
+ const same = (packStore.value || null) === (value || null)
70
+ packStore.value = value || null
71
+ if (same) return
72
+ for (const fn of [...packStore.subs]) { try { fn(packStore.value) } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
73
+ }
74
+ function subscribePack(fn) {
75
+ packStore.subs.add(fn)
76
+ return () => packStore.subs.delete(fn)
77
+ }
78
+
79
+ // 点了「清空进程」:打包页上的旧报错、旧的失败结果也一起收掉,别留着当幽灵
80
+ const clearSignal = { subs: new Set() }
81
+ function fireClear() {
82
+ for (const fn of [...clearSignal.subs]) { try { fn() } catch (e) { /* 一个订阅出错不该拖垮别的 */ } }
83
+ }
84
+ function subscribeClear(fn) {
85
+ clearSignal.subs.add(fn)
86
+ return () => clearSignal.subs.delete(fn)
87
+ }
88
+
89
+ async function api(pathname, body) {
90
+ const init = body === undefined ? { headers: { Accept: "application/json" } } : {
91
+ method: "POST",
92
+ headers: { "Content-Type": "application/json" },
93
+ body: JSON.stringify(body),
94
+ }
95
+ let res
96
+ try {
97
+ res = await fetch(API + pathname, init)
98
+ } catch (e) {
99
+ throw new Error("连不上 DSH 本体:" + (e && e.message ? e.message : e))
100
+ }
101
+ let data = null
102
+ try { data = await res.json() } catch {
103
+ throw new Error("服务端返回了非 JSON(HTTP " + res.status + ")")
104
+ }
105
+ if (!res.ok) {
106
+ // 统一在这里抛:上层只要 try/catch 就能把「为什么失败」显示出来,而不是静默卡住
107
+ const message = (data && (data.error || data.message)) || ("HTTP " + res.status)
108
+ const error = new Error(message)
109
+ error.status = res.status
110
+ error.data = data
111
+ throw error
112
+ }
113
+ return data
114
+ }
115
+
116
+ const bytes = (n) => {
117
+ const v = Number(n) || 0
118
+ if (v < 1024) return v + " B"
119
+ if (v < 1024 * 1024) return (v / 1024).toFixed(1) + " KB"
120
+ return (v / 1024 / 1024).toFixed(2) + " MB"
121
+ }
122
+ const when = (iso) => {
123
+ if (!iso) return "—"
124
+ try { return new Date(iso).toLocaleString() } catch { return String(iso) }
125
+ }
126
+
127
+ function Switch(props) {
128
+ return h("label", { style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: props.disabled ? "not-allowed" : "pointer", opacity: props.disabled ? 0.45 : 1 } },
129
+ h("input", { type: "checkbox", checked: !!props.checked, disabled: !!props.disabled, onChange: (e) => props.onChange(e.target.checked) }),
130
+ props.label)
131
+ }
132
+
133
+ // 一句话闪 5 秒:用于「点了也不给关」的开关。
134
+ function useNag(ms = 5000) {
135
+ const [text, setText] = useState("")
136
+ const timer = useRef(null)
137
+ const fire = useCallback((msg) => {
138
+ setText(msg)
139
+ if (timer.current) clearTimeout(timer.current)
140
+ timer.current = setTimeout(() => setText(""), ms)
141
+ }, [ms])
142
+ useEffect(() => () => { if (timer.current) clearTimeout(timer.current) }, [])
143
+ return [text, fire]
144
+ }
145
+
146
+ function NagText(props) {
147
+ if (!props.text) return null
148
+ return h("div", { style: { color: "#ff6b6b", fontSize: "12px", lineHeight: "18px" } }, props.text)
149
+ }
150
+
151
+ // 强制项:开关照常显示(让人知道这项存在),但点不动——点一次弹红字。
152
+ function ForcedSwitch(props) {
153
+ return h("label", {
154
+ style: { display: "inline-flex", gap: "6px", alignItems: "center", fontSize: "12.5px", cursor: "not-allowed", opacity: 0.6 },
155
+ title: "强制性检查,不能关",
156
+ onClick: (e) => { e.preventDefault(); props.onNag() },
157
+ },
158
+ h("input", { type: "checkbox", checked: true, readOnly: true, disabled: true, style: { cursor: "not-allowed" } }),
159
+ props.label)
160
+ }
161
+
162
+ function Tag(props) {
163
+ return h("span", { style: { ...chip, color: props.color || chip.color, borderColor: props.color || "var(--dsw-alias-border-l2)" } }, props.children)
164
+ }
165
+
166
+ function Notice(props) {
167
+ return h("div", { style: { ...box, borderColor: props.tone === "warn" ? "#ffb020" : props.tone === "bad" ? "#ff6b6b" : "var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-l2, transparent)", fontSize: "12px", lineHeight: "18px" } }, props.children)
168
+ }
169
+
170
+ const ORIGIN_LABEL = { local: "本机", market: "市场", config: "配置", data: "数据", pack: "整合包" }
171
+
172
+ function ScanReport(props) {
173
+ const scan = props.scan
174
+ const counts = (scan && scan.counts) || { high: 0, medium: 0, low: 0 }
175
+ const findings = scan && Array.isArray(scan.findings) ? scan.findings : []
176
+ const [open, setOpen] = useState(counts.high > 0)
177
+ const [openGroup, setOpenGroup] = useState({})
178
+ if (!scan) return null
179
+ const groups = Array.isArray(props.groups) && props.groups.length
180
+ ? props.groups
181
+ : (findings.length ? [{ key: "all", label: "全部命中", origin: "", counts, findings }] : [])
182
+ const toggleGroup = (key) => setOpenGroup((prev) => ({ ...prev, [key]: !prev[key] }))
183
+ const toggleOpen = () => setOpen((prev) => !prev)
184
+ return h("div", { style: { display: "flex", flexDirection: "column", gap: "8px" } },
185
+ h("div", { style: row },
186
+ h("div", { style: strong }, "安全检测"),
187
+ h(Tag, { color: counts.high ? "#ff6b6b" : counts.medium ? "#ffb020" : "#2bb673" },
188
+ "高 " + counts.high + " · 中 " + counts.medium + " · 低 " + counts.low),
189
+ h("span", { style: hint }, "扫描 " + (scan.scannedFiles || 0) + " 个文件 / " + bytes(scan.scannedBytes || 0) + (scan.note ? " · " + scan.note : "")),
190
+ findings.length
191
+ ? h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: toggleOpen },
192
+ open ? "收起风险列表(" + findings.length + " 条)" : "展开风险列表(" + findings.length + " 条)")
193
+ : null),
194
+ findings.length === 0 ? h("div", { style: hint }, "没有命中敏感信息或可疑代码规则。") : null,
195
+ open && findings.length
196
+ ? h("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } },
197
+ groups.map((group) => {
198
+ const expanded = openGroup[group.key] === true
199
+ return h("div", { key: group.key, style: { border: "0.5px solid var(--dsw-alias-border-l2)", borderRadius: "6px", overflow: "hidden" } },
200
+ h("div", {
201
+ style: { display: "flex", alignItems: "center", gap: "8px", padding: "6px 9px", cursor: "pointer", background: "var(--dsw-alias-bg-l2, transparent)" },
202
+ onClick: () => toggleGroup(group.key),
203
+ },
204
+ h("span", { style: { ...label, fontSize: "12.5px" } }, group.label),
205
+ group.origin ? h(Tag, null, ORIGIN_LABEL[group.origin] || group.origin) : null,
206
+ h("span", { style: hint }, "高 " + group.counts.high + " · 中 " + group.counts.medium + " · 低 " + group.counts.low),
207
+ h("span", { style: { ...hint, marginLeft: "auto" } }, expanded ? "收起" : "展开")),
208
+ expanded
209
+ ? h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", padding: "0 9px 8px", maxHeight: "220px", overflow: "auto" } },
210
+ group.findings.map((f, i) => h("div", { key: i, style: { ...mono, color: LEVEL_COLOR[f.severity] || "inherit" } },
211
+ "[" + String(f.severity || "").toUpperCase() + "] " + (f.label || f.rule) + " · " + f.file + (f.line ? ":" + f.line : "") + " · " + (f.masked || ""))))
212
+ : null)
213
+ }))
214
+ : null,
215
+ h("div", { style: hint }, props.footNote || "命中内容只在内存里比对,报告只保留类型、位置与掩码,原文不落盘。"))
216
+ }
217
+
218
+ function CompatList(props) {
219
+ const compat = props.compat
220
+ if (!compat) return null
221
+ const findings = compat.findings || []
222
+ if (findings.length === 0) return h("div", { style: hint }, "兼容性:没有发现问题。")
223
+ return h("div", { style: { display: "flex", flexDirection: "column", gap: "5px" } },
224
+ h("div", { style: row }, h("div", { style: strong }, "兼容性"), h("span", { style: hint }, compat.summary || ""),
225
+ compat.blocking ? h(Tag, { color: "#ff6b6b" }, "有阻断项") : null),
226
+ findings.map((f, i) => h("div", { key: i, style: { borderLeft: "2px solid " + (LEVEL_COLOR[f.level] || "transparent"), paddingLeft: "8px" } },
227
+ h("div", { style: { ...label, color: LEVEL_COLOR[f.level] || "inherit" } }, (f.plugin ? f.plugin + ":" : "") + f.message),
228
+ f.suggestion ? h("div", { style: hint }, "建议:" + f.suggestion) : null)))
229
+ }
230
+
231
+ const JOB_KIND_LABEL = { pack: "打包", install: "安装" }
232
+ const JOB_STATUS_TEXT = { running: "进行中", paused: "等决定", acked: "已确认", done: "完成", failed: "失败", cancelled: "已取消" }
233
+
234
+ function useJobs(intervalMs) {
235
+ const [jobs, setJobs] = useState([])
236
+ useEffect(() => {
237
+ let alive = true
238
+ const load = async () => {
239
+ try {
240
+ const res = await fetch(API + "/jobs")
241
+ if (!res.ok) return
242
+ const data = await res.json()
243
+ if (alive && data && Array.isArray(data.jobs)) setJobs(data.jobs)
244
+ } catch { /* 轮询失败不该打断界面,下一次再试 */ }
245
+ }
246
+ load()
247
+ const timer = setInterval(load, intervalMs || 900)
248
+ return () => { alive = false; clearInterval(timer) }
249
+ }, [intervalMs])
250
+ return jobs
251
+ }
252
+
253
+ function ProgressBar(props) {
254
+ const pct = Math.max(0, Math.min(100, Math.round(props.pct || 0)))
255
+ return h("div", { style: { height: "6px", borderRadius: "99px", background: "rgba(127,163,245,.18)", overflow: "hidden" } },
256
+ h("div", { style: { width: pct + "%", height: "100%", borderRadius: "99px", transition: "width .25s ease", background: props.tone || "linear-gradient(90deg,#7FA3F5,#4C7DF0)" } }))
257
+ }
258
+
259
+ // 进度窗:可以拖,拖过的位置记在浏览器本地;没有任务时自动收起,只留一枚唤出按钮。
260
+ const DOCK_POS_KEY = "dsh-modpack-kit:dock-pos"
261
+ function readDockPos() {
262
+ try {
263
+ const raw = typeof localStorage !== "undefined" ? localStorage.getItem(DOCK_POS_KEY) : null
264
+ if (!raw) return null
265
+ const parsed = JSON.parse(raw)
266
+ if (!parsed || typeof parsed !== "object") return null
267
+ if (!Number.isFinite(Number(parsed.x)) || !Number.isFinite(Number(parsed.y))) return null
268
+ return { x: Math.max(0, Math.round(Number(parsed.x))), y: Math.max(0, Math.round(Number(parsed.y))) }
269
+ } catch { return null }
270
+ }
271
+ function writeDockPos(pos) {
272
+ try { if (typeof localStorage !== "undefined" && pos) localStorage.setItem(DOCK_POS_KEY, JSON.stringify(pos)) } catch { /* 存不了就算了,不影响本场使用 */ }
273
+ }
274
+ function viewportSize() {
275
+ const width = typeof window !== "undefined" && Number(window.innerWidth) ? Number(window.innerWidth) : 1280
276
+ const height = typeof window !== "undefined" && Number(window.innerHeight) ? Number(window.innerHeight) : 800
277
+ return { width, height }
278
+ }
279
+
280
+ function JobDock(props) {
281
+ const jobs = Array.isArray(props.jobs) ? props.jobs : []
282
+ const [pos, setPos] = useState(readDockPos())
283
+ const [pinned, setPinned] = useState(false) // 手动唤出:没有任务时也显示
284
+ const [hidden, setHidden] = useState(false) // 手动收起:连进行中的也先藏起来
285
+ const [open, setOpen] = useState(false)
286
+ const [dockMsg, setDockMsg] = useState("")
287
+ const dragRef = useRef(null)
288
+ const boxRef = useRef(null)
289
+ const running = jobs.filter((job) => job.status === "running")
290
+ const visible = !hidden && (pinned || running.length > 0)
291
+
292
+ // 有任务开跑就自己冒出来(之前手动收起的也一并放出来)
293
+ useEffect(() => {
294
+ if (running.length > 0) { setHidden(false) }
295
+ }, [running.length])
296
+
297
+ const startDrag = (event) => {
298
+ if (!event || typeof event.clientX !== "number") return
299
+ const el = boxRef.current
300
+ const rect = el && el.getBoundingClientRect ? el.getBoundingClientRect() : { left: 0, top: 0, width: 0, height: 0 }
301
+ dragRef.current = {
302
+ dx: event.clientX - rect.left,
303
+ dy: event.clientY - rect.top,
304
+ width: rect.width,
305
+ height: rect.height,
306
+ startX: rect.left,
307
+ startY: rect.top,
308
+ moved: false,
309
+ last: null,
310
+ }
311
+ if (event.currentTarget && event.currentTarget.setPointerCapture && event.pointerId !== undefined) {
312
+ try { event.currentTarget.setPointerCapture(event.pointerId) } catch { /* 某些环境不支持捕获,照样能拖 */ }
313
+ }
314
+ }
315
+ const moveDrag = (event) => {
316
+ const drag = dragRef.current
317
+ if (!drag || !event || typeof event.clientX !== "number") return
318
+ const { width, height } = viewportSize()
319
+ const left = Math.min(Math.max(4, event.clientX - drag.dx), Math.max(4, width - drag.width - 4))
320
+ const top = Math.min(Math.max(4, event.clientY - drag.dy), Math.max(4, height - drag.height - 4))
321
+ if (Math.abs(left - drag.startX) > 3 || Math.abs(top - drag.startY) > 3) drag.moved = true
322
+ drag.last = { x: Math.round(left), y: Math.round(top) }
323
+ setPos(drag.last)
324
+ }
325
+ const endDrag = () => {
326
+ const drag = dragRef.current
327
+ if (!drag) return
328
+ dragRef.current = null
329
+ if (drag.moved) {
330
+ if (drag.last) writeDockPos(drag.last)
331
+ return
332
+ }
333
+ // 没拖动就是点了一下标题:展开 / 收起
334
+ setOpen((prev) => !prev)
335
+ }
336
+
337
+ if (!visible) {
338
+ const anchor = pos || null
339
+ const summonStyle = {
340
+ position: "fixed",
341
+ zIndex: 70,
342
+ display: "flex",
343
+ alignItems: "center",
344
+ gap: "6px",
345
+ padding: "7px 11px",
346
+ borderRadius: "999px",
347
+ border: "0.5px solid var(--dsw-alias-border-l2)",
348
+ background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
349
+ color: "var(--dsw-alias-label-primary)",
350
+ boxShadow: "0 6px 18px rgba(0,0,0,.28)",
351
+ cursor: "pointer",
352
+ fontSize: "12px",
353
+ ...(anchor ? { left: anchor.x + "px", top: anchor.y + "px" } : { right: "16px", bottom: "16px" }),
354
+ }
355
+ const badge = running.length || jobs.length
356
+ return h("button", { style: summonStyle, title: "打开整合包进度窗", onClick: () => { setPinned(true); setHidden(false) } },
357
+ h("span", { style: { width: "7px", height: "7px", borderRadius: "99px", background: running.length ? "#4C7DF0" : "rgba(127,163,245,.5)" } }),
358
+ "进度",
359
+ badge ? h("span", { style: { ...hint, marginLeft: "0", fontVariantNumeric: "tabular-nums" } }, String(badge)) : null)
360
+ }
361
+
362
+ const current = running[0] || jobs[0] || null
363
+ const headText = current
364
+ ? (running.length ? (current.note || "处理中") : (JOB_STATUS_TEXT[current.status] || "打包记录"))
365
+ : "还没有任务"
366
+ const headPct = current ? Math.round(current.status === "done" ? 100 : (current.pct || 0)) : 0
367
+ const stop = async (id) => {
368
+ try { await api("/jobs/cancel", { id }) } catch { /* 已经结束就忽略 */ }
369
+ }
370
+ const ack = async (id) => {
371
+ try { await api("/jobs/ack", { id }) } catch (error) { setDockMsg((error && error.message) || "确认失败") }
372
+ }
373
+ const dismiss = async (id) => {
374
+ try { await api("/jobs/dismiss", { id }) } catch (error) { setDockMsg((error && error.message) || "删除失败") }
375
+ }
376
+ const clearDone = async () => {
377
+ // 先试一次服务端的批量清空;老宿主上没有这个路由时,退回逐个删
378
+ try {
379
+ const data = await api("/jobs/clear", {})
380
+ setDockMsg(data && data.removed && data.removed.length ? "" : "没有可清空的进程")
381
+ fireClear()
382
+ return
383
+ } catch (error) {
384
+ const targets = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
385
+ if (targets.length === 0) { setDockMsg((error && error.message) || "清空进程失败"); return }
386
+ let bad = 0
387
+ for (const job of targets) {
388
+ try { await api("/jobs/dismiss", { id: job.id }) } catch { bad += 1 }
389
+ }
390
+ fireClear()
391
+ setDockMsg(bad ? ("有 " + bad + " 条没删掉(可能还在跑),其余已清") : "")
392
+ }
393
+ }
394
+ // 只要有一条不是「在跑」或「停在风险点」,就给清空入口(状态再怪也算收尾)
395
+ const finished = jobs.filter((job) => job.status !== "running" && job.status !== "paused")
396
+
397
+ return h("div", {
398
+ ref: boxRef,
399
+ style: {
400
+ position: "fixed",
401
+ zIndex: 70,
402
+ ...(pos ? { left: pos.x + "px", top: pos.y + "px" } : { right: "16px", bottom: "16px" }),
403
+ width: open ? "380px" : "288px",
404
+ maxHeight: open ? "58vh" : "none",
405
+ overflow: "auto",
406
+ boxSizing: "border-box",
407
+ padding: "10px 12px",
408
+ borderRadius: "10px",
409
+ border: "0.5px solid var(--dsw-alias-border-l2)",
410
+ background: "var(--dsw-alias-surface-1, rgba(24,26,31,.97))",
411
+ boxShadow: "0 10px 30px rgba(0,0,0,.35)",
412
+ display: "flex",
413
+ flexDirection: "column",
414
+ gap: "7px",
415
+ },
416
+ },
417
+ h("div", {
418
+ style: { display: "flex", alignItems: "center", gap: "8px", cursor: "grab", userSelect: "none", touchAction: "none" },
419
+ title: "按住可以拖动;点一下展开或收起",
420
+ onPointerDown: startDrag,
421
+ onPointerMove: moveDrag,
422
+ onPointerUp: endDrag,
423
+ onPointerCancel: endDrag,
424
+ },
425
+ h("span", { style: { fontSize: "12px", color: "var(--dsw-alias-label-secondary, #b6bac3)", minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, headText),
426
+ h("span", { style: { marginLeft: "auto", fontSize: "12px", fontVariantNumeric: "tabular-nums" } }, headPct + "%"),
427
+ running.length > 1 ? h("span", { style: { ...hint, marginLeft: "0" } }, "+" + (running.length - 1)) : null,
428
+ finished.length
429
+ ? h("button", {
430
+ style: { ...chipBtn, marginLeft: "2px", padding: "0 6px", lineHeight: "18px" },
431
+ title: "清掉所有收尾与失败的进程(跑着的和停在风险点的留着)",
432
+ onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation(); clearDone() },
433
+ }, "清空进程")
434
+ : null,
435
+ h("button", {
436
+ style: { ...chipBtn, marginLeft: "2px", padding: "0 6px", lineHeight: "18px" },
437
+ title: "收起(有任务时还会再冒出来)",
438
+ onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation(); setHidden(true); setPinned(false) },
439
+ }, "收起")),
440
+ current ? h(ProgressBar, { pct: headPct, tone: current.status === "failed" ? "#ff6b6b" : current.status === "cancelled" ? "#8b8f99" : undefined }) : null,
441
+ open
442
+ ? (jobs.length === 0
443
+ ? h("div", { style: hint }, "还没有打包或安装任务。开始一个就会出现在这里。")
444
+ : h("div", { style: { display: "flex", flexDirection: "column", gap: "8px", marginTop: "2px" } },
445
+ jobs.map((job) => h("div", { key: job.id, style: { display: "flex", flexDirection: "column", gap: "4px", paddingTop: "7px", borderTop: "0.5px solid var(--dsw-alias-border-l2)" } },
446
+ h("div", { style: row },
447
+ h("span", { style: { ...label, fontSize: "12.5px" } }, job.label || JOB_KIND_LABEL[job.kind] || "任务"),
448
+ h("span", { style: { ...hint, marginLeft: "auto" } }, (JOB_STATUS_TEXT[job.status] || job.status) + " · " + Math.round(job.pct || 0) + "%")),
449
+ h("div", { style: hint }, job.note || ""),
450
+ job.risk && job.status === "paused"
451
+ ? h("div", { style: { ...hint, color: "#ff9b9b", display: "flex", flexDirection: "column", gap: "2px" } },
452
+ h("div", null, "检测到风险:高 " + (job.risk.high || 0) + " · 中 " + (job.risk.medium || 0) + " · 低 " + (job.risk.low || 0)),
453
+ h("div", { style: { fontSize: "10.5px" } }, job.risk.message || ""),
454
+ job.risk.groups && job.risk.groups.length
455
+ ? h("div", { style: { fontSize: "10.5px" } },
456
+ job.risk.groups.map((g) => (g.label || "") + "(高 " + ((g.counts && g.counts.high) || 0) + " / 中 " + ((g.counts && g.counts.medium) || 0) + ")").join(" "))
457
+ : null)
458
+ : null,
459
+ h(ProgressBar, { pct: job.pct, tone: job.status === "failed" || job.status === "paused" ? "#ff6b6b" : job.status === "cancelled" ? "#8b8f99" : undefined }),
460
+ h("div", { style: { display: "flex", flexWrap: "wrap", gap: "6px" } },
461
+ job.status === "running" ? h("button", { style: { ...chipBtn }, onClick: () => stop(job.id) }, "终止") : null,
462
+ job.status === "done" && job.kind === "pack" && job.data && job.data.token
463
+ ? h("button", {
464
+ style: { ...chipBtn, color: "#4C7DF0", borderColor: "#4C7DF0" },
465
+ title: "跳到打包页的下载部分",
466
+ onClick: () => { if (typeof props.onOpenResult === "function") props.onOpenResult(job) },
467
+ }, "下载安装包")
468
+ : null,
469
+ job.canAck
470
+ ? h("button", { style: { ...chipBtn, color: "#ff6b6b", borderColor: "#ff6b6b" }, title: "忽略风险,在同一个任务里接着跑完", onClick: () => ack(job.id) }, "我知道在干什么")
471
+ : null,
472
+ job.canDismiss
473
+ ? h("button", { style: { ...chipBtn, color: "var(--dsw-alias-label-tertiary, #8b8f99)" }, title: "从列表里删掉这条记录", onClick: () => dismiss(job.id) }, "删除该进程")
474
+ : null,
475
+ job.error && job.status !== "paused" ? h("span", { style: { ...hint, color: "#ff6b6b" } }, job.error) : null)))))
476
+ : h("div", { style: { ...hint, fontSize: "10.5px" } },
477
+ (running.length ? running.length + " 个任务进行中 · " : "") + "按住标题能拖动,点标题展开看详情、也能中途终止"),
478
+ dockMsg
479
+ ? h("div", { style: { ...hint, fontSize: "10.5px", color: "#ff6b6b", display: "flex", gap: "6px", alignItems: "center" } },
480
+ dockMsg,
481
+ h("button", { style: { ...chipBtn, marginLeft: "auto" }, onClick: () => setDockMsg("") }, "知道了"))
482
+ : null)
483
+ }
484
+
485
+ // —— 打包 ——
486
+ function PackPanel(props) {
487
+ const status = props.status
488
+ const jobs = Array.isArray(props.jobs) ? props.jobs : []
489
+ const pageSize = (status && status.config && status.config.catalogPageSize) || 20
490
+ const [installed, setInstalled] = useState((status && status.installed) || [])
491
+ const [marketInfo, setMarketInfo] = useState({}) // name -> 市场同名条目(标题/版本/分类)
492
+ const [catalog, setCatalog] = useState((status && status.catalog) || { present: false, categories: [] })
493
+ const [loading, setLoading] = useState(!(status && status.installed))
494
+ const [selected, setSelected] = useState({}) // name -> {source, spec, mode}
495
+ const [query, setQuery] = useState("")
496
+ const [category, setCategory] = useState("all")
497
+ const [search, setSearch] = useState({ items: [], total: 0, page: 0, hasMore: false, error: "" })
498
+ const [searching, setSearching] = useState(false)
499
+ const [syncing, setSyncing] = useState("")
500
+ const [options, setOptions] = useState({
501
+ includePayload: true,
502
+ includeConfig: true,
503
+ scanBeforePack: true,
504
+ confirmLicense: false,
505
+ name: "DSH 整合包",
506
+ description: "",
507
+ author: "",
508
+ })
509
+ const [busy, setBusy] = useState("")
510
+ // 结果由 Home 保管(模块级缓存),切页签回来仍然在
511
+ const result = props.result === undefined ? null : props.result
512
+ const setResult = typeof props.setResult === "function" ? props.setResult : () => {}
513
+ const [started, setStarted] = useState("")
514
+ const [seenJobs, setSeenJobs] = useState({})
515
+ const [mountAt] = useState(() => Date.now())
516
+ const [error, setError] = useState("")
517
+ const [packNag, firePackNag] = useNag()
518
+ const resultRef = useRef(null)
519
+
520
+ const active = query.trim() !== "" || category !== "all"
521
+
522
+ // 首屏只读「已装 + 目录摘要 + 每条的相机市场信息」,不整份下发目录
523
+ useEffect(() => {
524
+ let alive = true
525
+ ;(async () => {
526
+ try {
527
+ const st = status && status.installed ? status : await api("/status")
528
+ if (!alive) return
529
+ const list = (st && st.installed) || []
530
+ setInstalled(list)
531
+ setCatalog((st && st.catalog) || { present: false, categories: [] })
532
+ if (st && st.placements) setPlacement(st.placements)
533
+ if (list.length) {
534
+ const look = await api("/catalog/lookup", { names: list.map((p) => p.name) })
535
+ if (alive && look && look.ok) setMarketInfo(look.items || {})
536
+ }
537
+ } catch (e) {
538
+ if (alive) setError(e.message || String(e))
539
+ } finally {
540
+ if (alive) setLoading(false)
541
+ }
542
+ })()
543
+ return () => { alive = false }
544
+ }, [])
545
+
546
+ // 搜索/选分类才查市场目录;服务端分页,一次一页,输入停 220ms 再发
547
+ useEffect(() => {
548
+ if (!active) { setSearch({ items: [], total: 0, page: 0, hasMore: false, error: "" }); return }
549
+ let alive = true
550
+ const timer = setTimeout(async () => {
551
+ setSearching(true)
552
+ try {
553
+ const data = await api("/catalog/search", { query, category, page: 1, pageSize })
554
+ if (!alive) return
555
+ setSearch({
556
+ items: data.items || [],
557
+ total: data.total || 0,
558
+ page: data.page || 1,
559
+ hasMore: !!data.hasMore,
560
+ error: data.error || "",
561
+ })
562
+ } catch (e) {
563
+ if (alive) setSearch({ items: [], total: 0, page: 0, hasMore: false, error: e.message || String(e) })
564
+ } finally {
565
+ if (alive) setSearching(false)
566
+ }
567
+ }, 220)
568
+ return () => { alive = false; clearTimeout(timer) }
569
+ }, [query, category, active, pageSize])
570
+
571
+ const loadMore = async () => {
572
+ if (searching || !search.hasMore) return
573
+ setSearching(true)
574
+ try {
575
+ const data = await api("/catalog/search", { query, category, page: (search.page || 1) + 1, pageSize })
576
+ setSearch((prev) => ({
577
+ ...prev,
578
+ items: prev.items.concat(data.items || []),
579
+ page: data.page || prev.page,
580
+ hasMore: !!data.hasMore,
581
+ total: data.total || prev.total,
582
+ }))
583
+ } catch (e) {
584
+ setSearch((prev) => ({ ...prev, error: e.message || String(e) }))
585
+ } finally {
586
+ setSearching(false)
587
+ }
588
+ }
589
+
590
+ const buildCatalog = async () => {
591
+ setSyncing("正在从插件市场取目录(5~30 秒,看网络)…")
592
+ try {
593
+ const data = await api("/catalog/sync", { force: true })
594
+ if (data && data.ok) {
595
+ setCatalog((data.catalog) || { present: true })
596
+ setSyncing("目录就绪:" + (data.count || 0) + " 条" + (data.skipped ? "(本来就有)" : ""))
597
+ } else {
598
+ setSyncing((data && data.error) || "目录没取到,稍后再试")
599
+ }
600
+ } catch (e) {
601
+ setSyncing(String((e && e.message) || e))
602
+ }
603
+ }
604
+
605
+ const localRows = useMemo(() => installed.map((p) => {
606
+ const m = marketInfo[p.name] || {}
607
+ return {
608
+ name: p.name,
609
+ version: p.version,
610
+ title: m.title || p.name,
611
+ description: m.description || p.description || "",
612
+ category: m.category || p.category || "other",
613
+ marketVersion: m.version || "",
614
+ hasMarket: Boolean(m.version),
615
+ source: "profile",
616
+ }
617
+ }), [installed, marketInfo])
618
+
619
+ const rows = active ? search.items : localRows
620
+ const chips = useMemo(() => {
621
+ const list = (catalog && Array.isArray(catalog.categories)) ? catalog.categories : []
622
+ return [{ id: "all", label: "全部", count: (catalog && catalog.count) || 0 }].concat(list.map((c) => ({ id: c.id, label: c.label, count: c.count || 0 })))
623
+ }, [catalog])
624
+ const labelOf = (id) => {
625
+ const hit = chips.find((c) => c.id === id)
626
+ return (hit && hit.label) || CATEGORY_LABELS[id] || id
627
+ }
628
+
629
+ const picked = Object.keys(selected)
630
+ const toggle = (entry) => {
631
+ setSelected((prev) => {
632
+ const next = { ...prev }
633
+ if (next[entry.name]) delete next[entry.name]
634
+ else next[entry.name] = {
635
+ name: entry.name,
636
+ source: entry.source,
637
+ spec: entry.version || "",
638
+ mode: "base",
639
+ }
640
+ return next
641
+ })
642
+ }
643
+ const setSpec = (name, spec) => setSelected((prev) => ({ ...prev, [name]: { ...prev[name], spec } }))
644
+ const setMode = (name, mode) => setSelected((prev) => ({ ...prev, [name]: { ...prev[name], mode } }))
645
+ // 同名市场版:装出来是上游原版代码 + 插件默认配置
646
+ const switchMarket = (entry, toMarket) => setSelected((prev) => {
647
+ if (!prev[entry.name]) return prev
648
+ return {
649
+ ...prev,
650
+ [entry.name]: toMarket
651
+ ? { name: entry.name, source: "npm", spec: entry.marketVersion || "", mode: "base" }
652
+ : { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" },
653
+ }
654
+ })
655
+
656
+ const addAllLocal = () => setSelected((prev) => {
657
+ const next = { ...prev }
658
+ for (const entry of localRows) {
659
+ if (!next[entry.name]) next[entry.name] = { name: entry.name, source: "profile", spec: entry.version || "", mode: "base" }
660
+ }
661
+ return next
662
+ })
663
+ const clearSelected = () => setSelected({})
664
+
665
+ const [jobMsg, setJobMsg] = useState("")
666
+ const pausedJobs = (props.jobs || []).filter((job) => job.kind === "pack" && job.status === "paused" && job.risk)
667
+
668
+ const ackJob = async (id) => {
669
+ setJobMsg("")
670
+ try {
671
+ const data = await api("/jobs/ack", { id })
672
+ if (!data || !data.ok) setJobMsg((data && data.error) || "确认失败")
673
+ } catch (e) { setJobMsg(String((e && e.message) || e)) }
674
+ }
675
+ // 停在风险点的任务:按插件分栏列出命中项,确认/删除都在这里做
676
+ const pausedRiskNodes = []
677
+ if (pausedJobs.length > 0) {
678
+ pausedRiskNodes.push(h("div", { key: "title", style: { ...strong, color: "#ff6b6b" } }, "打包停在风险点(" + pausedJobs.length + " 个任务)"))
679
+ pausedRiskNodes.push(h("div", { key: "hint", style: hint }, "下面是每个插件自己的命中项。确认后原任务从这个检测点接着跑完,不再重复检测。"))
680
+ for (const job of pausedJobs) {
681
+ const groupNodes = (job.risk.groups || []).map((group, index) => {
682
+ const sampleNodes = (group.samples || []).map((sample, i) => h("div", {
683
+ key: i,
684
+ style: { color: LEVEL_COLOR[sample.severity] || "inherit" },
685
+ }, "· " + (sample.label || "") + " " + (sample.file || "") + (sample.line ? ":" + sample.line : "")))
686
+ return h("div", {
687
+ key: index,
688
+ style: { ...box, padding: "8px 10px", background: "transparent", display: "flex", flexDirection: "column", gap: "4px" },
689
+ },
690
+ h("div", { style: row },
691
+ h(Tag, null, group.plugin || group.label),
692
+ h("span", { style: hint }, ORIGIN_LABEL[group.origin] || group.origin || ""),
693
+ h("span", { style: hint }, "高 " + ((group.counts && group.counts.high) || 0) + " · 中 " + ((group.counts && group.counts.medium) || 0) + " · 低 " + ((group.counts && group.counts.low) || 0))),
694
+ sampleNodes.length > 0
695
+ ? h("div", { style: { ...mono, display: "flex", flexDirection: "column", gap: "2px" } }, sampleNodes)
696
+ : h("div", { style: hint }, "命中详情写进了包内 security/report.txt。"))
697
+ })
698
+ pausedRiskNodes.push(h("div", { key: job.id, style: { display: "flex", flexDirection: "column", gap: "6px" } },
699
+ h("div", { style: { ...row, justifyContent: "space-between" } },
700
+ h("div", { style: strong }, job.label || "打包任务"),
701
+ h("div", { style: row },
702
+ h("button", { style: { ...btn, borderColor: "#ff6b6b", color: "#ff6b6b" }, onClick: () => ackJob(job.id) }, "我知道在干什么"),
703
+ h("button", { style: btn, onClick: () => dismissJob(job.id) }, "删除该进程"))),
704
+ groupNodes))
705
+ }
706
+ pausedRiskNodes.push(h("div", { key: "msg", style: hint }, jobMsg))
707
+ }
708
+
709
+ const dismissJob = async (id) => {
710
+ setJobMsg("")
711
+ try {
712
+ const data = await api("/jobs/dismiss", { id })
713
+ if (!data || !data.ok) setJobMsg((data && data.error) || "删除失败")
714
+ } catch (e) { setJobMsg(String((e && e.message) || e)) }
715
+ }
716
+
717
+ const doPack = async (ack) => {
718
+ setError(""); setStarted(""); setBusy("start")
719
+ try {
720
+ const data = await api("/pack", {
721
+ async: true,
722
+ selection: picked.map((name) => selected[name]),
723
+ options: {
724
+ includePayload: options.includePayload,
725
+ includeConfig: options.includeConfig,
726
+ acknowledge: ack === true,
727
+ force: false,
728
+ confirmLicense: options.confirmLicense,
729
+ name: options.name,
730
+ description: options.description,
731
+ author: options.author,
732
+ },
733
+ })
734
+ if (!data) { setError("没有响应"); return }
735
+ if (!data.ok) { setError(data.error || "打包请求被拒绝"); return }
736
+ setStarted((data.job && data.job.label) || "打包任务")
737
+ } catch (e) {
738
+ setError(String((e && e.message) || e))
739
+ } finally { setBusy("") }
740
+ }
741
+
742
+ // 后台任务完成后,把结果搬回这一页(可以同时打好几个包)
743
+ useEffect(() => {
744
+ const finished = (props.jobs || []).filter((job) => job.kind === "pack" && job.status !== "running" && job.data && Date.parse(job.startedAt) >= mountAt)
745
+ const fresh = finished.filter((job) => !seenJobs[job.id])
746
+ if (fresh.length === 0) return
747
+ const nextSeen = { ...seenJobs }
748
+ for (const job of fresh) nextSeen[job.id] = true
749
+ setSeenJobs(nextSeen)
750
+ const payload = fresh[fresh.length - 1].data
751
+ if (payload && payload.ok) setResult(payload)
752
+ else if (payload && payload.refused) setResult({ refused: true, needsAck: payload.needsAck === true, trustedOnly: payload.trustedOnly === true, error: payload.error, scan: payload.scan, scanGroups: payload.scanGroups })
753
+ else if (payload && payload.cancelled) { setResult(null); setError(payload.error || "已取消") }
754
+ else { setResult(null); setError((payload && payload.error) || "打包失败,详情见左下角") }
755
+ }, [props.jobs])
756
+
757
+ // 从进度窗点「下载安装包」跳过来:滚到结果那一块
758
+ useEffect(() => {
759
+ if (!props.focus) return
760
+ const el = resultRef.current
761
+ if (el && typeof el.scrollIntoView === "function") {
762
+ try { el.scrollIntoView({ block: "start", behavior: "smooth" }) } catch { /* 老浏览器不支持行为参数,忽略 */ }
763
+ }
764
+ }, [props.focus])
765
+
766
+ // 「清空进程」之后,打包页上的旧报错与失败结果也一起收掉
767
+ useEffect(() => subscribeClear(() => {
768
+ setError("")
769
+ const current = props.result
770
+ if (current && (current.refused || current.error)) setResult(null)
771
+ }), [props.result])
772
+
773
+ const downloadPack = async () => {
774
+ if (!result || !result.token) return
775
+ setBusy("download")
776
+ try {
777
+ const res = await fetch(API + "/download", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: result.token, fileName: result.fileName }) })
778
+ if (!res.ok) { setError("下载失败(" + res.status + ")"); return }
779
+ const blob = await res.blob()
780
+ const url = URL.createObjectURL(blob)
781
+ const a = document.createElement("a")
782
+ a.href = url
783
+ a.download = result.fileName || "pack.dshpack"
784
+ document.body.appendChild(a)
785
+ a.click()
786
+ setTimeout(() => { try { a.remove(); URL.revokeObjectURL(url) } catch {} }, 4000)
787
+ } catch (e) {
788
+ setError("下载失败:" + (e && e.message ? e.message : e))
789
+ } finally { setBusy("") }
790
+ }
791
+
792
+ const savePack = async () => {
793
+ if (!result || !result.token) return
794
+ setBusy("save")
795
+ try {
796
+ const data = await api("/save", { token: result.token, fileName: result.fileName })
797
+ if (data && data.ok) setResult({ ...result, savedPath: data.path })
798
+ else setError((data && data.error) || "保存失败")
799
+ } catch (e) {
800
+ setError(e.message || String(e))
801
+ } finally { setBusy("") }
802
+ }
803
+
804
+ return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
805
+ h(Notice, null,
806
+ h("b", null, "打包:将所选插件封装为一个 .dshpack 文件"),
807
+ " 完整版包含插件本体的全部文件;轻量版仅记录插件名称与版本,安装时按版本从插件市场下载。两种包在安装前均不修改 profile 内容。",
808
+ status && status.market && status.market.installed
809
+ ? h("div", { style: { ...hint, marginTop: "6px" } }, "已检测到插件市场 v" + status.market.version + ":本插件与其共用目录源与安装链路,但不依赖该插件,移除后打包与安装功能不受影响。")
810
+ : h("div", { style: { ...hint, marginTop: "6px" } }, "未检测到插件市场,功能不受影响:打包、安装与检测均在本地完成。建议先安装 dshmarket 以获得分类、搜索与「切换市场版」入口;未安装时,首次使用请点击「建立目录索引」。"),
811
+ h("div", { style: hint }, "目录中存在同名插件时,该条目末尾提供「(切换市场版)」入口:可将打包源切换为上架市场的上游原版,安装结果与从市场安装一致。")),
812
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
813
+ h("div", { style: row },
814
+ h("div", { style: strong }, "选择插件"),
815
+ h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "搜索插件名 / 描述(在插件市场目录里搜)", value: query, onChange: (e) => setQuery(e.target.value) }),
816
+ active ? h("button", { style: btn, onClick: () => { setQuery(""); setCategory("all") } }, "回到已装") : null,
817
+ h("button", { style: btn, onClick: addAllLocal, title: "把本机已装的全部插件加入选择(默认按基础配置打包,可逐个改)" }, "全部加入"),
818
+ h("button", { style: btn, disabled: picked.length === 0, onClick: clearSelected, title: "清空当前选择" }, "清除选择"),
819
+ h("span", { style: hint }, loading ? "读取中…" : active
820
+ ? ("已选 " + picked.length + " · 匹配 " + search.total + " 条" + (searching ? " · 搜索中…" : "") + (search.total > rows.length ? " · 已加载 " + rows.length : ""))
821
+ : ("已选 " + picked.length + " 个 · 本机已装 " + localRows.length + " 个"))),
822
+ !catalog.present
823
+ ? h("div", { style: row },
824
+ h("span", { style: hint }, "还没有插件市场目录——分类和搜索要靠它。"),
825
+ h("button", { style: btn, disabled: !!syncing, onClick: buildCatalog }, syncing || "建立目录索引(5~30 秒)"))
826
+ : null,
827
+ catalog.present && syncing ? h("div", { style: hint }, syncing) : null,
828
+ catalog.present ? h("div", { style: { ...row, rowGap: "4px", maxHeight: "78px", overflow: "auto" } },
829
+ chips.map((c) => h("button", {
830
+ key: c.id,
831
+ style: category === c.id ? chipOn : chipBtn,
832
+ onClick: () => setCategory(c.id),
833
+ title: "只看「" + c.label + "」" + (c.count ? ",市场内 " + c.count + " 个" : ""),
834
+ }, c.label + (c.count ? " " + c.count : "")))) : null,
835
+ search.error ? h("div", { style: { ...hint, color: "#ffb020" } }, search.error) : null,
836
+ h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", maxHeight: "320px", overflow: "auto" } },
837
+ rows.length === 0
838
+ ? h("div", { style: hint }, loading ? "读取中…" : active ? (searching ? "搜索中…" : "无匹配条目") : "本机尚未安装插件")
839
+ : rows.map((entry) => {
840
+ const on = Boolean(selected[entry.name])
841
+ return h("div", { key: entry.name, style: { display: "flex", gap: "8px", alignItems: "center", padding: "5px 2px", borderTop: "0.5px solid var(--dsw-alias-border-l2)", flexWrap: "wrap" } },
842
+ h("input", { type: "checkbox", checked: on, onChange: () => toggle(entry) }),
843
+ h("div", { style: { flex: "1 1 220px", minWidth: "180px" } },
844
+ h("div", { style: label }, entry.title || entry.name, " ", h("span", { style: hint }, "@" + (entry.version || "?"))),
845
+ h("div", { style: hint }, (entry.description || "").slice(0, 110))),
846
+ h("span", { style: chip }, entry.installed === false ? "市场" : "本机"),
847
+ h("span", { style: { ...chip, color: "var(--dsw-alias-label-tertiary)" } }, labelOf(categoryOf(entry))),
848
+ entry.updateAvailable ? h(Tag, { color: "#2bb673" }, "市场版 " + (entry.marketVersion || entry.version) + " 更新") : null,
849
+ on ? h("input", {
850
+ style: { ...input, width: "120px" },
851
+ placeholder: selected[entry.name].source === "npm" ? "版本,空=最新" : "版本,空=原版",
852
+ value: selected[entry.name].spec || "",
853
+ onChange: (e) => setSpec(entry.name, e.target.value),
854
+ }) : null,
855
+ on && entry.source === "profile" && selected[entry.name].source === "profile" ? h("div", { style: { display: "flex", gap: "4px" } },
856
+ h("button", { style: selected[entry.name].mode === "base" ? chipOn : chipBtn, onClick: () => setMode(entry.name, "base"), title: "上游原版代码 + 插件默认配置,不带你的修改" }, "基础配置"),
857
+ h("button", { style: selected[entry.name].mode === "local" ? chipOn : chipBtn, onClick: () => setMode(entry.name, "local"), title: "打你本机现在的代码、配置与数据快照" }, "本地改动")) : null,
858
+ entry.hasMarket && entry.source === "profile" && on ? h("button", {
859
+ style: { ...chipBtn, border: "none", fontSize: "10.5px", color: "var(--dsw-alias-label-tertiary)" },
860
+ onClick: () => switchMarket(entry, selected[entry.name].source !== "npm"),
861
+ title: "改用插件市场发的同名版本(上游原版代码 + 默认配置),装出来和从市场装一样",
862
+ }, selected[entry.name].source === "npm" ? "(切回本机版)" : "(切换市场版)") : null)
863
+ })),
864
+ active && search.hasMore ? h("div", { style: row },
865
+ h("button", { style: btn, disabled: searching, onClick: loadMore }, searching ? "加载中…" : ("加载更多(还有 " + Math.max(0, search.total - rows.length) + " 条)"))) : null,
866
+ h("div", { style: hint }, active
867
+ ? "排序:已装的排前面,其余按插件市场的相关度与目录顺序。分类和词条都来自插件市场目录。"
868
+ : "首屏只列本机已装。搜索或点分类才会去插件市场目录里查,服务端分页、一次一页。")
869
+ ),
870
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
871
+ h("div", { style: strong }, "包选项"),
872
+ h("div", { style: { ...row, rowGap: "6px" } },
873
+ h(Switch, { checked: options.includePayload, label: "包含插件本体(关=轻量版)", onChange: (v) => setOptions({ ...options, includePayload: v }) }),
874
+ h(Switch, { checked: options.includeConfig, label: "包含配置与数据快照", onChange: (v) => setOptions({ ...options, includeConfig: v }) }),
875
+ h(ForcedSwitch, { label: "打包前安全检测(强制)", onNag: () => firePackNag("你想干什么") })),
876
+ h(NagText, { text: packNag }),
877
+ h("div", { style: { ...row, rowGap: "6px" } },
878
+ h("input", { style: { ...input, flex: "1 1 200px" }, placeholder: "整合包名", value: options.name, onChange: (e) => setOptions({ ...options, name: e.target.value }) }),
879
+ h("input", { style: { ...input, flex: "1 1 160px" }, placeholder: "作者(可空)", value: options.author, onChange: (e) => setOptions({ ...options, author: e.target.value }) })),
880
+ h("input", { style: { ...input, width: "100%" }, placeholder: "一句话描述(可空)", value: options.description, onChange: (e) => setOptions({ ...options, description: e.target.value }) }),
881
+ h(Switch, { checked: options.confirmLicense, label: "我确认所选插件的许可证允许再分发,或已获得作者授权", onChange: (v) => setOptions({ ...options, confirmLicense: v }) }),
882
+ h("div", { style: row },
883
+ h("button", { style: btnPrimary, disabled: picked.length === 0 || busy === "start", onClick: doPack }, busy === "start" ? "提交中…" : ("打包 " + picked.length + " 个插件")),
884
+ started ? h("span", { style: hint }, "已开始:" + started + "(进度在左下角,可以接着选别的再打一个)") : null,
885
+ status ? h("span", { style: hint }, "DSH " + (status.dshVersion || "?") + " · profile " + status.profile) : null)),
886
+ pausedRiskNodes.length ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px", borderColor: "#d9534f" } }, pausedRiskNodes) : null,
887
+ error ? h(Notice, { tone: "bad" }, error) : null,
888
+ result ? h("div", { ref: resultRef, style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
889
+ result.refused || result.error
890
+ ? h(Notice, { tone: "warn" },
891
+ h("b", null, "已停止:"), result.error || "未通过检查",
892
+ result.needsAck ? h("div", { style: { ...row, marginTop: "8px" } },
893
+ h("button", {
894
+ style: { ...btn, borderColor: "#ff6b6b", color: "#ff6b6b" },
895
+ disabled: busy === "start",
896
+ onClick: () => doPack(true),
897
+ }, busy === "start" ? "提交中…" : "我已知晓其中风险,继续打包")) : null)
898
+ : h("div", { style: row },
899
+ h("div", { style: strong }, result.fileName),
900
+ h(Tag, { color: "#2bb673" }, bytes(result.size)),
901
+ h(Tag, null, FORMAT_TEXT[result.manifest && result.manifest.format] || ""),
902
+ h("span", { style: hint }, "包内插件 " + ((result.manifest && result.manifest.plugins) || []).length + " 个")),
903
+ result.scan ? h(ScanReport, { scan: result.scan, groups: result.scanGroups, footNote: "报告已写进包内 security/report.txt(只含类型与掩码)。" }) : null,
904
+ result.manifest && result.manifest.plugins && result.manifest.plugins.length
905
+ ? h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
906
+ result.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
907
+ "· " + p.name + "@" + p.version + " " + (p.size ? bytes(p.size) : "") + ((p.mode === "local" || p.localEdits) ? " [本地改动]" : " [基础配置]") + (p.configIncluded ? " [含配置]" : ""))))
908
+ : null,
909
+ result.compat ? h(CompatList, { compat: result.compat }) : null,
910
+ result.notes && result.notes.length ? h("div", { style: { ...hint, maxHeight: "110px", overflow: "auto" } }, result.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
911
+ result.refused || result.error ? null : h("div", { style: row },
912
+ h("button", { style: btnPrimary, disabled: busy !== "", onClick: downloadPack }, busy === "download" ? "准备下载…" : "下载 .dshpack"),
913
+ h("button", { style: btn, disabled: busy !== "", onClick: savePack }, busy === "save" ? "保存中…" : "保存到本机 packs/"),
914
+ result.savedPath ? h("span", { style: hint }, "已存:" + result.savedPath) : null),
915
+ result.refused || result.error ? null : h("div", { style: hint }, "下载后可在「安装 / 导入」页签读回,或将该文件转交他人。"))
916
+ : null)
917
+ }
918
+
919
+ // —— 安装 / 导入 ——
920
+ function InstallPanel(props) {
921
+ const [source, setSource] = useState({ kind: "url", url: "", file: "" })
922
+ const [packs, setPacks] = useState([])
923
+ const [preview, setPreview] = useState(null)
924
+ const [busy, setBusy] = useState("")
925
+ const [error, setError] = useState("")
926
+ const [done, setDone] = useState(null)
927
+ const [options, setOptions] = useState({ keepLocal: true, applyConfig: true, force: false, dryRun: false, enableBundles: !!((props.status && props.status.config && props.status.config.enableOnInstall) === true) })
928
+
929
+ const reloadPacks = useCallback(async () => {
930
+ try {
931
+ const data = await api("/packs")
932
+ if (data && data.ok) setPacks(data.items || [])
933
+ } catch { /* 列目录失败不打扰用户,真要装可以用链接 */ }
934
+ }, [])
935
+ useEffect(() => { reloadPacks() }, [reloadPacks])
936
+
937
+ const bodyFor = () => {
938
+ if (source.kind === "url") return { url: source.url.trim() }
939
+ return { file: source.file }
940
+ }
941
+
942
+ const inspect = async () => {
943
+ setBusy("inspect"); setError(""); setPreview(null); setDone(null)
944
+ try {
945
+ const data = await api("/inspect", { ...bodyFor(), force: options.force })
946
+ if (data && data.ok) setPreview(data)
947
+ else { setPreview(null); setError((data && data.error) || "读取失败") }
948
+ } catch (e) {
949
+ setPreview(null); setError(e.message || String(e))
950
+ } finally { setBusy("") }
951
+ }
952
+
953
+ const install = async () => {
954
+ setBusy("install"); setError(""); setDone(null)
955
+ try {
956
+ const data = await api("/install", { ...bodyFor(), ...options })
957
+ if (!data.ok) {
958
+ setDone({ ok: false, error: data.error, refused: data.refused, scan: data.scan, report: data.report })
959
+ return
960
+ }
961
+ setDone(data)
962
+ } catch (e) {
963
+ setDone({ ok: false, error: e.message || String(e), scan: (e.data && e.data.scan) || null, report: (e.data && e.data.report) || "", refused: Boolean(e.data && e.data.refused) })
964
+ } finally { setBusy("") }
965
+ }
966
+
967
+ return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
968
+ h(Notice, null,
969
+ h("b", null, "先看清楚,再装"),
970
+ " 读取阶段解压、校验完整性、扫一遍风险,全部在内存里完成;只有你点「安装」才会碰 profile。安装走官方 ",
971
+ h("code", { style: mono }, "dsh plugin add"), ",不手改 node_modules。"),
972
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
973
+ h("div", { style: row },
974
+ h("button", { style: source.kind === "url" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "url" }) }, "从链接读取"),
975
+ h("button", { style: source.kind === "file" ? btnPrimary : btn, onClick: () => setSource({ ...source, kind: "file" }) }, "从本机 packs/ 读取")),
976
+ source.kind === "url"
977
+ ? h("input", { style: { ...input, width: "100%" }, placeholder: "https://…/xxx.dshpack", value: source.url, onChange: (e) => setSource({ ...source, url: e.target.value }) })
978
+ : h("div", { style: row },
979
+ h("div", { style: { display: "flex", flexDirection: "column", gap: "3px", flex: "1 1 260px", maxHeight: "170px", overflow: "auto" } },
980
+ packs.length === 0 ? h("div", { style: hint }, "packs 目录还是空的。先去打包页生成一个,或把 .dshpack 放进 " + ((props.status && props.status.paths && props.status.paths.packs) || "packs")) : null,
981
+ packs.map((p) => h("label", { key: p.name, style: { ...row, gap: "6px", cursor: "pointer" } },
982
+ h("input", { type: "radio", name: "packfile", checked: source.file === p.name, onChange: () => setSource({ ...source, file: p.name }) }),
983
+ h("span", { style: label }, p.name),
984
+ h("span", { style: hint }, bytes(p.size) + " · " + when(p.mtime))))),
985
+ h("button", { style: btn, onClick: reloadPacks }, "刷新")),
986
+ h("div", { style: row },
987
+ h(Switch, { checked: options.keepLocal, label: "保留本地已有修改(不覆盖已装插件)", onChange: (v) => setOptions({ ...options, keepLocal: v }) }),
988
+ h(Switch, { checked: options.applyConfig, label: "安装后回填包内配置", onChange: (v) => setOptions({ ...options, applyConfig: v }) }),
989
+ h(Switch, { checked: options.enableBundles, label: "安装后直接启用(登记 bundle,重启后加载;默认关)", onChange: (v) => setOptions({ ...options, enableBundles: v }) }),
990
+ h(Switch, { checked: options.force, label: "忽略阻断(我知道自己在干什么)", onChange: (v) => setOptions({ ...options, force: v }) })),
991
+ h("div", { style: row },
992
+ h("button", { style: btnPrimary, disabled: busy !== "" || (source.kind === "url" ? !source.url.trim() : !source.file), onClick: inspect }, busy === "inspect" ? "检测中…" : "检测这个包"),
993
+ source.kind === "file" && source.file ? h("span", { style: hint }, "选中:" + source.file) : null)),
994
+ error ? h(Notice, { tone: "bad" }, error) : null,
995
+ preview ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
996
+ h("div", { style: row },
997
+ h("div", { style: strong }, preview.manifest.name),
998
+ h(Tag, null, FORMAT_TEXT[preview.manifest.format] || preview.manifest.format),
999
+ h(Tag, { color: preview.integrity && preview.integrity.ok ? "#2bb673" : "#ffb020" }, preview.integrity && preview.integrity.present ? (preview.integrity.ok ? "完整性通过" : "完整性有出入") : "无完整性清单"),
1000
+ h("span", { style: hint }, "生成于 " + when(preview.manifest.createdAt) + (preview.manifest.author ? " · " + preview.manifest.author : ""))),
1001
+ preview.manifest.description ? h("div", { style: label }, preview.manifest.description) : null,
1002
+ preview.blockingReasons && preview.blockingReasons.length
1003
+ ? h(Notice, { tone: "bad" }, h("b", null, "阻断:" ), preview.blockingReasons.join(";"), " (真要装,勾上面的「忽略阻断」)")
1004
+ : null,
1005
+ h("div", { style: { display: "flex", flexDirection: "column", gap: "2px" } },
1006
+ preview.manifest.plugins.map((p) => h("div", { key: p.name, style: mono },
1007
+ "· " + p.name + "@" + p.version + (p.localEdits ? " [含本机修改]" : "") + (p.configIncluded ? " [有配置]" : "") + (p.dataIncluded ? " [有数据快照]" : "")))),
1008
+ h(ScanReport, { scan: preview.scan, groups: preview.scanGroups }),
1009
+ h(CompatList, { compat: preview.compat }),
1010
+ preview.notes && preview.notes.length ? h("div", { style: hint }, preview.notes.map((n, i) => h("div", { key: i }, "· " + n))) : null,
1011
+ h("div", { style: row },
1012
+ h(Switch, { checked: options.dryRun, label: "只演练不落地", onChange: (v) => setOptions({ ...options, dryRun: v }) }),
1013
+ h("button", { style: btnPrimary, disabled: busy !== "", onClick: install }, busy === "install" ? "安装中…" : (options.dryRun ? "演练一次" : "安装这个整合包"))))
1014
+ : null,
1015
+ done ? h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1016
+ h("div", { style: row },
1017
+ h("div", { style: strong }, done.ok ? "安装完成" : "没有装成"),
1018
+ done.needsRestart ? h(Tag, { color: "#ffb020" }, "需要重启 DSH 生效") : null),
1019
+ done.error ? h("div", { style: { ...label, color: "#ff6b6b" } }, done.error) : null,
1020
+ (done.actions || []).map((a, i) => h("div", { key: i, style: { ...mono, color: a.ok ? "inherit" : "#ff6b6b" } },
1021
+ (a.ok ? "✓ " : "✗ ") + a.plugin + " · " + a.action + " · " + a.message)),
1022
+ (done.lines || []).length ? h("details", null, h("summary", { style: hint }, "命令输出(" + done.lines.length + " 行)"),
1023
+ h("pre", { style: { ...mono, maxHeight: "200px", overflow: "auto", whiteSpace: "pre-wrap" } }, done.lines.join("\n"))) : null,
1024
+ done.scan ? h(ScanReport, { scan: done.scan, groups: done.scanGroups }) : null)
1025
+ : null)
1026
+ }
1027
+
1028
+ // —— 设置与记录 ——
1029
+ function SettingsPanel(props) {
1030
+ const [cfg, setCfg] = useState(props.status ? props.status.config : null)
1031
+ const [saved, setSaved] = useState("")
1032
+ const [busy, setBusy] = useState(false)
1033
+ const [scanNag, fireScanNag] = useNag()
1034
+ const history = (props.status && props.status.history) || []
1035
+
1036
+ const patch = async (p) => {
1037
+ setBusy(true); setSaved("")
1038
+ try {
1039
+ const data = await api("/settings", { patch: p })
1040
+ if (data && data.ok) { setCfg(data.config); setSaved("已保存") }
1041
+ else setSaved((data && data.error) || "保存失败")
1042
+ } catch (e) {
1043
+ setSaved(e.message || String(e))
1044
+ } finally { setBusy(false) }
1045
+ }
1046
+ const setField = (key, value) => setCfg((prev) => ({ ...(prev || {}), [key]: value }))
1047
+ // 显示位:先本地生效(不用等接口回来),再落盘
1048
+ const placementOn = {
1049
+ showInSettings: !!cfg && cfg.showInSettings !== false,
1050
+ showInSidebar: !!cfg && cfg.showInSidebar !== false,
1051
+ showInPluginsTab: !!cfg && cfg.showInPluginsTab === true,
1052
+ }
1053
+ const placementCount = (placementOn.showInSettings ? 1 : 0) + (placementOn.showInSidebar ? 1 : 0) + (placementOn.showInPluginsTab ? 1 : 0)
1054
+ // 只剩一处开着时,这一处锁死:点了只会提示,不能让三处全关
1055
+ const placementLocked = (key) => placementCount <= 1 && placementOn[key] === true
1056
+ const savePlacement = async (key, value) => {
1057
+ const next = { ...(cfg || {}), [key]: value }
1058
+ const want = {
1059
+ settings: next.showInSettings !== false,
1060
+ sidebar: next.showInSidebar !== false,
1061
+ pluginsTab: next.showInPluginsTab === true,
1062
+ }
1063
+ if (!want.settings && !want.sidebar && !want.pluginsTab) { setSaved("三处至少留一处,最后剩的那个不能关"); return }
1064
+ setCfg(next)
1065
+ setPlacement(want)
1066
+ setBusy(true)
1067
+ try {
1068
+ const data = await api("/settings", { patch: { [key]: value } })
1069
+ if (data && data.ok) { setCfg(data.config); setSaved("已保存") } else setSaved((data && data.error) || "保存失败")
1070
+ } catch (e) {
1071
+ setSaved(e.message || String(e))
1072
+ } finally { setBusy(false) }
1073
+ }
1074
+ if (!cfg) return h("div", { style: hint }, "设置读取中…")
1075
+
1076
+ const textList = (key) => (Array.isArray(cfg[key]) ? cfg[key].join("\n") : "")
1077
+
1078
+ return h("div", { style: { display: "flex", flexDirection: "column", gap: "14px" } },
1079
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "10px" } },
1080
+ h("div", { style: strong }, "扫描与安装策略"),
1081
+ h("div", { style: row },
1082
+ h(ForcedSwitch, { label: "打包前扫描(强制)", onNag: () => fireScanNag("你想干什么") }),
1083
+ h(Switch, { checked: cfg.scanBeforeInstall !== false, label: "安装前扫描", onChange: (v) => { setField("scanBeforeInstall", v); patch({ scanBeforeInstall: v }) } }),
1084
+ h(Switch, { checked: cfg.blockHighRisk !== false, label: "高风险直接拒绝", onChange: (v) => { setField("blockHighRisk", v); patch({ blockHighRisk: v }) } }),
1085
+ h(Switch, { checked: cfg.applyPackedConfig !== false, label: "默认回填配置", onChange: (v) => { setField("applyPackedConfig", v); patch({ applyPackedConfig: v }) } }),
1086
+ h(Switch, { checked: cfg.enableOnInstall === true, label: "装完直接启用(默认关)", onChange: (v) => { setField("enableOnInstall", v); patch({ enableOnInstall: v }) } })),
1087
+ h(NagText, { text: scanNag }),
1088
+ h("div", { style: hint }, "扫描只看代码与文本,不执行任何东西;命中原文不会落盘,也不进日志。"),
1089
+ h("div", { style: row },
1090
+ h("span", { style: label }, "体积上限(MB)"),
1091
+ h("input", { style: { ...input, width: "90px" }, type: "number", min: "1", value: Math.round((cfg.maxPackBytes || 0) / 1048576), onChange: (e) => setField("maxPackBytes", Number(e.target.value) * 1048576) }),
1092
+ h("button", { style: btn, disabled: busy, onClick: () => patch({ maxPackBytes: cfg.maxPackBytes, maxDownloadBytes: cfg.maxDownloadBytes, maxFileBytes: cfg.maxFileBytes, licenseAllow: cfg.licenseAllow, registries: cfg.registries, allowHosts: cfg.allowHosts }) }, "保存数值"),
1093
+ saved ? h("span", { style: hint }, saved) : null)),
1094
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1095
+ h("div", { style: strong }, "信任清单"),
1096
+ h("div", { style: hint }, "允许的许可证(一行一个,例如 MIT):"),
1097
+ h("textarea", { style: { ...input, height: "62px", padding: "6px 8px", width: "100%", resize: "vertical" }, value: textList("licenseAllow"), onChange: (e) => setField("licenseAllow", e.target.value.split("\n")) }),
1098
+ h("div", { style: hint }, "允许的下载域名(一行一个,只走 https):"),
1099
+ h("textarea", { style: { ...input, height: "62px", padding: "6px 8px", width: "100%", resize: "vertical" }, value: textList("allowHosts"), onChange: (e) => setField("allowHosts", e.target.value.split("\n")) }),
1100
+ h("div", { style: hint }, "npm 源(按顺序回退):"),
1101
+ h("textarea", { style: { ...input, height: "62px", padding: "6px 8px", width: "100%", resize: "vertical" }, value: textList("registries"), onChange: (e) => setField("registries", e.target.value.split("\n")) }),
1102
+ h("div", { style: row },
1103
+ h("button", { style: btn, disabled: busy, onClick: () => patch({ licenseAllow: cfg.licenseAllow.filter(Boolean), allowHosts: cfg.allowHosts.filter(Boolean), registries: cfg.registries.filter(Boolean) }) }, "保存清单"))),
1104
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1105
+ h("div", { style: strong }, "位置"),
1106
+ h("div", { style: mono }, "profile:" + ((props.status && props.status.paths && props.status.paths.profile) || "?")),
1107
+ h("div", { style: mono }, "整合包:" + ((props.status && props.status.paths && props.status.paths.packs) || "?")),
1108
+ h("div", { style: mono }, "缓存与暂存:" + ((props.status && props.status.paths && props.status.paths.vendor) || "?")),
1109
+ h("div", { style: mono }, "卸载临时文件:删掉 vendor 目录即可,装好的插件不受影响。")),
1110
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "6px" } },
1111
+ h("div", { style: strong }, "最近记录"),
1112
+ history.length === 0 ? h("div", { style: hint }, "还没有记录。") : history.map((item, i) => h("div", { key: i, style: { ...mono, borderTop: "0.5px solid var(--dsw-alias-border-l2)", paddingTop: "4px" } },
1113
+ "[" + (item.kind || "?") + "] " + (item.name || item.pack || "") + " · " + when(item.at) + (item.size ? " · " + bytes(item.size) : "") + (item.ok === false ? " · 失败" : "")))),
1114
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1115
+ h("div", { style: strong }, "显示位置"),
1116
+ h("div", { style: hint }, "三处互相独立,一点就生效,不用重启。关掉只是不挂载入口,功能与接口都还在。至少留一处:只剩一个时,那个开关会变灰、点不动。"),
1117
+ h("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } },
1118
+ h(Switch, { checked: cfg.showInSettings !== false, disabled: placementLocked("showInSettings"), label: "在设置里显示(插件设置页内一栏「整合包」)" + (placementLocked("showInSettings") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSettings", v) }),
1119
+ h(Switch, { checked: cfg.showInSidebar !== false, disabled: placementLocked("showInSidebar"), label: "在侧边栏显示(左侧栏「整合包」入口)" + (placementLocked("showInSidebar") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInSidebar", v) }),
1120
+ h(Switch, { checked: cfg.showInPluginsTab === true, disabled: placementLocked("showInPluginsTab"), label: "在插件页内显示(与插件市场同一位置,单开一栏「整合包」)" + (placementLocked("showInPluginsTab") ? "(最后剩这一个,不能关)" : ""), onChange: (v) => savePlacement("showInPluginsTab", v) })),
1121
+ saved ? h("span", { style: hint }, saved) : null),
1122
+ h("div", { style: { ...box, display: "flex", flexDirection: "column", gap: "8px" } },
1123
+ h("div", { style: strong }, "插件目录(分类 · 搜索 · 分页)"),
1124
+ h("div", { style: hint }, (() => {
1125
+ const c = props.status && props.status.catalog
1126
+ if (!c || !c.present) return "本地还没有目录索引;要按分类找插件、要搜索时,先在这里或打包页建一次。"
1127
+ return "本地索引:" + c.count + " 条 · 来源 " + (c.sourceLabel || c.source || "?") + " · 建于 " + when(c.builtAt) + (c.stale ? "(偏旧了,建议更新)" : "")
1128
+ })()),
1129
+ h("div", { style: row },
1130
+ h("span", { style: label }, "每页条数"),
1131
+ h("input", { style: { ...input, width: "78px" }, type: "number", min: "5", max: "100", value: cfg.catalogPageSize || 20, onChange: (e) => setField("catalogPageSize", Number(e.target.value)) }),
1132
+ h("span", { style: label }, "自动更新(小时)"),
1133
+ h("input", { style: { ...input, width: "78px" }, type: "number", min: "1", max: "168", value: cfg.catalogRefreshHours || 24, onChange: (e) => setField("catalogRefreshHours", Number(e.target.value)) }),
1134
+ h("button", { style: btn, disabled: busy, onClick: () => patch({ catalogPageSize: cfg.catalogPageSize, catalogRefreshHours: cfg.catalogRefreshHours }) }, "保存目录设置")),
1135
+ h("div", { style: hint }, "目录就是插件市场自己发布的那份 dsh-plugin-catalog:CDN 优先,失败退回 npm 包。分类与词条都照它来,本插件不另造一套。"))
1136
+ )
1137
+ }
1138
+
1139
+ function Home(props) {
1140
+ const [tab, setTab] = useState("pack")
1141
+ const jobs = useJobs()
1142
+ const status = props.status
1143
+ const [packResult, setPackResult] = useState(() => readPackValue())
1144
+ const [focus, setFocus] = useState(0)
1145
+ useEffect(() => subscribePack((value) => { setPackResult(value) }), [])
1146
+ const savePackResult = (value) => {
1147
+ setPackValue(value)
1148
+ setPackResult(value)
1149
+ }
1150
+ // 进度窗里点「下载安装包」→ 切到打包页、把那次的结果放进去、滚到下载那一块
1151
+ const openResult = (job) => {
1152
+ const payload = job && job.data ? job.data : null
1153
+ if (!payload) return
1154
+ savePackResult(payload)
1155
+ setTab("pack")
1156
+ setFocus((n) => n + 1)
1157
+ }
1158
+ const tabs = [
1159
+ ["pack", "打包"],
1160
+ ["install", "安装 / 导入"],
1161
+ ["settings", "设置与记录"],
1162
+ ]
1163
+ const tabBtn = (key, text) => h("button", {
1164
+ key,
1165
+ onClick: () => setTab(key),
1166
+ style: {
1167
+ ...btn,
1168
+ borderColor: tab === key ? "transparent" : "var(--dsw-alias-border-l2)",
1169
+ background: tab === key ? "var(--dsw-alias-fill-primary, #3b6cf6)" : "transparent",
1170
+ color: tab === key ? "#fff" : "var(--dsw-alias-label-primary)",
1171
+ },
1172
+ }, text)
1173
+
1174
+ return h("div", { style: { height: "100%", overflow: "auto", boxSizing: "border-box", padding: "22px 26px 44px", color: "var(--dsw-alias-label-primary)" } },
1175
+ h("div", { style: { maxWidth: "1020px", margin: "0 auto", display: "flex", flexDirection: "column", gap: "14px" } },
1176
+ h("div", { style: { display: "flex", alignItems: "baseline", gap: "10px", flexWrap: "wrap" } },
1177
+ h("h2", { style: { margin: 0, fontSize: "20px", fontWeight: 600 } }, "整合包"),
1178
+ h("span", { style: hint }, "把多个插件打成一个 .dshpack:完整版自带本体,轻量版联网取包")),
1179
+ h("div", { style: row }, tabs.map(([key, text]) => tabBtn(key, text)),
1180
+ h("span", { style: { ...hint, marginLeft: "auto" } },
1181
+ status ? ("DSH " + (status.dshVersion || "?") + " · 已装 " + ((status.installed || []).length) + " 个 · v" + (status.pluginVersion || "?")) : "读取环境…")),
1182
+ tab === "pack" ? h(PackPanel, { status, jobs, result: packResult, setResult: savePackResult, focus }) : null,
1183
+ tab === "install" ? h(InstallPanel, { status }) : null,
1184
+ tab === "settings" ? h(SettingsPanel, { status }) : null,
1185
+ h("div", { style: hint }, "说明:整合包只打包你选择的插件与必要配置。打包与安装安全检测在内存中进行,命中原文不落盘;请遵守插件作者许可证与你所在地区的法律法规。")),
1186
+ h(JobDock, { jobs, onOpenResult: openResult })
1187
+ )
1188
+ }
1189
+
1190
+ function Icon(props) {
1191
+ const size = (props && props.size) || 16
1192
+ return h("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
1193
+ h("path", { d: "M2.2 5.2 8 2.3l5.8 2.9v5.6L8 13.7l-5.8-2.9z" }),
1194
+ h("path", { d: "M2.2 5.2 8 8.1l5.8-2.9M8 8.1v5.6" }))
1195
+ }
1196
+
1197
+ /** 用一个小组件包住面板,进入时拉一次状态,之后交给子面板。 */
1198
+ function Page(props) {
1199
+ const [status, setStatus] = useState(null)
1200
+ const [error, setError] = useState("")
1201
+ const reload = useCallback(async () => {
1202
+ try {
1203
+ const data = await api("/status")
1204
+ if (data && data.ok) {
1205
+ setStatus(data)
1206
+ setError("")
1207
+ if (data.placements) setPlacement(data.placements)
1208
+ } else setError((data && data.error) || "读取状态失败")
1209
+ } catch (e) { setError(String((e && e.message) || e)) }
1210
+ }, [])
1211
+ useEffect(() => { reload() }, [reload])
1212
+ if (error) return h("div", { style: { padding: "24px", color: "#ff6b6b", fontSize: "13px" } }, "整合包没起来:" + error)
1213
+ if (!status) return h("div", { style: { padding: "24px", color: "var(--dsw-alias-label-tertiary)", fontSize: "13px" } }, "整合包:读取环境…")
1214
+ return h(Home, { status, surface: (props && props.surface) || "sidebar" })
1215
+ }
1216
+
1217
+ const inject = ["slots"]
1218
+
1219
+ // 三处显示位各自注册什么。开关一翻就整组挂上 / 整组撤掉,不动别的插件。
1220
+ const PLACEMENT_MOUNTS = {
1221
+ settings: () => [
1222
+ { slot: "settings.section", spec: { name: "settings.section", id: "dsh-modpack-kit", order: 45, label: () => "整合包" }, Comp: () => h(Page, { surface: "settings" }) },
1223
+ { slot: "settings.plugins.tab", spec: { name: "settings.plugins.tab", id: "dsh-modpack-kit", order: 70, label: () => "整合包" }, Comp: () => h(Page, { surface: "plugins" }) },
1224
+ ],
1225
+ pluginsTab: () => [
1226
+ { slot: "plugins.tab", spec: { name: "plugins.tab", id: "dsh-modpack-kit", order: 1, label: () => "整合包" }, Comp: () => h(Page, { surface: "plugins" }) },
1227
+ ],
1228
+ sidebar: () => [
1229
+ { slot: "sidebar.panellist", spec: { name: "sidebar.panellist", id: "dsh-modpack-kit", order: 60, label: () => "整合包" }, Comp: Icon },
1230
+ { slot: "main", spec: { name: "main", key: "dsh-modpack-kit" }, Comp: () => h(Page, { surface: "sidebar" }) },
1231
+ ],
1232
+ }
1233
+
1234
+ function apply(ctx) {
1235
+ const mounted = new Map()
1236
+ const mount = (group, item) => {
1237
+ const key = group + ":" + item.slot
1238
+ if (mounted.has(key)) return
1239
+ try {
1240
+ const off = ctx.slots.inject(item.slot, () => ctx.slots.register(item.spec, item.Comp))
1241
+ mounted.set(key, typeof off === "function" ? off : () => {})
1242
+ } catch (e) {
1243
+ // 某个宿主版本没有这个槽位时跳过,别的显示位照常
1244
+ }
1245
+ }
1246
+ const unmount = (key) => {
1247
+ const off = mounted.get(key)
1248
+ if (!off) return
1249
+ mounted.delete(key)
1250
+ try { off() } catch {}
1251
+ }
1252
+ const sync = (value) => {
1253
+ const want = normalizePlacement(value)
1254
+ for (const group of Object.keys(PLACEMENT_MOUNTS)) {
1255
+ const items = PLACEMENT_MOUNTS[group]()
1256
+ if (want[group]) for (const item of items) mount(group, item)
1257
+ else for (const item of items) unmount(group + ":" + item.slot)
1258
+ }
1259
+ }
1260
+ ctx.effect(() => {
1261
+ const unsubscribe = subscribePlacement(sync)
1262
+ sync(placement.value)
1263
+ return () => { unsubscribe(); for (const key of [...mounted.keys()]) unmount(key) }
1264
+ }, "dsh-modpack-kit: 三处显示位")
1265
+ }
1266
+
1267
+ exports.apply = apply
1268
+ exports.inject = inject
1269
+ exports.Page = Page
1270
+ exports.Home = Home
1271
+ exports.Icon = Icon
1272
+
1273
+ return module.exports
1274
+ },
1275
+ })