@snap-rail/ui 0.0.0-stage → 0.1.1

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.
Files changed (62) hide show
  1. package/LICENSE +202 -0
  2. package/lib/charts.js +118 -0
  3. package/lib/contract.js +527 -0
  4. package/lib/fallback.js +399 -0
  5. package/lib/index.js +1282 -0
  6. package/lib/pages.js +68 -0
  7. package/lib/runtime.js +3003 -0
  8. package/lib/settings.js +2069 -0
  9. package/lib/skins.js +258 -0
  10. package/lib/slots.js +267 -0
  11. package/lib/types/charts.d.ts +62 -0
  12. package/lib/types/charts.js +41 -0
  13. package/lib/types/components/button.d.ts +39 -0
  14. package/lib/types/components/button.js +27 -0
  15. package/lib/types/components/controls.d.ts +66 -0
  16. package/lib/types/components/controls.js +66 -0
  17. package/lib/types/components/dialog.d.ts +58 -0
  18. package/lib/types/components/dialog.js +46 -0
  19. package/lib/types/components/feedback.d.ts +46 -0
  20. package/lib/types/components/feedback.js +20 -0
  21. package/lib/types/components/form.d.ts +31 -0
  22. package/lib/types/components/form.js +13 -0
  23. package/lib/types/components/index.d.ts +15 -0
  24. package/lib/types/components/index.js +15 -0
  25. package/lib/types/components/input.d.ts +40 -0
  26. package/lib/types/components/input.js +18 -0
  27. package/lib/types/components/layout.d.ts +103 -0
  28. package/lib/types/components/layout.js +80 -0
  29. package/lib/types/components/schema-form.d.ts +44 -0
  30. package/lib/types/components/schema-form.js +84 -0
  31. package/lib/types/components/surface.d.ts +49 -0
  32. package/lib/types/components/surface.js +59 -0
  33. package/lib/types/contract.d.ts +350 -0
  34. package/lib/types/contract.js +231 -0
  35. package/lib/types/fallback.d.ts +14 -0
  36. package/lib/types/fallback.js +50 -0
  37. package/lib/types/index.d.ts +19 -0
  38. package/lib/types/index.js +19 -0
  39. package/lib/types/pages.d.ts +40 -0
  40. package/lib/types/pages.js +69 -0
  41. package/lib/types/runtime.d.ts +93 -0
  42. package/lib/types/runtime.js +233 -0
  43. package/lib/types/settings-pages/appearance.d.ts +15 -0
  44. package/lib/types/settings-pages/appearance.js +128 -0
  45. package/lib/types/settings-pages/index.d.ts +3 -0
  46. package/lib/types/settings-pages/index.js +3 -0
  47. package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
  48. package/lib/types/settings-pages/plugin-feed.js +66 -0
  49. package/lib/types/settings-pages/plugins.d.ts +21 -0
  50. package/lib/types/settings-pages/plugins.js +372 -0
  51. package/lib/types/settings.d.ts +59 -0
  52. package/lib/types/settings.js +176 -0
  53. package/lib/types/skins.d.ts +137 -0
  54. package/lib/types/skins.js +271 -0
  55. package/lib/types/slots.d.ts +69 -0
  56. package/lib/types/slots.js +210 -0
  57. package/lib/types/utils.d.ts +15 -0
  58. package/lib/types/utils.js +26 -0
  59. package/package.json +105 -3
  60. package/src/styles/base.css +329 -0
  61. package/src/styles/default.css +735 -0
  62. package/README.md +0 -3
