@snap-rail/ui 0.1.1 → 0.3.0

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