package/lib/index.js ADDED
@@ -0,0 +1,1282 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { rpcErrorText } from "@snap-rail/connection";
3
+ import { useEffect, useState } from "react";
4
+ import { Slot } from "@radix-ui/react-slot";
5
+ import "@radix-ui/react-checkbox";
6
+ import "@radix-ui/react-label";
7
+ import "@radix-ui/react-radio-group";
8
+ import "@radix-ui/react-select";
9
+ import * as SwitchPrimitive from "@radix-ui/react-switch";
10
+ import "@radix-ui/react-tabs";
11
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
12
+ //#region lib/types/utils.js
13
+ /**
14
+ * Small helpers shared by the headless semantic components: class merging and
15
+ * the stable `data-snap-*` anatomy that skins target.
16
+ *
17
+ * @module @snap-rail/ui/utils
18
+ */
19
+ /** Join truthy class names. */
20
+ function cn(...values) {
21
+ return values.filter((value) => typeof value === "string" && value.length > 0).join(" ");
22
+ }
23
+ /** The anatomy attributes every semantic component renders. */
24
+ function part(component, name) {
25
+ return {
26
+ "data-snap-component": component,
27
+ "data-snap-part": `${component}.${name}`
28
+ };
29
+ }
30
+ /** Map a semantic spacing token to a CSS variable. */
31
+ function space(token) {
32
+ return `var(--snap-space-${token})`;
33
+ }
34
+ //#endregion
35
+ //#region lib/types/components/button.js
36
+ /**
37
+ * Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
38
+ * `button.root`, `button.label`, `button.icon`, and `button.spinner` parts;
39
+ * intent/emphasis/size are data attributes a skin styles.
40
+ *
41
+ * @module @snap-rail/ui/components/button
42
+ */
43
+ /** A spinner that inherits the current text colour. */
44
+ function Spinner(props) {
45
+ return jsxs("svg", {
46
+ ...part("button", "spinner"),
47
+ className: cn("snap-spinner", props.className),
48
+ viewBox: "0 0 24 24",
49
+ "aria-hidden": "true",
50
+ children: [jsx("circle", {
51
+ cx: "12",
52
+ cy: "12",
53
+ r: "9",
54
+ fill: "none",
55
+ stroke: "currentColor",
56
+ strokeWidth: "3",
57
+ opacity: "0.25"
58
+ }), jsx("path", {
59
+ d: "M21 12a9 9 0 0 0-9-9",
60
+ fill: "none",
61
+ stroke: "currentColor",
62
+ strokeWidth: "3",
63
+ strokeLinecap: "round"
64
+ })]
65
+ });
66
+ }
67
+ /** A themed button; `asChild` composes the behaviour onto a child element. */
68
+ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading = false, icon, iconPosition = "start", asChild = false, disabled, className, children, type, ...props }) {
69
+ const Component = asChild ? Slot : "button";
70
+ const content = asChild ? children : jsxs(Fragment, { children: [
71
+ icon !== void 0 && iconPosition === "start" && jsx("span", {
72
+ ...part("button", "icon"),
73
+ children: icon
74
+ }),
75
+ children !== void 0 && jsx("span", {
76
+ ...part("button", "label"),
77
+ children
78
+ }),
79
+ icon !== void 0 && iconPosition === "end" && jsx("span", {
80
+ ...part("button", "icon"),
81
+ children: icon
82
+ }),
83
+ loading && jsx(Spinner, {})
84
+ ] });
85
+ return jsx(Component, {
86
+ ...part("button", "root"),
87
+ ...type !== void 0 ? { type } : !asChild ? { type: "button" } : {},
88
+ className: cn("snap-button", className),
89
+ "data-intent": intent,
90
+ "data-emphasis": emphasis,
91
+ "data-size": size,
92
+ "data-loading": loading || void 0,
93
+ "data-disabled": disabled === true || void 0,
94
+ "aria-busy": loading || void 0,
95
+ disabled: !asChild ? disabled === true || loading : void 0,
96
+ ...props,
97
+ children: content
98
+ });
99
+ }
100
+ /** A square glyph button with a mandatory accessible label. */
101
+ function IconButton({ icon, label, active = false, intent = "neutral", emphasis = "ghost", size = "md", className, ...props }) {
102
+ return jsx("button", {
103
+ ...part("icon-button", "root"),
104
+ type: "button",
105
+ className: cn("snap-icon-button", className),
106
+ "data-intent": intent,
107
+ "data-emphasis": emphasis,
108
+ "data-size": size,
109
+ "data-active": active || void 0,
110
+ "aria-label": label,
111
+ "aria-pressed": active || void 0,
112
+ ...props,
113
+ children: jsx("span", {
114
+ ...part("icon-button", "icon"),
115
+ "aria-hidden": "true",
116
+ children: icon
117
+ })
118
+ });
119
+ }
120
+ //#endregion
121
+ //#region lib/types/components/dialog.js
122
+ /**
123
+ * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
124
+ * the presentation (modal, sheet, fullscreen) through the `presentation`
125
+ * attribute; the core owns dismissal and focus behaviour.
126
+ *
127
+ * @module @snap-rail/ui/components/dialog
128
+ */
129
+ /** The dialog root. */
130
+ const Dialog = DialogPrimitive.Root;
131
+ /** The portalled dialog content. */
132
+ function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
133
+ const resolved = presentation === "auto" ? "modal" : presentation;
134
+ return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
135
+ ...part("dialog", "overlay"),
136
+ className: "snap-dialog-overlay"
137
+ }), jsxs(DialogPrimitive.Content, {
138
+ ...part("dialog", "panel"),
139
+ className: cn("snap-dialog-panel", className),
140
+ "data-presentation": resolved,
141
+ "data-size": size,
142
+ ...rest,
143
+ children: [children, showClose && jsx(DialogPrimitive.Close, {
144
+ ...part("dialog", "close"),
145
+ className: "snap-dialog-close",
146
+ "aria-label": "关闭",
147
+ children: "×"
148
+ })]
149
+ })] });
150
+ }
151
+ /** The dialog header. */
152
+ function DialogHeader({ children, className }) {
153
+ return jsx("div", {
154
+ ...part("dialog", "header"),
155
+ className: cn("snap-dialog-header", className),
156
+ children
157
+ });
158
+ }
159
+ /** The dialog title. */
160
+ function DialogTitle({ children, className }) {
161
+ return jsx(DialogPrimitive.Title, {
162
+ ...part("dialog", "title"),
163
+ className: cn("snap-dialog-title", className),
164
+ children
165
+ });
166
+ }
167
+ /** The dialog description. */
168
+ function DialogDescription({ children, className }) {
169
+ return jsx(DialogPrimitive.Description, {
170
+ ...part("dialog", "description"),
171
+ className: cn("snap-dialog-description", className),
172
+ children
173
+ });
174
+ }
175
+ /** The dialog body. */
176
+ function DialogBody({ children, className }) {
177
+ return jsx("div", {
178
+ ...part("dialog", "body"),
179
+ className: cn("snap-dialog-body", className),
180
+ children
181
+ });
182
+ }
183
+ /** The dialog footer. */
184
+ function DialogFooter({ children, className }) {
185
+ return jsx("div", {
186
+ ...part("dialog", "footer"),
187
+ className: cn("snap-dialog-footer", className),
188
+ children
189
+ });
190
+ }
191
+ //#endregion
192
+ //#region lib/types/components/controls.js
193
+ /** A boolean switch. */
194
+ function Switch({ className, label, ...props }) {
195
+ return jsxs("label", {
196
+ className: "snap-switch-label",
197
+ children: [jsx(SwitchPrimitive.Root, {
198
+ ...part("switch", "root"),
199
+ className: cn("snap-switch", className),
200
+ ...props,
201
+ children: jsx(SwitchPrimitive.Thumb, {
202
+ ...part("switch", "thumb"),
203
+ className: "snap-switch-thumb"
204
+ })
205
+ }), label !== void 0 && jsx("span", {
206
+ ...part("switch", "label"),
207
+ children: label
208
+ })]
209
+ });
210
+ }
211
+ //#endregion
212
+ //#region lib/types/components/feedback.js
213
+ /** A compact status/count label. */
214
+ function Badge({ children, intent = "neutral", className }) {
215
+ return jsx("span", {
216
+ ...part("badge", "root"),
217
+ className: cn("snap-badge", className),
218
+ "data-intent": intent,
219
+ children
220
+ });
221
+ }
222
+ /** A centered empty/zero-state block. */
223
+ function EmptyState({ title, description, icon, action, className }) {
224
+ return jsxs("div", {
225
+ ...part("empty-state", "root"),
226
+ className: cn("snap-empty-state", className),
227
+ children: [
228
+ icon !== void 0 && jsx("div", {
229
+ ...part("empty-state", "icon"),
230
+ children: icon
231
+ }),
232
+ jsx("div", {
233
+ ...part("empty-state", "title"),
234
+ children: title
235
+ }),
236
+ description !== void 0 && jsx("div", {
237
+ ...part("empty-state", "description"),
238
+ children: description
239
+ }),
240
+ action !== void 0 && jsx("div", {
241
+ ...part("empty-state", "action"),
242
+ children: action
243
+ })
244
+ ]
245
+ });
246
+ }
247
+ //#endregion
248
+ //#region lib/types/components/input.js
249
+ /** A single-line text field with semantic prefix/suffix slots. Layout
250
+ * `style`/`className` dress the wrapper — the visible control; the native
251
+ * field already stretches inside it. */
252
+ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, style, disabled, ...props }) {
253
+ return jsxs("div", {
254
+ ...part(componentName, "root"),
255
+ className: cn("snap-input", className),
256
+ style,
257
+ "data-size": size,
258
+ "data-invalid": invalid || void 0,
259
+ "data-disabled": disabled === true || void 0,
260
+ children: [
261
+ prefix !== void 0 && jsx("span", {
262
+ ...part(componentName, "prefix"),
263
+ children: prefix
264
+ }),
265
+ jsx("input", {
266
+ ...part(componentName, "field"),
267
+ className: "snap-input-field",
268
+ disabled,
269
+ "aria-invalid": invalid || void 0,
270
+ ...props
271
+ }),
272
+ onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
273
+ ...part(componentName, "clear"),
274
+ type: "button",
275
+ className: "snap-input-clear",
276
+ "aria-label": "清除",
277
+ onClick: onClear,
278
+ children: "×"
279
+ }),
280
+ suffix !== void 0 && jsx("span", {
281
+ ...part(componentName, "suffix"),
282
+ children: suffix
283
+ })
284
+ ]
285
+ });
286
+ }
287
+ //#endregion
288
+ //#region lib/types/components/layout.js
289
+ /** A vertical flow. */
290
+ function Stack({ gap = "md", padding, align, className, style, children }) {
291
+ return jsx("div", {
292
+ ...part("stack", "root"),
293
+ className: cn("snap-stack", className),
294
+ style: {
295
+ display: "flex",
296
+ flexDirection: "column",
297
+ gap: space(gap),
298
+ ...padding !== void 0 ? { padding: space(padding) } : {},
299
+ ...align !== void 0 ? { alignItems: align } : {},
300
+ ...style
301
+ },
302
+ children
303
+ });
304
+ }
305
+ /** A page body with its own header/actions anatomy. */
306
+ function Page({ header, actions, title, titleExtra, description, className, style, children }) {
307
+ return jsxs("div", {
308
+ ...part("page", "root"),
309
+ className: cn("snap-page", className),
310
+ style: {
311
+ display: "flex",
312
+ flexDirection: "column",
313
+ minHeight: 0,
314
+ ...style
315
+ },
316
+ children: [(header !== void 0 || title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("div", {
317
+ ...part("page", "header"),
318
+ style: {
319
+ display: "flex",
320
+ flexDirection: "column",
321
+ gap: space("sm"),
322
+ flexShrink: 0
323
+ },
324
+ children: [
325
+ jsxs("div", {
326
+ style: {
327
+ display: "flex",
328
+ alignItems: "flex-start",
329
+ justifyContent: "space-between",
330
+ gap: space("md")
331
+ },
332
+ children: [jsxs("div", {
333
+ style: {
334
+ display: "flex",
335
+ alignItems: "center",
336
+ gap: space("sm")
337
+ },
338
+ children: [title !== void 0 && jsx("div", {
339
+ ...part("page", "title"),
340
+ children: title
341
+ }), titleExtra !== void 0 && jsx("div", {
342
+ ...part("page", "title-extra"),
343
+ children: titleExtra
344
+ })]
345
+ }), actions !== void 0 && jsx("div", {
346
+ ...part("page", "actions"),
347
+ children: actions
348
+ })]
349
+ }),
350
+ description !== void 0 && jsx("div", {
351
+ ...part("page", "description"),
352
+ children: description
353
+ }),
354
+ header
355
+ ]
356
+ }), jsx("div", {
357
+ ...part("page", "body"),
358
+ style: {
359
+ display: "flex",
360
+ flexDirection: "column",
361
+ flex: 1,
362
+ minHeight: 0
363
+ },
364
+ children
365
+ })]
366
+ });
367
+ }
368
+ //#endregion
369
+ //#region lib/types/components/surface.js
370
+ /** A semantic table. */
371
+ function Table({ className, children, ...props }) {
372
+ return jsx("div", {
373
+ ...part("table", "root"),
374
+ className: cn("snap-table", className),
375
+ children: jsx("table", {
376
+ ...props,
377
+ children
378
+ })
379
+ });
380
+ }
381
+ /** The table head. */
382
+ function TableHeader({ className, children, ...props }) {
383
+ return jsx("thead", {
384
+ ...part("table", "header"),
385
+ className: cn("snap-table-header", className),
386
+ ...props,
387
+ children
388
+ });
389
+ }
390
+ /** The table body. */
391
+ function TableBody({ className, children, ...props }) {
392
+ return jsx("tbody", {
393
+ ...part("table", "body"),
394
+ className: cn("snap-table-body", className),
395
+ ...props,
396
+ children
397
+ });
398
+ }
399
+ /** A table row. */
400
+ function TableRow({ className, children, ...props }) {
401
+ return jsx("tr", {
402
+ ...part("table", "row"),
403
+ className: cn("snap-table-row", className),
404
+ ...props,
405
+ children
406
+ });
407
+ }
408
+ /** A table header cell. */
409
+ function TableHead({ className, children, ...props }) {
410
+ return jsx("th", {
411
+ ...part("table", "head"),
412
+ className: cn("snap-table-head", className),
413
+ ...props,
414
+ children
415
+ });
416
+ }
417
+ /** A table body cell. */
418
+ function TableCell({ className, children, ...props }) {
419
+ return jsx("td", {
420
+ ...part("table", "cell"),
421
+ className: cn("snap-table-cell", className),
422
+ ...props,
423
+ children
424
+ });
425
+ }
426
+ //#endregion
427
+ //#region lib/types/settings-pages/plugins.js
428
+ /** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
429
+ * Electron or in tests. Inlined rather than imported from the app-internal
430
+ * kernel package: it never ships in the installer, and the packaged-app gate
431
+ * refuses any shipped `@snap-rail/ui` lib that requires it. */
432
+ function droppedZipPath(file) {
433
+ const zipPathOf = globalThis.snapRail?.zipPathOf;
434
+ if (typeof zipPathOf !== "function") return null;
435
+ return zipPathOf(file);
436
+ }
437
+ /** Human labels for the package kinds. */
438
+ const KIND_LABELS = {
439
+ skin: "界面风格",
440
+ driver: "通讯驱动",
441
+ suite: "业务套件",
442
+ plugin: "插件"
443
+ };
444
+ const PROFILE_LABELS = {
445
+ native: "皮肤原生",
446
+ integrated: "图表桥接",
447
+ custom: "自定义界面"
448
+ };
449
+ /** Search rows shown before the tail is folded into a counter. */
450
+ const SEARCH_ROW_CAP = 20;
451
+ /** The plus glyph for the page's install entry. */
452
+ function PlusIcon() {
453
+ return jsx("svg", {
454
+ viewBox: "0 0 24 24",
455
+ width: "18",
456
+ height: "18",
457
+ fill: "none",
458
+ stroke: "currentColor",
459
+ strokeWidth: "2.4",
460
+ strokeLinecap: "round",
461
+ "aria-hidden": "true",
462
+ children: jsx("path", { d: "M12 5v14M5 12h14" })
463
+ });
464
+ }
465
+ /** Collapse entry rows into package rows (one master switch per package). */
466
+ function packageRows(plugins) {
467
+ const byPackage = /* @__PURE__ */ new Map();
468
+ for (const plugin of plugins) {
469
+ if (plugin.source === "builtin") continue;
470
+ const existing = byPackage.get(plugin.packageName);
471
+ if (existing !== void 0) {
472
+ existing.enabled = existing.enabled || plugin.enabled;
473
+ continue;
474
+ }
475
+ byPackage.set(plugin.packageName, {
476
+ packageName: plugin.packageName,
477
+ title: plugin.title ?? plugin.packageName,
478
+ category: plugin.category ?? "其他",
479
+ kind: plugin.kind ?? "plugin",
480
+ ...plugin.version !== void 0 ? { version: plugin.version } : {},
481
+ enabled: plugin.enabled,
482
+ source: plugin.source,
483
+ builtinDefault: plugin.source === "builtin-default",
484
+ clientOnly: plugin.clientOnly === true,
485
+ ...plugin.uiProfile !== void 0 ? { uiProfile: plugin.uiProfile } : {}
486
+ });
487
+ }
488
+ return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
489
+ }
490
+ /** The preview's signature line (one row in the confirm card). */
491
+ function signatureText(signature, viaUrl) {
492
+ if (signature.state === "verified") return {
493
+ text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
494
+ warning: false
495
+ };
496
+ const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
497
+ return {
498
+ text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
499
+ warning: true
500
+ };
501
+ }
502
+ /** Does the input name an http(s) address? */
503
+ const isHttpUrl = (text) => /^https?:\/\//i.test(text);
504
+ /** Does the input look like a filesystem path (drive letter, UNC, posix
505
+ * root, or a .zip name with a separator in it)? */
506
+ const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
507
+ /** The plugin management page. */
508
+ function PluginsPage({ ctx }) {
509
+ const [rows, setRows] = useState([]);
510
+ const [error, setError] = useState(void 0);
511
+ const [busy, setBusy] = useState(void 0);
512
+ const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
513
+ const [restartNeeded, setRestartNeeded] = useState(false);
514
+ const [installOpen, setInstallOpen] = useState(false);
515
+ const [phase, setPhase] = useState({ kind: "idle" });
516
+ const [message, setMessage] = useState(void 0);
517
+ const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
518
+ const [updatingName, setUpdatingName] = useState(void 0);
519
+ const [keyChange, setKeyChange] = useState(void 0);
520
+ const [query, setQuery] = useState("");
521
+ const [searchResults, setSearchResults] = useState(void 0);
522
+ const [searching, setSearching] = useState(false);
523
+ const [dragging, setDragging] = useState(false);
524
+ const link = ctx.client.link;
525
+ const load = () => {
526
+ setError(void 0);
527
+ link.call("plugins.list", {}).then((result) => {
528
+ if (!result.ok) {
529
+ setError(rpcErrorText(result.error));
530
+ return;
531
+ }
532
+ setRows(packageRows(result.value.plugins));
533
+ }).catch((cause) => {
534
+ setError(cause instanceof Error ? cause.message : String(cause));
535
+ });
536
+ link.call("plugins.updates-check", {}).then((result) => {
537
+ if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
538
+ }).catch(() => void 0);
539
+ };
540
+ useEffect(() => {
541
+ load();
542
+ }, [link]);
543
+ const openInstall = () => {
544
+ setQuery("");
545
+ setSearchResults(void 0);
546
+ setMessage(void 0);
547
+ setDragging(false);
548
+ setInstallOpen(true);
549
+ };
550
+ const closeInstall = () => {
551
+ setInstallOpen(false);
552
+ setQuery("");
553
+ setSearchResults(void 0);
554
+ setMessage(void 0);
555
+ setDragging(false);
556
+ };
557
+ const toggle = (row, enabled) => {
558
+ setBusy(row.packageName);
559
+ link.call("plugins.set-enabled", {
560
+ name: row.packageName,
561
+ enabled
562
+ }).then((result) => {
563
+ if (!result.ok) {
564
+ setError(rpcErrorText(result.error));
565
+ return;
566
+ }
567
+ setRows((current) => current.map((item) => item.packageName === row.packageName ? {
568
+ ...item,
569
+ enabled
570
+ } : item));
571
+ setTouched((current) => new Set(current).add(row.packageName));
572
+ }).catch((cause) => {
573
+ setError(cause instanceof Error ? cause.message : String(cause));
574
+ }).finally(() => {
575
+ setBusy(void 0);
576
+ });
577
+ };
578
+ const uninstall = (row) => {
579
+ if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
580
+ setBusy(row.packageName);
581
+ link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
582
+ if (!result.ok) {
583
+ setError(rpcErrorText(result.error));
584
+ return;
585
+ }
586
+ setTouched((current) => new Set(current).add(row.packageName));
587
+ setRestartNeeded(true);
588
+ load();
589
+ }).catch((cause) => {
590
+ setError(cause instanceof Error ? cause.message : String(cause));
591
+ }).finally(() => {
592
+ setBusy(void 0);
593
+ });
594
+ };
595
+ const inspectPath = (zipPath) => {
596
+ setMessage(void 0);
597
+ link.call("plugins.inspect", { zipPath }).then((result) => {
598
+ if (!result.ok) {
599
+ setPhase({
600
+ kind: "error",
601
+ message: `读取插件包失败:${rpcErrorText(result.error)}`
602
+ });
603
+ return;
604
+ }
605
+ setPhase({
606
+ kind: "confirm",
607
+ zipPath,
608
+ archive: result.value.archive,
609
+ viaUrl: false,
610
+ risk: false
611
+ });
612
+ }).catch((cause) => setPhase({
613
+ kind: "error",
614
+ message: String(cause)
615
+ }));
616
+ };
617
+ const inspectFromUrl = (url) => {
618
+ setMessage(void 0);
619
+ link.call("plugins.inspect-from-url", { url }).then((result) => {
620
+ if (!result.ok) {
621
+ setPhase({
622
+ kind: "error",
623
+ message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
624
+ });
625
+ return;
626
+ }
627
+ setPhase({
628
+ kind: "confirm",
629
+ zipPath: result.value.zipPath,
630
+ archive: result.value.archive,
631
+ viaUrl: true,
632
+ risk: false
633
+ });
634
+ }).catch((cause) => setPhase({
635
+ kind: "error",
636
+ message: String(cause)
637
+ }));
638
+ };
639
+ const runInstall = (zipPath, archive) => {
640
+ setPhase({ kind: "installing" });
641
+ (archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
642
+ if (!result.ok) {
643
+ setPhase({
644
+ kind: "error",
645
+ message: `安装失败:${rpcErrorText(result.error)}`
646
+ });
647
+ return;
648
+ }
649
+ setPhase({ kind: "idle" });
650
+ closeInstall();
651
+ setRestartNeeded(true);
652
+ load();
653
+ }).catch((cause) => setPhase({
654
+ kind: "error",
655
+ message: String(cause)
656
+ }));
657
+ };
658
+ /** The update pill's click: a plain update installs directly; a key
659
+ * change confirmation intercepts first. */
660
+ const requestUpdate = (update) => {
661
+ if (update.keyChanged === true) {
662
+ setKeyChange(update);
663
+ return;
664
+ }
665
+ updateNow(update.name);
666
+ };
667
+ /** The update itself: the feed's entry, no preview. */
668
+ const updateNow = (name) => {
669
+ setKeyChange(void 0);
670
+ setUpdatingName(name);
671
+ setMessage(void 0);
672
+ link.call("plugins.remote-install", { name }).then((result) => {
673
+ setUpdatingName(void 0);
674
+ if (!result.ok) {
675
+ setMessage({
676
+ kind: "error",
677
+ text: rpcErrorText(result.error)
678
+ });
679
+ return;
680
+ }
681
+ setRestartNeeded(true);
682
+ load();
683
+ }).catch(() => setUpdatingName(void 0));
684
+ };
685
+ /** The tri-form input: address/path → inspect, anything else → feed search. */
686
+ const submitQuery = () => {
687
+ const text = query.trim();
688
+ if (text === "") return;
689
+ setMessage(void 0);
690
+ if (isHttpUrl(text)) {
691
+ inspectFromUrl(text);
692
+ return;
693
+ }
694
+ if (looksLikePath(text)) {
695
+ inspectPath(text);
696
+ return;
697
+ }
698
+ runSearch(text);
699
+ };
700
+ const runSearch = (text) => {
701
+ setSearching(true);
702
+ setSearchResults(void 0);
703
+ link.call("plugins.remote-list", {}).then((result) => {
704
+ setSearching(false);
705
+ if (!result.ok) {
706
+ setMessage({
707
+ kind: "error",
708
+ text: `搜索失败:${rpcErrorText(result.error)}`
709
+ });
710
+ return;
711
+ }
712
+ const needle = text.toLowerCase();
713
+ setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
714
+ }).catch((cause) => {
715
+ setSearching(false);
716
+ setMessage({
717
+ kind: "error",
718
+ text: String(cause)
719
+ });
720
+ });
721
+ };
722
+ /** A search-result entry that is not installed yet: preview first. The
723
+ * entry's own coordinates decide where the zip comes from — a federation
724
+ * row downloads from the author's release, a same-directory row from its
725
+ * feed base. */
726
+ const previewRemote = (item) => {
727
+ if (item.url !== void 0) {
728
+ inspectFromUrl(item.url);
729
+ return;
730
+ }
731
+ if (item.feedUrl === void 0 || item.file === void 0) return;
732
+ const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
733
+ inspectFromUrl(`${base}${item.file}`);
734
+ };
735
+ const onDrop = (event) => {
736
+ event.preventDefault();
737
+ setDragging(false);
738
+ const file = event.dataTransfer.files[0];
739
+ if (file === void 0) return;
740
+ if (!file.name.toLowerCase().endsWith(".zip")) {
741
+ setMessage({
742
+ kind: "error",
743
+ text: "只支持 .zip 插件包或组合包"
744
+ });
745
+ return;
746
+ }
747
+ const zipPath = droppedZipPath(file);
748
+ if (zipPath === null) {
749
+ setMessage({
750
+ kind: "error",
751
+ text: "当前环境不支持拖拽安装(缺少路径桥)"
752
+ });
753
+ return;
754
+ }
755
+ inspectPath(zipPath);
756
+ };
757
+ const restart = () => {
758
+ link.call("window.relaunch", {});
759
+ };
760
+ const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
761
+ const spans = /* @__PURE__ */ new Map();
762
+ for (let index = 0; index < rows.length;) {
763
+ const category = rows[index].category;
764
+ let end = index + 1;
765
+ while (end < rows.length && rows[end].category === category) end += 1;
766
+ spans.set(index, end - index);
767
+ index = end;
768
+ }
769
+ return jsxs(Page, {
770
+ title: "插件管理",
771
+ titleExtra: jsx(IconButton, {
772
+ icon: jsx(PlusIcon, {}),
773
+ label: "安装插件",
774
+ onClick: openInstall
775
+ }),
776
+ actions: restartNeeded ? jsx(Button, {
777
+ intent: "primary",
778
+ onClick: restart,
779
+ children: "重启生效"
780
+ }) : void 0,
781
+ children: [
782
+ jsxs(Stack, {
783
+ gap: "lg",
784
+ children: [error !== void 0 && jsx("div", {
785
+ role: "alert",
786
+ style: { color: "var(--snap-color-danger)" },
787
+ children: error
788
+ }), rows.length === 0 ? jsx(EmptyState, {
789
+ title: "还没有安装插件",
790
+ action: jsx(Button, {
791
+ intent: "primary",
792
+ onClick: openInstall,
793
+ children: "安装插件"
794
+ })
795
+ }) : jsxs(Table, {
796
+ "data-plugins-table": true,
797
+ children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
798
+ jsx(TableHead, {
799
+ style: { width: "6em" },
800
+ children: "分类"
801
+ }),
802
+ jsx(TableHead, { children: "名称" }),
803
+ jsx(TableHead, { children: "类型" }),
804
+ jsx(TableHead, { children: "版本" }),
805
+ jsx(TableHead, { children: "状态" }),
806
+ jsx(TableHead, { children: "操作" })
807
+ ] }) }), jsx(TableBody, { children: rows.map((row, index) => {
808
+ const update = updates.get(row.packageName);
809
+ const span = spans.get(index);
810
+ return jsxs(TableRow, { children: [
811
+ span !== void 0 && jsx(TableCell, {
812
+ rowSpan: span,
813
+ style: {
814
+ verticalAlign: "middle",
815
+ color: "var(--snap-color-muted)",
816
+ fontWeight: 600
817
+ },
818
+ children: row.category
819
+ }),
820
+ jsx(TableCell, { children: jsxs("div", {
821
+ style: {
822
+ display: "flex",
823
+ flexDirection: "column"
824
+ },
825
+ children: [jsxs("span", {
826
+ style: {
827
+ display: "flex",
828
+ alignItems: "center",
829
+ gap: "var(--snap-space-sm)"
830
+ },
831
+ children: [row.title, row.builtinDefault && jsx(Badge, {
832
+ intent: "neutral",
833
+ children: "内置默认"
834
+ })]
835
+ }), jsx("span", {
836
+ style: {
837
+ color: "var(--snap-color-muted)",
838
+ fontSize: "var(--snap-text-xs)"
839
+ },
840
+ children: row.packageName
841
+ })]
842
+ }) }),
843
+ jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
844
+ intent: "neutral",
845
+ children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
846
+ })] }),
847
+ jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
848
+ intent: "primary",
849
+ emphasis: "ghost",
850
+ size: "sm",
851
+ title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
852
+ disabled: updatingName === row.packageName,
853
+ onClick: () => requestUpdate(update),
854
+ children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
855
+ }) : row.version ?? "—" }),
856
+ jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
857
+ checked: true,
858
+ disabled: true,
859
+ "aria-label": `启用 ${row.title}`
860
+ }) : jsxs("div", {
861
+ style: {
862
+ display: "flex",
863
+ alignItems: "center",
864
+ gap: "var(--snap-space-sm)"
865
+ },
866
+ children: [jsx(Switch, {
867
+ checked: row.enabled,
868
+ disabled: busy === row.packageName,
869
+ onCheckedChange: (next) => toggle(row, next),
870
+ "aria-label": `启用 ${row.title}`
871
+ }), touched.has(row.packageName) && jsx(Badge, {
872
+ intent: "warning",
873
+ children: "待重启"
874
+ })]
875
+ }) }),
876
+ jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
877
+ style: { color: "var(--snap-color-muted)" },
878
+ children: "内置默认不可卸载"
879
+ }) : jsx(Button, {
880
+ intent: "danger",
881
+ emphasis: "ghost",
882
+ size: "sm",
883
+ disabled: busy === row.packageName,
884
+ onClick: () => uninstall(row),
885
+ children: "卸载"
886
+ }) })
887
+ ] }, row.packageName);
888
+ }) })]
889
+ })]
890
+ }),
891
+ jsx(Dialog, {
892
+ open: installOpen,
893
+ onOpenChange: (next) => {
894
+ if (!next) closeInstall();
895
+ },
896
+ children: jsxs(DialogContent, {
897
+ presentation: "modal",
898
+ size: "lg",
899
+ "data-plugins-dropzone": true,
900
+ "aria-describedby": void 0,
901
+ onDragOver: (event) => {
902
+ event.preventDefault();
903
+ setDragging(true);
904
+ },
905
+ onDragLeave: (event) => {
906
+ if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
907
+ },
908
+ onDrop,
909
+ children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
910
+ gap: "sm",
911
+ children: [
912
+ jsx("div", {
913
+ "data-plugins-drop-hint": true,
914
+ style: {
915
+ height: "calc(var(--snap-control-height-md) * 3)",
916
+ display: "flex",
917
+ alignItems: "center",
918
+ justifyContent: "center",
919
+ border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
920
+ borderRadius: "var(--snap-radius-md)",
921
+ background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
922
+ color: "var(--snap-color-muted)",
923
+ fontSize: "var(--snap-text-sm)"
924
+ },
925
+ children: dragging ? "释放以安装" : "拖入 .zip 安装"
926
+ }),
927
+ jsxs("div", {
928
+ style: {
929
+ display: "flex",
930
+ gap: "var(--snap-space-sm)"
931
+ },
932
+ children: [jsx(Input, {
933
+ value: query,
934
+ placeholder: "本地路径 / https://… / 插件名",
935
+ style: {
936
+ flex: 1,
937
+ minWidth: 0
938
+ },
939
+ onChange: (event) => setQuery(event.target.value),
940
+ onKeyDown: (event) => {
941
+ if (event.key === "Enter") submitQuery();
942
+ }
943
+ }), jsx(Button, {
944
+ intent: "neutral",
945
+ emphasis: "outline",
946
+ disabled: searching,
947
+ onClick: submitQuery,
948
+ children: searching ? "搜索中…" : "搜索"
949
+ })]
950
+ }),
951
+ message !== void 0 && jsx("div", {
952
+ role: message.kind === "error" ? "alert" : "status",
953
+ style: {
954
+ fontSize: "var(--snap-text-xs)",
955
+ color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
956
+ },
957
+ children: message.text
958
+ }),
959
+ visibleResults !== void 0 && jsxs(Stack, {
960
+ gap: "sm",
961
+ children: [
962
+ jsxs("div", {
963
+ style: {
964
+ display: "flex",
965
+ justifyContent: "space-between",
966
+ alignItems: "center"
967
+ },
968
+ children: [jsxs("span", {
969
+ style: {
970
+ fontSize: "var(--snap-text-sm)",
971
+ color: "var(--snap-color-muted)"
972
+ },
973
+ children: [
974
+ "搜索“",
975
+ query.trim(),
976
+ "”(",
977
+ searchResults?.length ?? 0,
978
+ ")"
979
+ ]
980
+ }), jsx(Button, {
981
+ intent: "neutral",
982
+ emphasis: "ghost",
983
+ size: "sm",
984
+ onClick: () => setSearchResults(void 0),
985
+ children: "✕"
986
+ })]
987
+ }),
988
+ visibleResults.length === 0 && jsx("div", {
989
+ style: {
990
+ padding: "12px 0",
991
+ textAlign: "center",
992
+ color: "var(--snap-color-muted)",
993
+ fontSize: "var(--snap-text-sm)"
994
+ },
995
+ children: "没有匹配的插件。"
996
+ }),
997
+ visibleResults.map((item) => {
998
+ const installed = item.installed !== void 0;
999
+ return jsxs("div", {
1000
+ style: {
1001
+ display: "flex",
1002
+ gap: "var(--snap-space-md)",
1003
+ alignItems: "center",
1004
+ justifyContent: "space-between",
1005
+ borderBottom: "1px solid var(--snap-color-border)",
1006
+ paddingBottom: "var(--snap-space-sm)"
1007
+ },
1008
+ children: [jsxs("div", {
1009
+ style: { minWidth: 0 },
1010
+ children: [jsxs("div", {
1011
+ style: {
1012
+ display: "flex",
1013
+ gap: "var(--snap-space-sm)",
1014
+ alignItems: "center"
1015
+ },
1016
+ children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
1017
+ intent: "neutral",
1018
+ children: item.source
1019
+ })]
1020
+ }), jsxs("div", {
1021
+ style: {
1022
+ fontSize: "var(--snap-text-xs)",
1023
+ color: "var(--snap-color-muted)"
1024
+ },
1025
+ children: [
1026
+ item.name,
1027
+ " · ",
1028
+ item.version
1029
+ ]
1030
+ })]
1031
+ }), item.action === "install" ? jsx(Button, {
1032
+ intent: "primary",
1033
+ emphasis: "outline",
1034
+ size: "sm",
1035
+ onClick: () => previewRemote(item),
1036
+ children: "安装"
1037
+ }) : item.action === "update" && installed ? jsx(Button, {
1038
+ intent: "primary",
1039
+ emphasis: "ghost",
1040
+ size: "sm",
1041
+ title: `当前 ${item.installed?.version} → ${item.version}`,
1042
+ disabled: updatingName === item.name,
1043
+ onClick: () => requestUpdate({
1044
+ name: item.name,
1045
+ installedVersion: item.installed?.version ?? "",
1046
+ feedVersion: item.version
1047
+ }),
1048
+ children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
1049
+ }) : jsx("span", {
1050
+ style: {
1051
+ fontSize: "var(--snap-text-xs)",
1052
+ color: "var(--snap-color-muted)"
1053
+ },
1054
+ children: item.action === "current" ? "已是最新" : "本地更新"
1055
+ })]
1056
+ }, item.name);
1057
+ }),
1058
+ (searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
1059
+ style: {
1060
+ fontSize: "var(--snap-text-xs)",
1061
+ color: "var(--snap-color-muted)"
1062
+ },
1063
+ children: [
1064
+ "已显示前 ",
1065
+ SEARCH_ROW_CAP,
1066
+ " 条,共 ",
1067
+ searchResults?.length,
1068
+ " 条。"
1069
+ ]
1070
+ })
1071
+ ]
1072
+ })
1073
+ ]
1074
+ }) })]
1075
+ })
1076
+ }),
1077
+ jsx(Dialog, {
1078
+ open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
1079
+ onOpenChange: (next) => {
1080
+ if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
1081
+ },
1082
+ children: jsxs(DialogContent, {
1083
+ presentation: "modal",
1084
+ "aria-describedby": void 0,
1085
+ children: [
1086
+ jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: phase.kind === "confirm" ? phase.archive.kind === "combo" ? "安装组合套件" : phase.archive.plugin.action === "update" ? "更新插件" : "安装插件" : phase.kind === "error" ? "安装失败" : "正在安装…" }), phase.kind === "confirm" && phase.archive.kind === "combo" && jsx(DialogDescription, { children: `${phase.archive.combo.title} · ${phase.archive.combo.id}` })] }),
1087
+ jsxs(DialogBody, { children: [
1088
+ phase.kind === "error" && jsx("div", {
1089
+ style: {
1090
+ color: "var(--snap-color-danger)",
1091
+ whiteSpace: "pre-wrap",
1092
+ fontSize: "var(--snap-text-sm)"
1093
+ },
1094
+ children: phase.message
1095
+ }),
1096
+ phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
1097
+ gap: "sm",
1098
+ children: [
1099
+ phase.archive.combo.description !== void 0 && jsx("div", {
1100
+ style: {
1101
+ color: "var(--snap-color-muted)",
1102
+ fontSize: "var(--snap-text-sm)"
1103
+ },
1104
+ children: phase.archive.combo.description
1105
+ }),
1106
+ jsxs("div", {
1107
+ style: {
1108
+ display: "grid",
1109
+ gap: "var(--snap-space-xs)",
1110
+ fontSize: "var(--snap-text-sm)"
1111
+ },
1112
+ children: [jsxs("div", { children: [
1113
+ "插件(",
1114
+ phase.archive.combo.plugins.length,
1115
+ ")"
1116
+ ] }), phase.archive.combo.plugins.map((plugin) => {
1117
+ const line = signatureText(plugin.signature, phase.viaUrl);
1118
+ const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
1119
+ return jsxs("div", {
1120
+ style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
1121
+ children: [
1122
+ plugin.title ?? plugin.name,
1123
+ " ",
1124
+ plugin.version,
1125
+ " · ",
1126
+ action,
1127
+ line.warning ? " · ⚠ 未验证" : ""
1128
+ ]
1129
+ }, plugin.name);
1130
+ })]
1131
+ }),
1132
+ phase.archive.combo.missing.length > 0 && jsxs("div", {
1133
+ style: {
1134
+ color: "var(--snap-color-danger)",
1135
+ fontSize: "var(--snap-text-sm)"
1136
+ },
1137
+ children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
1138
+ })
1139
+ ]
1140
+ }),
1141
+ phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
1142
+ gap: "sm",
1143
+ children: [
1144
+ phase.risk ? jsx("div", {
1145
+ "data-plugins-risk": true,
1146
+ style: {
1147
+ color: "var(--snap-color-warning)",
1148
+ fontWeight: 600
1149
+ },
1150
+ children: "⚠ 此插件未经发布者验证"
1151
+ }) : void 0,
1152
+ !phase.risk && jsxs(Stack, {
1153
+ gap: "sm",
1154
+ children: [
1155
+ phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
1156
+ jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
1157
+ phase.archive.plugin.action === "update" ? jsxs(Fragment, { children: [jsxs("div", { children: ["已安装版本:", phase.archive.plugin.installed?.version] }), jsxs("div", { children: ["将更新至:", phase.archive.plugin.version] })] }) : jsxs("div", { children: ["版本:", phase.archive.plugin.version] })
1158
+ ]
1159
+ }),
1160
+ (() => {
1161
+ const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
1162
+ return jsxs("div", {
1163
+ "data-plugins-signature": phase.archive.plugin.signature.state,
1164
+ style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
1165
+ children: ["签名:", line.text]
1166
+ });
1167
+ })(),
1168
+ !phase.risk && jsxs(Stack, {
1169
+ gap: "sm",
1170
+ children: [
1171
+ jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
1172
+ phase.archive.plugin.missing.length > 0 && jsxs("div", {
1173
+ style: {
1174
+ color: "var(--snap-color-danger)",
1175
+ fontSize: "var(--snap-text-sm)"
1176
+ },
1177
+ children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
1178
+ }),
1179
+ phase.archive.plugin.action === "blocked" && jsxs("div", {
1180
+ style: {
1181
+ color: "var(--snap-color-danger)",
1182
+ fontSize: "var(--snap-text-sm)"
1183
+ },
1184
+ children: [
1185
+ "已安装 v",
1186
+ phase.archive.plugin.installed?.version,
1187
+ ",安装包 v",
1188
+ phase.archive.plugin.version,
1189
+ " 不高于已装版本,无法覆盖。"
1190
+ ]
1191
+ })
1192
+ ]
1193
+ }),
1194
+ phase.risk && jsx("div", {
1195
+ style: {
1196
+ color: "var(--snap-color-muted)",
1197
+ fontSize: "var(--snap-text-sm)"
1198
+ },
1199
+ children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
1200
+ })
1201
+ ]
1202
+ })
1203
+ ] }),
1204
+ jsxs(DialogFooter, { children: [
1205
+ phase.kind === "error" && jsx(Button, {
1206
+ intent: "neutral",
1207
+ emphasis: "outline",
1208
+ onClick: () => setPhase({ kind: "idle" }),
1209
+ children: "返回"
1210
+ }),
1211
+ phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
1212
+ intent: "neutral",
1213
+ emphasis: "outline",
1214
+ onClick: () => setPhase({ kind: "idle" }),
1215
+ children: "取消"
1216
+ }), phase.risk ? jsx(Button, {
1217
+ intent: "primary",
1218
+ "data-plugins-risk-confirm": true,
1219
+ onClick: () => runInstall(phase.zipPath, phase.archive),
1220
+ children: "我知晓风险,仍要安装"
1221
+ }) : jsx(Button, {
1222
+ intent: "primary",
1223
+ "data-plugins-install-confirm": true,
1224
+ disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
1225
+ onClick: () => {
1226
+ if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
1227
+ setPhase({
1228
+ ...phase,
1229
+ risk: true
1230
+ });
1231
+ return;
1232
+ }
1233
+ runInstall(phase.zipPath, phase.archive);
1234
+ },
1235
+ children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
1236
+ })] }),
1237
+ phase.kind === "installing" && jsx("span", {
1238
+ style: { color: "var(--snap-color-muted)" },
1239
+ children: "正在安装…"
1240
+ })
1241
+ ] })
1242
+ ]
1243
+ })
1244
+ }),
1245
+ jsx(Dialog, {
1246
+ open: keyChange !== void 0,
1247
+ onOpenChange: (next) => {
1248
+ if (!next) setKeyChange(void 0);
1249
+ },
1250
+ children: jsxs(DialogContent, {
1251
+ presentation: "modal",
1252
+ children: [
1253
+ jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
1254
+ jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
1255
+ style: { fontSize: "var(--snap-text-sm)" },
1256
+ children: [
1257
+ "已安装 v",
1258
+ keyChange.installedVersion,
1259
+ " → 源上 v",
1260
+ keyChange.feedVersion,
1261
+ "。"
1262
+ ]
1263
+ }) }),
1264
+ jsxs(DialogFooter, { children: [jsx(Button, {
1265
+ intent: "neutral",
1266
+ emphasis: "outline",
1267
+ onClick: () => setKeyChange(void 0),
1268
+ children: "取消"
1269
+ }), jsx(Button, {
1270
+ intent: "primary",
1271
+ "data-plugins-keychange-confirm": true,
1272
+ onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
1273
+ children: "仍要更新"
1274
+ })] })
1275
+ ]
1276
+ })
1277
+ })
1278
+ ]
1279
+ });
1280
+ }
1281
+ //#endregion
1282
+ export { PluginsPage };