@snap-rail/ui 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/charts.js +6 -29
- package/lib/contract.js +119 -78
- package/lib/fallback.js +11 -1
- package/lib/index.js +2466 -735
- package/lib/runtime.js +1552 -490
- package/lib/settings.js +1162 -244
- package/lib/skins.js +163 -189
- package/lib/types/charts.d.ts +1 -1
- package/lib/types/charts.js +5 -5
- package/lib/types/components/alert.d.ts +57 -0
- package/lib/types/components/alert.js +46 -0
- package/lib/types/components/controls.d.ts +74 -11
- package/lib/types/components/controls.js +60 -17
- package/lib/types/components/dialog.d.ts +5 -5
- package/lib/types/components/dialog.js +2 -2
- package/lib/types/components/form-rhf.d.ts +56 -0
- package/lib/types/components/form-rhf.js +74 -0
- package/lib/types/components/form.d.ts +33 -5
- package/lib/types/components/form.js +22 -6
- package/lib/types/components/index.d.ts +7 -0
- package/lib/types/components/index.js +7 -0
- package/lib/types/components/input.d.ts +16 -7
- package/lib/types/components/input.js +39 -9
- package/lib/types/components/layout.d.ts +32 -7
- package/lib/types/components/layout.js +88 -15
- package/lib/types/components/overlay.d.ts +95 -0
- package/lib/types/components/overlay.js +138 -0
- package/lib/types/components/schema-form.d.ts +16 -4
- package/lib/types/components/schema-form.js +69 -40
- package/lib/types/components/slider.d.ts +18 -0
- package/lib/types/components/slider.js +15 -0
- package/lib/types/contract.d.ts +49 -37
- package/lib/types/contract.js +49 -33
- package/lib/types/fallback.js +1 -1
- package/lib/types/runtime.d.ts +23 -1
- package/lib/types/runtime.js +77 -20
- package/lib/types/settings-pages/appearance.d.ts +6 -4
- package/lib/types/settings-pages/appearance.js +33 -36
- package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
- package/lib/types/settings-pages/plugin-feed.js +66 -0
- package/lib/types/settings-pages/plugins.d.ts +10 -5
- package/lib/types/settings-pages/plugins.js +284 -21
- package/lib/types/settings.d.ts +1 -0
- package/lib/types/settings.js +14 -8
- package/lib/types/skins.d.ts +38 -44
- package/lib/types/skins.js +172 -169
- package/package.json +16 -9
- package/src/styles/base.css +251 -5
- package/src/styles/default.css +315 -136
package/lib/settings.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Component, createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import "@radix-ui/react-separator";
|
|
3
4
|
import { Slot } from "@radix-ui/react-slot";
|
|
4
5
|
import "@radix-ui/react-checkbox";
|
|
5
6
|
import "@radix-ui/react-label";
|
|
@@ -8,13 +9,22 @@ import "@radix-ui/react-select";
|
|
|
8
9
|
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
|
9
10
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
10
11
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
12
|
+
import "react-hook-form";
|
|
13
|
+
import "@hookform/resolvers/zod";
|
|
14
|
+
import "@radix-ui/react-scroll-area";
|
|
15
|
+
import "@radix-ui/react-dropdown-menu";
|
|
16
|
+
import "@radix-ui/react-popover";
|
|
17
|
+
import "@radix-ui/react-toast";
|
|
18
|
+
import "@radix-ui/react-tooltip";
|
|
19
|
+
import "@radix-ui/react-slider";
|
|
20
|
+
import { rpcErrorText } from "@snap-rail/connection";
|
|
21
|
+
import "@snap-rail/client-kernel";
|
|
22
|
+
import "@snap-rail/station-rpc/contract";
|
|
13
23
|
import "@snap-rail/cordis";
|
|
14
24
|
import "@snap-rail/cordis-plugin-timer";
|
|
15
25
|
import "@snap-rail/shell/contract";
|
|
16
26
|
import "react-dom/client";
|
|
17
|
-
import "@snap-rail/app-boot/contract";
|
|
27
|
+
import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
|
|
18
28
|
//#region lib/types/utils.js
|
|
19
29
|
/**
|
|
20
30
|
* Small helpers shared by the headless semantic components: class merging and
|
|
@@ -38,6 +48,19 @@ function space(token) {
|
|
|
38
48
|
return `var(--snap-space-${token})`;
|
|
39
49
|
}
|
|
40
50
|
//#endregion
|
|
51
|
+
//#region lib/types/components/alert.js
|
|
52
|
+
/** An inline status banner for results and failures. */
|
|
53
|
+
function Alert({ intent = "neutral", className, children, ...props }) {
|
|
54
|
+
return jsx("div", {
|
|
55
|
+
...part("alert", "root"),
|
|
56
|
+
role: "alert",
|
|
57
|
+
className: cn("snap-alert", className),
|
|
58
|
+
"data-intent": intent,
|
|
59
|
+
...props,
|
|
60
|
+
children
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
41
64
|
//#region lib/types/components/button.js
|
|
42
65
|
/**
|
|
43
66
|
* Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
|
|
@@ -135,7 +158,7 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
|
|
|
135
158
|
/** The dialog root. */
|
|
136
159
|
const Dialog = DialogPrimitive.Root;
|
|
137
160
|
/** The portalled dialog content. */
|
|
138
|
-
function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true }) {
|
|
161
|
+
function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
|
|
139
162
|
const resolved = presentation === "auto" ? "modal" : presentation;
|
|
140
163
|
return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
|
|
141
164
|
...part("dialog", "overlay"),
|
|
@@ -145,6 +168,7 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
|
|
|
145
168
|
className: cn("snap-dialog-panel", className),
|
|
146
169
|
"data-presentation": resolved,
|
|
147
170
|
"data-size": size,
|
|
171
|
+
...rest,
|
|
148
172
|
children: [children, showClose && jsx(DialogPrimitive.Close, {
|
|
149
173
|
...part("dialog", "close"),
|
|
150
174
|
className: "snap-dialog-close",
|
|
@@ -153,6 +177,14 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
|
|
|
153
177
|
})]
|
|
154
178
|
})] });
|
|
155
179
|
}
|
|
180
|
+
/** The dialog header. */
|
|
181
|
+
function DialogHeader({ children, className }) {
|
|
182
|
+
return jsx("div", {
|
|
183
|
+
...part("dialog", "header"),
|
|
184
|
+
className: cn("snap-dialog-header", className),
|
|
185
|
+
children
|
|
186
|
+
});
|
|
187
|
+
}
|
|
156
188
|
/** The dialog title. */
|
|
157
189
|
function DialogTitle({ children, className }) {
|
|
158
190
|
return jsx(DialogPrimitive.Title, {
|
|
@@ -161,10 +193,41 @@ function DialogTitle({ children, className }) {
|
|
|
161
193
|
children
|
|
162
194
|
});
|
|
163
195
|
}
|
|
196
|
+
/** The dialog description. */
|
|
197
|
+
function DialogDescription({ children, className }) {
|
|
198
|
+
return jsx(DialogPrimitive.Description, {
|
|
199
|
+
...part("dialog", "description"),
|
|
200
|
+
className: cn("snap-dialog-description", className),
|
|
201
|
+
children
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** The dialog body. */
|
|
205
|
+
function DialogBody({ children, className }) {
|
|
206
|
+
return jsx("div", {
|
|
207
|
+
...part("dialog", "body"),
|
|
208
|
+
className: cn("snap-dialog-body", className),
|
|
209
|
+
children
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** The dialog footer. */
|
|
213
|
+
function DialogFooter({ children, className }) {
|
|
214
|
+
return jsx("div", {
|
|
215
|
+
...part("dialog", "footer"),
|
|
216
|
+
className: cn("snap-dialog-footer", className),
|
|
217
|
+
children
|
|
218
|
+
});
|
|
219
|
+
}
|
|
164
220
|
//#endregion
|
|
165
221
|
//#region lib/types/components/controls.js
|
|
166
222
|
/** The tabs root. */
|
|
167
|
-
|
|
223
|
+
function Tabs({ className, children, ...props }) {
|
|
224
|
+
return jsx(TabsPrimitive.Root, {
|
|
225
|
+
...part("tabs", "root"),
|
|
226
|
+
className: cn("snap-tabs", className),
|
|
227
|
+
...props,
|
|
228
|
+
children
|
|
229
|
+
});
|
|
230
|
+
}
|
|
168
231
|
/** The tabs list. */
|
|
169
232
|
function TabsList({ className, children, ...props }) {
|
|
170
233
|
return jsx(TabsPrimitive.List, {
|
|
@@ -183,21 +246,36 @@ function TabsTrigger({ className, children, ...props }) {
|
|
|
183
246
|
children
|
|
184
247
|
});
|
|
185
248
|
}
|
|
186
|
-
/** A boolean switch. */
|
|
187
|
-
function Switch({ className, label, ...props }) {
|
|
188
|
-
|
|
249
|
+
/** A boolean switch with an optional label on either side. */
|
|
250
|
+
function Switch({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
|
|
251
|
+
const labelNode = label !== void 0 && jsx("span", {
|
|
252
|
+
...part("switch", "label"),
|
|
253
|
+
children: label
|
|
254
|
+
});
|
|
255
|
+
const row = jsxs("label", {
|
|
189
256
|
className: "snap-switch-label",
|
|
190
|
-
children: [
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
...
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
257
|
+
children: [
|
|
258
|
+
labelPosition === "start" && labelNode,
|
|
259
|
+
jsx(SwitchPrimitive.Root, {
|
|
260
|
+
...part("switch", "root"),
|
|
261
|
+
className: cn("snap-switch", className),
|
|
262
|
+
...props,
|
|
263
|
+
children: jsx(SwitchPrimitive.Thumb, {
|
|
264
|
+
...part("switch", "thumb"),
|
|
265
|
+
className: "snap-switch-thumb"
|
|
266
|
+
})
|
|
267
|
+
}),
|
|
268
|
+
labelPosition === "end" && labelNode
|
|
269
|
+
]
|
|
270
|
+
});
|
|
271
|
+
if (description === void 0) return row;
|
|
272
|
+
return jsxs("span", {
|
|
273
|
+
...part("switch", "field"),
|
|
274
|
+
className: cn("snap-switch-field", containerClassName),
|
|
275
|
+
children: [row, jsx("span", {
|
|
276
|
+
...part("switch", "description"),
|
|
277
|
+
className: "snap-field-help",
|
|
278
|
+
children: description
|
|
201
279
|
})]
|
|
202
280
|
});
|
|
203
281
|
}
|
|
@@ -237,6 +315,48 @@ function EmptyState({ title, description, icon, action, className }) {
|
|
|
237
315
|
]
|
|
238
316
|
});
|
|
239
317
|
}
|
|
318
|
+
createContext(null);
|
|
319
|
+
createContext(null);
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region lib/types/components/input.js
|
|
322
|
+
/** A single-line text field with semantic prefix/suffix slots. Layout
|
|
323
|
+
* `style`/`className` dress the wrapper — the visible control; the native
|
|
324
|
+
* field already stretches inside it. */
|
|
325
|
+
function Input({ size = "md", invalid = false, prefix, suffix, onClear, fieldClassName, componentName = "input", className, style, disabled, ...props }) {
|
|
326
|
+
return jsxs("div", {
|
|
327
|
+
...part(componentName, "root"),
|
|
328
|
+
className: cn("snap-input", className),
|
|
329
|
+
style,
|
|
330
|
+
"data-size": size,
|
|
331
|
+
"data-invalid": invalid || void 0,
|
|
332
|
+
"data-disabled": disabled === true || void 0,
|
|
333
|
+
children: [
|
|
334
|
+
prefix !== void 0 && jsx("span", {
|
|
335
|
+
...part(componentName, "prefix"),
|
|
336
|
+
children: prefix
|
|
337
|
+
}),
|
|
338
|
+
jsx("input", {
|
|
339
|
+
...part(componentName, "field"),
|
|
340
|
+
className: cn("snap-input-field", fieldClassName),
|
|
341
|
+
disabled,
|
|
342
|
+
"aria-invalid": invalid || void 0,
|
|
343
|
+
...props
|
|
344
|
+
}),
|
|
345
|
+
onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
|
|
346
|
+
...part(componentName, "clear"),
|
|
347
|
+
type: "button",
|
|
348
|
+
className: "snap-input-clear",
|
|
349
|
+
"aria-label": "清除",
|
|
350
|
+
onClick: onClear,
|
|
351
|
+
children: "×"
|
|
352
|
+
}),
|
|
353
|
+
suffix !== void 0 && jsx("span", {
|
|
354
|
+
...part(componentName, "suffix"),
|
|
355
|
+
children: suffix
|
|
356
|
+
})
|
|
357
|
+
]
|
|
358
|
+
});
|
|
359
|
+
}
|
|
240
360
|
//#endregion
|
|
241
361
|
//#region lib/types/components/layout.js
|
|
242
362
|
/** A vertical flow. */
|
|
@@ -274,7 +394,7 @@ function Row({ gap = "sm", padding, align, justify, wrap = false, className, sty
|
|
|
274
394
|
});
|
|
275
395
|
}
|
|
276
396
|
/** A page body with its own header/actions anatomy. */
|
|
277
|
-
function Page({ header, actions, title, description, className, style, children }) {
|
|
397
|
+
function Page({ header, actions, title, titleExtra, description, className, style, children }) {
|
|
278
398
|
return jsxs("div", {
|
|
279
399
|
...part("page", "root"),
|
|
280
400
|
className: cn("snap-page", className),
|
|
@@ -300,9 +420,19 @@ function Page({ header, actions, title, description, className, style, children
|
|
|
300
420
|
justifyContent: "space-between",
|
|
301
421
|
gap: space("md")
|
|
302
422
|
},
|
|
303
|
-
children: [
|
|
304
|
-
|
|
305
|
-
|
|
423
|
+
children: [jsxs("div", {
|
|
424
|
+
style: {
|
|
425
|
+
display: "flex",
|
|
426
|
+
alignItems: "center",
|
|
427
|
+
gap: space("sm")
|
|
428
|
+
},
|
|
429
|
+
children: [title !== void 0 && jsx("div", {
|
|
430
|
+
...part("page", "title"),
|
|
431
|
+
children: title
|
|
432
|
+
}), titleExtra !== void 0 && jsx("div", {
|
|
433
|
+
...part("page", "title-extra"),
|
|
434
|
+
children: titleExtra
|
|
435
|
+
})]
|
|
306
436
|
}), actions !== void 0 && jsx("div", {
|
|
307
437
|
...part("page", "actions"),
|
|
308
438
|
children: actions
|
|
@@ -440,7 +570,22 @@ const UI_SLOT_IDS = {
|
|
|
440
570
|
settingsSurface: "settings.surface"
|
|
441
571
|
};
|
|
442
572
|
UI_SLOT_IDS.layout, UI_SLOT_IDS.titlebar, UI_SLOT_IDS.titlebarActions, UI_SLOT_IDS.sidebar, UI_SLOT_IDS.statusbar, UI_SLOT_IDS.overlay, UI_SLOT_IDS.ball, UI_SLOT_IDS.settingsEntry, UI_SLOT_IDS.settingsSurface;
|
|
443
|
-
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region lib/types/skins.js
|
|
575
|
+
/** The React context carrying the skin service. */
|
|
576
|
+
const SkinsContext = createContext(null);
|
|
577
|
+
/** Read the skin service. */
|
|
578
|
+
function useSkins() {
|
|
579
|
+
const service = useContext(SkinsContext);
|
|
580
|
+
if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
|
|
581
|
+
return service;
|
|
582
|
+
}
|
|
583
|
+
/** Re-render on theme changes and return the active theme id. */
|
|
584
|
+
function useSkinId() {
|
|
585
|
+
const service = useSkins();
|
|
586
|
+
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
587
|
+
return service.active().id;
|
|
588
|
+
}
|
|
444
589
|
createContext(null);
|
|
445
590
|
//#endregion
|
|
446
591
|
//#region lib/types/runtime.js
|
|
@@ -501,24 +646,21 @@ async function writeSetting(link, key, value) {
|
|
|
501
646
|
/** The appearance/display page. */
|
|
502
647
|
function AppearancePage() {
|
|
503
648
|
const { link } = useClient();
|
|
504
|
-
const
|
|
649
|
+
const skins = useSkins();
|
|
650
|
+
const activeId = useSkinId();
|
|
651
|
+
const [packages, setPackages] = useState([]);
|
|
505
652
|
const [windowPreset, setWindowPreset] = useState(void 0);
|
|
506
653
|
const [ballSize, setBallSize] = useState(128);
|
|
507
654
|
const [ballEnabled, setBallEnabled] = useState(true);
|
|
508
|
-
const [ballDockable, setBallDockable] = useState(true);
|
|
509
655
|
const [ballCollapse, setBallCollapse] = useState(true);
|
|
510
|
-
const [skins, setSkins] = useState([]);
|
|
511
656
|
const [error, setError] = useState(void 0);
|
|
512
657
|
const [busy, setBusy] = useState(false);
|
|
513
658
|
useEffect(() => {
|
|
514
659
|
Promise.all([
|
|
515
|
-
readSetting(link, THEME_KEY),
|
|
516
660
|
readSetting(link, WINDOW_KEY),
|
|
517
661
|
readSetting(link, BALL_KEY),
|
|
518
662
|
link.call("plugins.list", {})
|
|
519
|
-
]).then(([
|
|
520
|
-
const themeMode = theme?.mode;
|
|
521
|
-
if (themeMode === "system" || themeMode === "light" || themeMode === "dark") setMode(themeMode);
|
|
663
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
522
664
|
const windowProfile = windowRow;
|
|
523
665
|
if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
|
|
524
666
|
const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
@@ -527,9 +669,8 @@ function AppearancePage() {
|
|
|
527
669
|
const ballProfile = ballRow;
|
|
528
670
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
|
|
529
671
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
|
|
530
|
-
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.dockable === "boolean") setBallDockable(ballProfile.dockable);
|
|
531
672
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
|
|
532
|
-
if (plugins.ok)
|
|
673
|
+
if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
|
|
533
674
|
name: plugin.packageName,
|
|
534
675
|
title: plugin.title ?? plugin.packageName,
|
|
535
676
|
enabled: plugin.enabled
|
|
@@ -537,19 +678,7 @@ function AppearancePage() {
|
|
|
537
678
|
}).catch((cause) => {
|
|
538
679
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
539
680
|
});
|
|
540
|
-
return subscribeFrame(link, "settings/changed", settingsChangedSchema, (change) => {
|
|
541
|
-
if (change.key === THEME_KEY) {
|
|
542
|
-
const next = change.value?.mode;
|
|
543
|
-
if (next === "system" || next === "light" || next === "dark") setMode(next);
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
681
|
}, [link]);
|
|
547
|
-
const saveTheme = (next) => {
|
|
548
|
-
setMode(next);
|
|
549
|
-
writeSetting(link, THEME_KEY, { mode: next }).catch((cause) => {
|
|
550
|
-
setError(cause instanceof Error ? cause.message : String(cause));
|
|
551
|
-
});
|
|
552
|
-
};
|
|
553
682
|
const saveWindow = (width, height, label) => {
|
|
554
683
|
setWindowPreset(label);
|
|
555
684
|
writeSetting(link, WINDOW_KEY, {
|
|
@@ -571,31 +700,45 @@ function AppearancePage() {
|
|
|
571
700
|
const next = {
|
|
572
701
|
size: patch.size ?? ballSize,
|
|
573
702
|
enabled: patch.enabled ?? ballEnabled,
|
|
574
|
-
dockable: patch.dockable ?? ballDockable,
|
|
575
703
|
collapse: patch.collapse ?? ballCollapse
|
|
576
704
|
};
|
|
577
705
|
if (patch.size !== void 0) setBallSize(patch.size);
|
|
578
706
|
if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
|
|
579
|
-
if (patch.dockable !== void 0) setBallDockable(patch.dockable);
|
|
580
707
|
if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
|
|
581
708
|
writeSetting(link, BALL_KEY, next).catch((cause) => {
|
|
582
709
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
583
710
|
});
|
|
584
711
|
};
|
|
585
|
-
const
|
|
712
|
+
const tabs = [...skins.list().map((row) => ({
|
|
713
|
+
id: row.id,
|
|
714
|
+
title: row.title
|
|
715
|
+
})), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
|
|
716
|
+
id: pkg.name,
|
|
717
|
+
title: pkg.title,
|
|
718
|
+
enable: pkg.name
|
|
719
|
+
}))];
|
|
720
|
+
const selectTheme = (tab) => {
|
|
721
|
+
if (busy) return;
|
|
722
|
+
if (tab.enable === void 0) {
|
|
723
|
+
writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
|
|
724
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
725
|
+
});
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
586
728
|
setBusy(true);
|
|
587
729
|
link.call("plugins.set-enabled", {
|
|
588
|
-
name:
|
|
589
|
-
enabled:
|
|
730
|
+
name: tab.enable,
|
|
731
|
+
enabled: true
|
|
590
732
|
}).then((result) => {
|
|
591
733
|
if (!result.ok) {
|
|
592
734
|
setError(rpcErrorText(result.error));
|
|
593
735
|
return;
|
|
594
736
|
}
|
|
595
|
-
|
|
596
|
-
...
|
|
597
|
-
enabled:
|
|
598
|
-
} :
|
|
737
|
+
setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
|
|
738
|
+
...pkg,
|
|
739
|
+
enabled: true
|
|
740
|
+
} : pkg));
|
|
741
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
599
742
|
}).catch((cause) => {
|
|
600
743
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
601
744
|
}).finally(() => {
|
|
@@ -604,83 +747,34 @@ function AppearancePage() {
|
|
|
604
747
|
};
|
|
605
748
|
return jsx(Page, {
|
|
606
749
|
title: "外观与显示",
|
|
607
|
-
description: "
|
|
750
|
+
description: "主题、主窗口尺寸和悬浮球外观。",
|
|
608
751
|
children: jsxs(Stack, {
|
|
609
752
|
gap: "lg",
|
|
610
753
|
children: [
|
|
611
|
-
error !== void 0 && jsx(
|
|
612
|
-
|
|
613
|
-
style: { color: "var(--snap-color-danger)" },
|
|
754
|
+
error !== void 0 && jsx(Alert, {
|
|
755
|
+
intent: "danger",
|
|
614
756
|
children: error
|
|
615
757
|
}),
|
|
616
758
|
jsx(Section, {
|
|
617
|
-
title: "
|
|
759
|
+
title: "主题",
|
|
618
760
|
children: jsx(Tabs, {
|
|
619
|
-
value:
|
|
620
|
-
onValueChange: (value) =>
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}),
|
|
632
|
-
jsx(TabsTrigger, {
|
|
633
|
-
value: "dark",
|
|
634
|
-
children: "黑夜"
|
|
635
|
-
})
|
|
636
|
-
]
|
|
761
|
+
value: activeId,
|
|
762
|
+
onValueChange: (value) => {
|
|
763
|
+
const tab = tabs.find((item) => item.id === value);
|
|
764
|
+
if (tab !== void 0) selectTheme(tab);
|
|
765
|
+
},
|
|
766
|
+
children: jsx(TabsList, {
|
|
767
|
+
"aria-label": "主题",
|
|
768
|
+
children: tabs.map((tab) => jsx(TabsTrigger, {
|
|
769
|
+
value: tab.id,
|
|
770
|
+
disabled: busy,
|
|
771
|
+
children: tab.title
|
|
772
|
+
}, tab.id))
|
|
637
773
|
})
|
|
638
774
|
})
|
|
639
775
|
}),
|
|
640
|
-
jsx(Section, {
|
|
641
|
-
title: "界面皮肤",
|
|
642
|
-
description: "皮肤由独立插件提供;启用后需要重启终端。",
|
|
643
|
-
children: jsxs(Stack, {
|
|
644
|
-
gap: "sm",
|
|
645
|
-
children: [jsxs(Row, {
|
|
646
|
-
gap: "sm",
|
|
647
|
-
align: "center",
|
|
648
|
-
children: [jsx(Badge, {
|
|
649
|
-
intent: "success",
|
|
650
|
-
children: "默认(内置)"
|
|
651
|
-
}), jsx("span", {
|
|
652
|
-
style: {
|
|
653
|
-
color: "var(--snap-color-muted)",
|
|
654
|
-
fontSize: "var(--snap-text-sm)"
|
|
655
|
-
},
|
|
656
|
-
children: "工业钴蓝,始终可用"
|
|
657
|
-
})]
|
|
658
|
-
}), skins.length === 0 ? jsx("span", {
|
|
659
|
-
style: { color: "var(--snap-color-muted)" },
|
|
660
|
-
children: "尚未安装其他皮肤插件。"
|
|
661
|
-
}) : skins.map((skin) => jsxs(Row, {
|
|
662
|
-
gap: "sm",
|
|
663
|
-
align: "center",
|
|
664
|
-
children: [
|
|
665
|
-
jsx("span", { children: skin.title }),
|
|
666
|
-
jsx(Badge, {
|
|
667
|
-
intent: skin.enabled ? "success" : "neutral",
|
|
668
|
-
children: skin.enabled ? "已启用" : "未启用"
|
|
669
|
-
}),
|
|
670
|
-
jsx(Button, {
|
|
671
|
-
size: "sm",
|
|
672
|
-
emphasis: "outline",
|
|
673
|
-
disabled: busy,
|
|
674
|
-
onClick: () => toggleSkin(skin),
|
|
675
|
-
children: skin.enabled ? "停用" : "启用"
|
|
676
|
-
})
|
|
677
|
-
]
|
|
678
|
-
}, skin.name))]
|
|
679
|
-
})
|
|
680
|
-
}),
|
|
681
776
|
jsx(Section, {
|
|
682
777
|
title: "主窗口",
|
|
683
|
-
description: "布局/套件会声明推荐尺寸;这里的选择会覆盖布局推荐。",
|
|
684
778
|
children: jsxs(Stack, {
|
|
685
779
|
gap: "sm",
|
|
686
780
|
children: [jsxs(Row, {
|
|
@@ -709,7 +803,7 @@ function AppearancePage() {
|
|
|
709
803
|
}),
|
|
710
804
|
jsx(Section, {
|
|
711
805
|
title: "悬浮球",
|
|
712
|
-
description: "
|
|
806
|
+
description: "球面尺寸与停泊行为。",
|
|
713
807
|
children: jsxs(Stack, {
|
|
714
808
|
gap: "md",
|
|
715
809
|
children: [jsx(Row, {
|
|
@@ -727,23 +821,15 @@ function AppearancePage() {
|
|
|
727
821
|
gap: "lg",
|
|
728
822
|
wrap: true,
|
|
729
823
|
align: "center",
|
|
730
|
-
children: [
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
onCheckedChange: (dockable) => saveBall({ dockable })
|
|
740
|
-
}),
|
|
741
|
-
jsx(Switch, {
|
|
742
|
-
label: "贴边后收起",
|
|
743
|
-
checked: ballCollapse,
|
|
744
|
-
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
745
|
-
})
|
|
746
|
-
]
|
|
824
|
+
children: [jsx(Switch, {
|
|
825
|
+
label: "启用悬浮球",
|
|
826
|
+
checked: ballEnabled,
|
|
827
|
+
onCheckedChange: (enabled) => saveBall({ enabled })
|
|
828
|
+
}), jsx(Switch, {
|
|
829
|
+
label: "允许贴边收起",
|
|
830
|
+
checked: ballCollapse,
|
|
831
|
+
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
832
|
+
})]
|
|
747
833
|
})]
|
|
748
834
|
})
|
|
749
835
|
})
|
|
@@ -752,7 +838,157 @@ function AppearancePage() {
|
|
|
752
838
|
});
|
|
753
839
|
}
|
|
754
840
|
//#endregion
|
|
841
|
+
//#region lib/types/settings-pages/plugin-feed.js
|
|
842
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
843
|
+
function PluginFeedDialog(props) {
|
|
844
|
+
const { open } = props;
|
|
845
|
+
const link = props.ctx.client.link;
|
|
846
|
+
const [urls, setUrls] = useState([]);
|
|
847
|
+
const [draft, setDraft] = useState("");
|
|
848
|
+
const [error, setError] = useState(void 0);
|
|
849
|
+
useEffect(() => {
|
|
850
|
+
if (!open) return;
|
|
851
|
+
link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
|
|
852
|
+
if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
|
|
853
|
+
}).catch(() => void 0);
|
|
854
|
+
}, [open, link]);
|
|
855
|
+
const save = () => {
|
|
856
|
+
for (const url of urls) try {
|
|
857
|
+
const parsed = new URL(url);
|
|
858
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
859
|
+
} catch {
|
|
860
|
+
setError("插件源地址需要以 http(s) 开头");
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
setError(void 0);
|
|
864
|
+
link.call("settings.set", {
|
|
865
|
+
key: PLUGINS_FEED_URLS_KEY,
|
|
866
|
+
value: urls
|
|
867
|
+
}).then((result) => {
|
|
868
|
+
if (!result.ok) {
|
|
869
|
+
setError(rpcErrorText(result.error));
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
props.onOpenChange(false);
|
|
873
|
+
}).catch((cause) => setError(String(cause)));
|
|
874
|
+
};
|
|
875
|
+
const append = () => {
|
|
876
|
+
const value = draft.trim();
|
|
877
|
+
if (value === "") return;
|
|
878
|
+
try {
|
|
879
|
+
const parsed = new URL(value);
|
|
880
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
881
|
+
} catch {
|
|
882
|
+
setError("请填写 http(s) 开头的插件源地址");
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
setError(void 0);
|
|
886
|
+
setDraft("");
|
|
887
|
+
setUrls((current) => current.includes(value) ? current : [...current, value]);
|
|
888
|
+
};
|
|
889
|
+
return jsx(Dialog, {
|
|
890
|
+
open,
|
|
891
|
+
onOpenChange: props.onOpenChange,
|
|
892
|
+
children: jsxs(DialogContent, {
|
|
893
|
+
presentation: "modal",
|
|
894
|
+
"aria-describedby": void 0,
|
|
895
|
+
children: [
|
|
896
|
+
jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
|
|
897
|
+
jsx(DialogBody, { children: jsxs(Stack, {
|
|
898
|
+
gap: "sm",
|
|
899
|
+
children: [
|
|
900
|
+
urls.length === 0 && jsx("div", {
|
|
901
|
+
style: {
|
|
902
|
+
fontSize: "var(--snap-text-xs)",
|
|
903
|
+
color: "var(--snap-color-muted)"
|
|
904
|
+
},
|
|
905
|
+
children: "尚未添加自定义源(当前使用出厂默认源)。"
|
|
906
|
+
}),
|
|
907
|
+
urls.map((url, index) => jsxs("div", {
|
|
908
|
+
style: {
|
|
909
|
+
display: "flex",
|
|
910
|
+
gap: "var(--snap-space-sm)",
|
|
911
|
+
alignItems: "center"
|
|
912
|
+
},
|
|
913
|
+
children: [jsx("span", {
|
|
914
|
+
style: {
|
|
915
|
+
flex: 1,
|
|
916
|
+
minWidth: 0,
|
|
917
|
+
overflow: "hidden",
|
|
918
|
+
textOverflow: "ellipsis",
|
|
919
|
+
whiteSpace: "nowrap",
|
|
920
|
+
fontSize: "var(--snap-text-xs)"
|
|
921
|
+
},
|
|
922
|
+
children: url
|
|
923
|
+
}), jsx(Button, {
|
|
924
|
+
intent: "neutral",
|
|
925
|
+
emphasis: "ghost",
|
|
926
|
+
size: "sm",
|
|
927
|
+
"aria-label": `移除 ${url}`,
|
|
928
|
+
onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
|
|
929
|
+
children: "✕"
|
|
930
|
+
})]
|
|
931
|
+
}, url)),
|
|
932
|
+
jsxs("div", {
|
|
933
|
+
style: {
|
|
934
|
+
display: "flex",
|
|
935
|
+
gap: "var(--snap-space-sm)",
|
|
936
|
+
width: "100%"
|
|
937
|
+
},
|
|
938
|
+
children: [jsx(Input, {
|
|
939
|
+
value: draft,
|
|
940
|
+
placeholder: "https://…",
|
|
941
|
+
style: {
|
|
942
|
+
flex: 1,
|
|
943
|
+
minWidth: 0
|
|
944
|
+
},
|
|
945
|
+
onChange: (event) => setDraft(event.target.value),
|
|
946
|
+
onKeyDown: (event) => {
|
|
947
|
+
if (event.key === "Enter") append();
|
|
948
|
+
}
|
|
949
|
+
}), jsx(Button, {
|
|
950
|
+
intent: "neutral",
|
|
951
|
+
emphasis: "outline",
|
|
952
|
+
onClick: append,
|
|
953
|
+
children: "添加源"
|
|
954
|
+
})]
|
|
955
|
+
}),
|
|
956
|
+
error !== void 0 && jsx("div", {
|
|
957
|
+
role: "alert",
|
|
958
|
+
style: {
|
|
959
|
+
color: "var(--snap-color-danger)",
|
|
960
|
+
fontSize: "var(--snap-text-sm)"
|
|
961
|
+
},
|
|
962
|
+
children: error
|
|
963
|
+
})
|
|
964
|
+
]
|
|
965
|
+
}) }),
|
|
966
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
967
|
+
intent: "neutral",
|
|
968
|
+
emphasis: "outline",
|
|
969
|
+
onClick: () => props.onOpenChange(false),
|
|
970
|
+
children: "取消"
|
|
971
|
+
}), jsx(Button, {
|
|
972
|
+
intent: "primary",
|
|
973
|
+
"data-plugins-feed-save": true,
|
|
974
|
+
onClick: save,
|
|
975
|
+
children: "保存"
|
|
976
|
+
})] })
|
|
977
|
+
]
|
|
978
|
+
})
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
//#endregion
|
|
755
982
|
//#region lib/types/settings-pages/plugins.js
|
|
983
|
+
/** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
|
|
984
|
+
* Electron or in tests. Inlined rather than imported from the app-internal
|
|
985
|
+
* kernel package: it never ships in the installer, and the packaged-app gate
|
|
986
|
+
* refuses any shipped `@snap-rail/ui` lib that requires it. */
|
|
987
|
+
function droppedZipPath(file) {
|
|
988
|
+
const zipPathOf = globalThis.snapRail?.zipPathOf;
|
|
989
|
+
if (typeof zipPathOf !== "function") return null;
|
|
990
|
+
return zipPathOf(file);
|
|
991
|
+
}
|
|
756
992
|
/** Human labels for the package kinds. */
|
|
757
993
|
const KIND_LABELS = {
|
|
758
994
|
skin: "界面风格",
|
|
@@ -765,6 +1001,22 @@ const PROFILE_LABELS = {
|
|
|
765
1001
|
integrated: "图表桥接",
|
|
766
1002
|
custom: "自定义界面"
|
|
767
1003
|
};
|
|
1004
|
+
/** Search rows shown before the tail is folded into a counter. */
|
|
1005
|
+
const SEARCH_ROW_CAP = 20;
|
|
1006
|
+
/** The plus glyph for the page's install entry. */
|
|
1007
|
+
function PlusIcon() {
|
|
1008
|
+
return jsx("svg", {
|
|
1009
|
+
viewBox: "0 0 24 24",
|
|
1010
|
+
width: "18",
|
|
1011
|
+
height: "18",
|
|
1012
|
+
fill: "none",
|
|
1013
|
+
stroke: "currentColor",
|
|
1014
|
+
strokeWidth: "2.4",
|
|
1015
|
+
strokeLinecap: "round",
|
|
1016
|
+
"aria-hidden": "true",
|
|
1017
|
+
children: jsx("path", { d: "M12 5v14M5 12h14" })
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
768
1020
|
/** Collapse entry rows into package rows (one master switch per package). */
|
|
769
1021
|
function packageRows(plugins) {
|
|
770
1022
|
const byPackage = /* @__PURE__ */ new Map();
|
|
@@ -790,15 +1042,44 @@ function packageRows(plugins) {
|
|
|
790
1042
|
}
|
|
791
1043
|
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
792
1044
|
}
|
|
1045
|
+
/** The preview's signature line (one row in the confirm card). */
|
|
1046
|
+
function signatureText(signature, viaUrl) {
|
|
1047
|
+
if (signature.state === "verified") return {
|
|
1048
|
+
text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
|
|
1049
|
+
warning: false
|
|
1050
|
+
};
|
|
1051
|
+
const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
|
|
1052
|
+
return {
|
|
1053
|
+
text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
|
|
1054
|
+
warning: true
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
/** Does the input name an http(s) address? */
|
|
1058
|
+
const isHttpUrl = (text) => /^https?:\/\//i.test(text);
|
|
1059
|
+
/** Does the input look like a filesystem path (drive letter, UNC, posix
|
|
1060
|
+
* root, or a .zip name with a separator in it)? */
|
|
1061
|
+
const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
|
|
793
1062
|
/** The plugin management page. */
|
|
794
1063
|
function PluginsPage({ ctx }) {
|
|
795
1064
|
const [rows, setRows] = useState([]);
|
|
796
1065
|
const [error, setError] = useState(void 0);
|
|
797
1066
|
const [busy, setBusy] = useState(void 0);
|
|
798
1067
|
const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
|
|
1068
|
+
const [restartNeeded, setRestartNeeded] = useState(false);
|
|
1069
|
+
const [installOpen, setInstallOpen] = useState(false);
|
|
1070
|
+
const [phase, setPhase] = useState({ kind: "idle" });
|
|
1071
|
+
const [message, setMessage] = useState(void 0);
|
|
1072
|
+
const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
|
|
1073
|
+
const [updatingName, setUpdatingName] = useState(void 0);
|
|
1074
|
+
const [keyChange, setKeyChange] = useState(void 0);
|
|
1075
|
+
const [query, setQuery] = useState("");
|
|
1076
|
+
const [searchResults, setSearchResults] = useState(void 0);
|
|
1077
|
+
const [searching, setSearching] = useState(false);
|
|
1078
|
+
const [dragging, setDragging] = useState(false);
|
|
1079
|
+
const link = ctx.client.link;
|
|
799
1080
|
const load = () => {
|
|
800
1081
|
setError(void 0);
|
|
801
|
-
|
|
1082
|
+
link.call("plugins.list", {}).then((result) => {
|
|
802
1083
|
if (!result.ok) {
|
|
803
1084
|
setError(rpcErrorText(result.error));
|
|
804
1085
|
return;
|
|
@@ -807,11 +1088,30 @@ function PluginsPage({ ctx }) {
|
|
|
807
1088
|
}).catch((cause) => {
|
|
808
1089
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
809
1090
|
});
|
|
1091
|
+
link.call("plugins.updates-check", {}).then((result) => {
|
|
1092
|
+
if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
|
|
1093
|
+
}).catch(() => void 0);
|
|
1094
|
+
};
|
|
1095
|
+
useEffect(() => {
|
|
1096
|
+
load();
|
|
1097
|
+
}, [link]);
|
|
1098
|
+
const openInstall = () => {
|
|
1099
|
+
setQuery("");
|
|
1100
|
+
setSearchResults(void 0);
|
|
1101
|
+
setMessage(void 0);
|
|
1102
|
+
setDragging(false);
|
|
1103
|
+
setInstallOpen(true);
|
|
1104
|
+
};
|
|
1105
|
+
const closeInstall = () => {
|
|
1106
|
+
setInstallOpen(false);
|
|
1107
|
+
setQuery("");
|
|
1108
|
+
setSearchResults(void 0);
|
|
1109
|
+
setMessage(void 0);
|
|
1110
|
+
setDragging(false);
|
|
810
1111
|
};
|
|
811
|
-
useEffect(load, []);
|
|
812
1112
|
const toggle = (row, enabled) => {
|
|
813
1113
|
setBusy(row.packageName);
|
|
814
|
-
|
|
1114
|
+
link.call("plugins.set-enabled", {
|
|
815
1115
|
name: row.packageName,
|
|
816
1116
|
enabled
|
|
817
1117
|
}).then((result) => {
|
|
@@ -833,12 +1133,13 @@ function PluginsPage({ ctx }) {
|
|
|
833
1133
|
const uninstall = (row) => {
|
|
834
1134
|
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
|
|
835
1135
|
setBusy(row.packageName);
|
|
836
|
-
|
|
1136
|
+
link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
|
|
837
1137
|
if (!result.ok) {
|
|
838
1138
|
setError(rpcErrorText(result.error));
|
|
839
1139
|
return;
|
|
840
1140
|
}
|
|
841
1141
|
setTouched((current) => new Set(current).add(row.packageName));
|
|
1142
|
+
setRestartNeeded(true);
|
|
842
1143
|
load();
|
|
843
1144
|
}).catch((cause) => {
|
|
844
1145
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
@@ -846,100 +1147,689 @@ function PluginsPage({ ctx }) {
|
|
|
846
1147
|
setBusy(void 0);
|
|
847
1148
|
});
|
|
848
1149
|
};
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1150
|
+
const inspectPath = (zipPath) => {
|
|
1151
|
+
setMessage(void 0);
|
|
1152
|
+
link.call("plugins.inspect", { zipPath }).then((result) => {
|
|
1153
|
+
if (!result.ok) {
|
|
1154
|
+
setPhase({
|
|
1155
|
+
kind: "error",
|
|
1156
|
+
message: `读取插件包失败:${rpcErrorText(result.error)}`
|
|
1157
|
+
});
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
setPhase({
|
|
1161
|
+
kind: "confirm",
|
|
1162
|
+
zipPath,
|
|
1163
|
+
archive: result.value.archive,
|
|
1164
|
+
viaUrl: false,
|
|
1165
|
+
risk: false
|
|
1166
|
+
});
|
|
1167
|
+
}).catch((cause) => setPhase({
|
|
1168
|
+
kind: "error",
|
|
1169
|
+
message: String(cause)
|
|
1170
|
+
}));
|
|
1171
|
+
};
|
|
1172
|
+
const inspectFromUrl = (url) => {
|
|
1173
|
+
setMessage(void 0);
|
|
1174
|
+
link.call("plugins.inspect-from-url", { url }).then((result) => {
|
|
1175
|
+
if (!result.ok) {
|
|
1176
|
+
setPhase({
|
|
1177
|
+
kind: "error",
|
|
1178
|
+
message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
|
|
1179
|
+
});
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
setPhase({
|
|
1183
|
+
kind: "confirm",
|
|
1184
|
+
zipPath: result.value.zipPath,
|
|
1185
|
+
archive: result.value.archive,
|
|
1186
|
+
viaUrl: true,
|
|
1187
|
+
risk: false
|
|
1188
|
+
});
|
|
1189
|
+
}).catch((cause) => setPhase({
|
|
1190
|
+
kind: "error",
|
|
1191
|
+
message: String(cause)
|
|
1192
|
+
}));
|
|
1193
|
+
};
|
|
1194
|
+
const runInstall = (zipPath, archive) => {
|
|
1195
|
+
setPhase({ kind: "installing" });
|
|
1196
|
+
(archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
|
|
1197
|
+
if (!result.ok) {
|
|
1198
|
+
setPhase({
|
|
1199
|
+
kind: "error",
|
|
1200
|
+
message: `安装失败:${rpcErrorText(result.error)}`
|
|
1201
|
+
});
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
setPhase({ kind: "idle" });
|
|
1205
|
+
closeInstall();
|
|
1206
|
+
setRestartNeeded(true);
|
|
1207
|
+
load();
|
|
1208
|
+
}).catch((cause) => setPhase({
|
|
1209
|
+
kind: "error",
|
|
1210
|
+
message: String(cause)
|
|
1211
|
+
}));
|
|
1212
|
+
};
|
|
1213
|
+
/** The update pill's click: a plain update installs directly; a key
|
|
1214
|
+
* change confirmation intercepts first. */
|
|
1215
|
+
const requestUpdate = (update) => {
|
|
1216
|
+
if (update.keyChanged === true) {
|
|
1217
|
+
setKeyChange(update);
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
updateNow(update.name);
|
|
1221
|
+
};
|
|
1222
|
+
/** The update itself: the feed's entry, no preview. */
|
|
1223
|
+
const updateNow = (name) => {
|
|
1224
|
+
setKeyChange(void 0);
|
|
1225
|
+
setUpdatingName(name);
|
|
1226
|
+
setMessage(void 0);
|
|
1227
|
+
link.call("plugins.remote-install", { name }).then((result) => {
|
|
1228
|
+
setUpdatingName(void 0);
|
|
1229
|
+
if (!result.ok) {
|
|
1230
|
+
setMessage({
|
|
1231
|
+
kind: "error",
|
|
1232
|
+
text: rpcErrorText(result.error)
|
|
1233
|
+
});
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
setRestartNeeded(true);
|
|
1237
|
+
load();
|
|
1238
|
+
}).catch(() => setUpdatingName(void 0));
|
|
1239
|
+
};
|
|
1240
|
+
/** The tri-form input: address/path → inspect, anything else → feed search. */
|
|
1241
|
+
const submitQuery = () => {
|
|
1242
|
+
const text = query.trim();
|
|
1243
|
+
if (text === "") return;
|
|
1244
|
+
setMessage(void 0);
|
|
1245
|
+
if (isHttpUrl(text)) {
|
|
1246
|
+
inspectFromUrl(text);
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
if (looksLikePath(text)) {
|
|
1250
|
+
inspectPath(text);
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
runSearch(text);
|
|
1254
|
+
};
|
|
1255
|
+
const runSearch = (text) => {
|
|
1256
|
+
setSearching(true);
|
|
1257
|
+
setSearchResults(void 0);
|
|
1258
|
+
link.call("plugins.remote-list", {}).then((result) => {
|
|
1259
|
+
setSearching(false);
|
|
1260
|
+
if (!result.ok) {
|
|
1261
|
+
setMessage({
|
|
1262
|
+
kind: "error",
|
|
1263
|
+
text: `搜索失败:${rpcErrorText(result.error)}`
|
|
1264
|
+
});
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
const needle = text.toLowerCase();
|
|
1268
|
+
setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
|
|
1269
|
+
}).catch((cause) => {
|
|
1270
|
+
setSearching(false);
|
|
1271
|
+
setMessage({
|
|
1272
|
+
kind: "error",
|
|
1273
|
+
text: String(cause)
|
|
1274
|
+
});
|
|
1275
|
+
});
|
|
1276
|
+
};
|
|
1277
|
+
/** A search-result entry that is not installed yet: preview first. The
|
|
1278
|
+
* entry's own coordinates decide where the zip comes from — a federation
|
|
1279
|
+
* row downloads from the author's release, a same-directory row from its
|
|
1280
|
+
* feed base. */
|
|
1281
|
+
const previewRemote = (item) => {
|
|
1282
|
+
if (item.url !== void 0) {
|
|
1283
|
+
inspectFromUrl(item.url);
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (item.feedUrl === void 0 || item.file === void 0) return;
|
|
1287
|
+
const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
|
|
1288
|
+
inspectFromUrl(`${base}${item.file}`);
|
|
1289
|
+
};
|
|
1290
|
+
const onDrop = (event) => {
|
|
1291
|
+
event.preventDefault();
|
|
1292
|
+
setDragging(false);
|
|
1293
|
+
const file = event.dataTransfer.files[0];
|
|
1294
|
+
if (file === void 0) return;
|
|
1295
|
+
if (!file.name.toLowerCase().endsWith(".zip")) {
|
|
1296
|
+
setMessage({
|
|
1297
|
+
kind: "error",
|
|
1298
|
+
text: "只支持 .zip 插件包或组合包"
|
|
1299
|
+
});
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
const zipPath = droppedZipPath(file);
|
|
1303
|
+
if (zipPath === null) {
|
|
1304
|
+
setMessage({
|
|
1305
|
+
kind: "error",
|
|
1306
|
+
text: "当前环境不支持拖拽安装(缺少路径桥)"
|
|
1307
|
+
});
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
inspectPath(zipPath);
|
|
1311
|
+
};
|
|
1312
|
+
const restart = () => {
|
|
1313
|
+
link.call("window.relaunch", {});
|
|
1314
|
+
};
|
|
1315
|
+
const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
|
|
1316
|
+
const spans = /* @__PURE__ */ new Map();
|
|
1317
|
+
for (let index = 0; index < rows.length;) {
|
|
1318
|
+
const category = rows[index].category;
|
|
1319
|
+
let end = index + 1;
|
|
1320
|
+
while (end < rows.length && rows[end].category === category) end += 1;
|
|
1321
|
+
spans.set(index, end - index);
|
|
1322
|
+
index = end;
|
|
854
1323
|
}
|
|
855
|
-
return
|
|
1324
|
+
return jsxs(Page, {
|
|
856
1325
|
title: "插件管理",
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
onClick: load,
|
|
862
|
-
children: "刷新"
|
|
1326
|
+
titleExtra: jsx(IconButton, {
|
|
1327
|
+
icon: jsx(PlusIcon, {}),
|
|
1328
|
+
label: "安装插件",
|
|
1329
|
+
onClick: openInstall
|
|
863
1330
|
}),
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
jsx(
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1331
|
+
actions: restartNeeded ? jsx(Button, {
|
|
1332
|
+
intent: "primary",
|
|
1333
|
+
onClick: restart,
|
|
1334
|
+
children: "重启生效"
|
|
1335
|
+
}) : void 0,
|
|
1336
|
+
children: [
|
|
1337
|
+
jsxs(Stack, {
|
|
1338
|
+
gap: "lg",
|
|
1339
|
+
children: [error !== void 0 && jsx(Alert, {
|
|
1340
|
+
intent: "danger",
|
|
1341
|
+
children: error
|
|
1342
|
+
}), rows.length === 0 ? jsx(EmptyState, {
|
|
1343
|
+
title: "还没有安装插件",
|
|
1344
|
+
action: jsx(Button, {
|
|
1345
|
+
intent: "primary",
|
|
1346
|
+
onClick: openInstall,
|
|
1347
|
+
children: "安装插件"
|
|
1348
|
+
})
|
|
1349
|
+
}) : jsxs(Table, {
|
|
1350
|
+
"data-plugins-table": true,
|
|
1351
|
+
children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
|
|
1352
|
+
jsx(TableHead, {
|
|
1353
|
+
style: { width: "6em" },
|
|
1354
|
+
children: "分类"
|
|
1355
|
+
}),
|
|
1356
|
+
jsx(TableHead, { children: "名称" }),
|
|
1357
|
+
jsx(TableHead, { children: "类型" }),
|
|
1358
|
+
jsx(TableHead, { children: "版本" }),
|
|
1359
|
+
jsx(TableHead, { children: "状态" }),
|
|
1360
|
+
jsx(TableHead, { children: "操作" })
|
|
1361
|
+
] }) }), jsx(TableBody, { children: rows.map((row, index) => {
|
|
1362
|
+
const update = updates.get(row.packageName);
|
|
1363
|
+
const span = spans.get(index);
|
|
1364
|
+
return jsxs(TableRow, { children: [
|
|
1365
|
+
span !== void 0 && jsx(TableCell, {
|
|
1366
|
+
rowSpan: span,
|
|
1367
|
+
style: {
|
|
1368
|
+
verticalAlign: "middle",
|
|
1369
|
+
color: "var(--snap-color-muted)",
|
|
1370
|
+
fontWeight: 600
|
|
1371
|
+
},
|
|
1372
|
+
children: row.category
|
|
1373
|
+
}),
|
|
1374
|
+
jsx(TableCell, { children: jsxs("div", {
|
|
1375
|
+
style: {
|
|
1376
|
+
display: "flex",
|
|
1377
|
+
flexDirection: "column"
|
|
1378
|
+
},
|
|
1379
|
+
children: [jsxs("span", {
|
|
1380
|
+
style: {
|
|
1381
|
+
display: "flex",
|
|
1382
|
+
alignItems: "center",
|
|
1383
|
+
gap: "var(--snap-space-sm)"
|
|
1384
|
+
},
|
|
1385
|
+
children: [row.title, row.builtinDefault && jsx(Badge, {
|
|
1386
|
+
intent: "neutral",
|
|
1387
|
+
children: "内置默认"
|
|
1388
|
+
})]
|
|
1389
|
+
}), jsx("span", {
|
|
1390
|
+
style: {
|
|
1391
|
+
color: "var(--snap-color-muted)",
|
|
1392
|
+
fontSize: "var(--snap-text-xs)"
|
|
1393
|
+
},
|
|
1394
|
+
children: row.packageName
|
|
1395
|
+
})]
|
|
1396
|
+
}) }),
|
|
1397
|
+
jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
|
|
894
1398
|
intent: "neutral",
|
|
895
|
-
children:
|
|
896
|
-
})]
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
children: "
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1399
|
+
children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
|
|
1400
|
+
})] }),
|
|
1401
|
+
jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
|
|
1402
|
+
intent: "primary",
|
|
1403
|
+
emphasis: "ghost",
|
|
1404
|
+
size: "sm",
|
|
1405
|
+
title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
|
|
1406
|
+
disabled: updatingName === row.packageName,
|
|
1407
|
+
onClick: () => requestUpdate(update),
|
|
1408
|
+
children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
|
|
1409
|
+
}) : row.version ?? "—" }),
|
|
1410
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
|
|
1411
|
+
checked: true,
|
|
1412
|
+
disabled: true,
|
|
1413
|
+
"aria-label": `启用 ${row.title}`
|
|
1414
|
+
}) : jsxs("div", {
|
|
1415
|
+
style: {
|
|
1416
|
+
display: "flex",
|
|
1417
|
+
alignItems: "center",
|
|
1418
|
+
gap: "var(--snap-space-sm)"
|
|
1419
|
+
},
|
|
1420
|
+
children: [jsx(Switch, {
|
|
1421
|
+
checked: row.enabled,
|
|
1422
|
+
disabled: busy === row.packageName,
|
|
1423
|
+
onCheckedChange: (next) => toggle(row, next),
|
|
1424
|
+
"aria-label": `启用 ${row.title}`
|
|
1425
|
+
}), touched.has(row.packageName) && jsx(Badge, {
|
|
1426
|
+
intent: "warning",
|
|
1427
|
+
children: "待重启"
|
|
1428
|
+
})]
|
|
1429
|
+
}) }),
|
|
1430
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
|
|
1431
|
+
style: { color: "var(--snap-color-muted)" },
|
|
1432
|
+
children: "内置默认不可卸载"
|
|
1433
|
+
}) : jsx(Button, {
|
|
1434
|
+
intent: "danger",
|
|
1435
|
+
emphasis: "ghost",
|
|
1436
|
+
size: "sm",
|
|
1437
|
+
disabled: busy === row.packageName,
|
|
1438
|
+
onClick: () => uninstall(row),
|
|
1439
|
+
children: "卸载"
|
|
1440
|
+
}) })
|
|
1441
|
+
] }, row.packageName);
|
|
1442
|
+
}) })]
|
|
1443
|
+
})]
|
|
1444
|
+
}),
|
|
1445
|
+
jsx(Dialog, {
|
|
1446
|
+
open: installOpen,
|
|
1447
|
+
onOpenChange: (next) => {
|
|
1448
|
+
if (!next) closeInstall();
|
|
1449
|
+
},
|
|
1450
|
+
children: jsxs(DialogContent, {
|
|
1451
|
+
presentation: "modal",
|
|
1452
|
+
size: "lg",
|
|
1453
|
+
"data-plugins-dropzone": true,
|
|
1454
|
+
"aria-describedby": void 0,
|
|
1455
|
+
onDragOver: (event) => {
|
|
1456
|
+
event.preventDefault();
|
|
1457
|
+
setDragging(true);
|
|
1458
|
+
},
|
|
1459
|
+
onDragLeave: (event) => {
|
|
1460
|
+
if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
|
|
1461
|
+
},
|
|
1462
|
+
onDrop,
|
|
1463
|
+
children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
|
|
1464
|
+
gap: "sm",
|
|
1465
|
+
children: [
|
|
1466
|
+
jsx("div", {
|
|
1467
|
+
"data-plugins-drop-hint": true,
|
|
1468
|
+
style: {
|
|
1469
|
+
height: "calc(var(--snap-control-height-md) * 3)",
|
|
1470
|
+
display: "flex",
|
|
1471
|
+
alignItems: "center",
|
|
1472
|
+
justifyContent: "center",
|
|
1473
|
+
border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
|
|
1474
|
+
borderRadius: "var(--snap-radius-md)",
|
|
1475
|
+
background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
|
|
1476
|
+
color: "var(--snap-color-muted)",
|
|
1477
|
+
fontSize: "var(--snap-text-sm)"
|
|
1478
|
+
},
|
|
1479
|
+
children: dragging ? "释放以安装" : "拖入 .zip 安装"
|
|
1480
|
+
}),
|
|
1481
|
+
jsxs("div", {
|
|
1482
|
+
style: {
|
|
1483
|
+
display: "flex",
|
|
1484
|
+
gap: "var(--snap-space-sm)"
|
|
1485
|
+
},
|
|
1486
|
+
children: [jsx(Input, {
|
|
1487
|
+
value: query,
|
|
1488
|
+
placeholder: "本地路径 / https://… / 插件名",
|
|
1489
|
+
style: {
|
|
1490
|
+
flex: 1,
|
|
1491
|
+
minWidth: 0
|
|
1492
|
+
},
|
|
1493
|
+
onChange: (event) => setQuery(event.target.value),
|
|
1494
|
+
onKeyDown: (event) => {
|
|
1495
|
+
if (event.key === "Enter") submitQuery();
|
|
1496
|
+
}
|
|
1497
|
+
}), jsx(Button, {
|
|
1498
|
+
intent: "neutral",
|
|
1499
|
+
emphasis: "outline",
|
|
1500
|
+
disabled: searching,
|
|
1501
|
+
onClick: submitQuery,
|
|
1502
|
+
children: searching ? "搜索中…" : "搜索"
|
|
1503
|
+
})]
|
|
1504
|
+
}),
|
|
1505
|
+
message !== void 0 && jsx("div", {
|
|
1506
|
+
role: message.kind === "error" ? "alert" : "status",
|
|
1507
|
+
style: {
|
|
1508
|
+
fontSize: "var(--snap-text-xs)",
|
|
1509
|
+
color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
|
|
1510
|
+
},
|
|
1511
|
+
children: message.text
|
|
1512
|
+
}),
|
|
1513
|
+
visibleResults !== void 0 && jsxs(Stack, {
|
|
1514
|
+
gap: "sm",
|
|
1515
|
+
children: [
|
|
1516
|
+
jsxs("div", {
|
|
1517
|
+
style: {
|
|
1518
|
+
display: "flex",
|
|
1519
|
+
justifyContent: "space-between",
|
|
1520
|
+
alignItems: "center"
|
|
1521
|
+
},
|
|
1522
|
+
children: [jsxs("span", {
|
|
1523
|
+
style: {
|
|
1524
|
+
fontSize: "var(--snap-text-sm)",
|
|
1525
|
+
color: "var(--snap-color-muted)"
|
|
1526
|
+
},
|
|
1527
|
+
children: [
|
|
1528
|
+
"搜索“",
|
|
1529
|
+
query.trim(),
|
|
1530
|
+
"”(",
|
|
1531
|
+
searchResults?.length ?? 0,
|
|
1532
|
+
")"
|
|
1533
|
+
]
|
|
1534
|
+
}), jsx(Button, {
|
|
1535
|
+
intent: "neutral",
|
|
1536
|
+
emphasis: "ghost",
|
|
1537
|
+
size: "sm",
|
|
1538
|
+
onClick: () => setSearchResults(void 0),
|
|
1539
|
+
children: "✕"
|
|
1540
|
+
})]
|
|
1541
|
+
}),
|
|
1542
|
+
visibleResults.length === 0 && jsx("div", {
|
|
1543
|
+
style: {
|
|
1544
|
+
padding: "12px 0",
|
|
1545
|
+
textAlign: "center",
|
|
1546
|
+
color: "var(--snap-color-muted)",
|
|
1547
|
+
fontSize: "var(--snap-text-sm)"
|
|
1548
|
+
},
|
|
1549
|
+
children: "没有匹配的插件。"
|
|
1550
|
+
}),
|
|
1551
|
+
visibleResults.map((item) => {
|
|
1552
|
+
const installed = item.installed !== void 0;
|
|
1553
|
+
return jsxs("div", {
|
|
1554
|
+
style: {
|
|
1555
|
+
display: "flex",
|
|
1556
|
+
gap: "var(--snap-space-md)",
|
|
1557
|
+
alignItems: "center",
|
|
1558
|
+
justifyContent: "space-between",
|
|
1559
|
+
borderBottom: "1px solid var(--snap-color-border)",
|
|
1560
|
+
paddingBottom: "var(--snap-space-sm)"
|
|
1561
|
+
},
|
|
1562
|
+
children: [jsxs("div", {
|
|
1563
|
+
style: { minWidth: 0 },
|
|
1564
|
+
children: [jsxs("div", {
|
|
1565
|
+
style: {
|
|
1566
|
+
display: "flex",
|
|
1567
|
+
gap: "var(--snap-space-sm)",
|
|
1568
|
+
alignItems: "center"
|
|
1569
|
+
},
|
|
1570
|
+
children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
|
|
1571
|
+
intent: "neutral",
|
|
1572
|
+
children: item.source
|
|
1573
|
+
})]
|
|
1574
|
+
}), jsxs("div", {
|
|
1575
|
+
style: {
|
|
1576
|
+
fontSize: "var(--snap-text-xs)",
|
|
1577
|
+
color: "var(--snap-color-muted)"
|
|
1578
|
+
},
|
|
1579
|
+
children: [
|
|
1580
|
+
item.name,
|
|
1581
|
+
" · ",
|
|
1582
|
+
item.version
|
|
1583
|
+
]
|
|
1584
|
+
})]
|
|
1585
|
+
}), item.action === "install" ? jsx(Button, {
|
|
1586
|
+
intent: "primary",
|
|
1587
|
+
emphasis: "outline",
|
|
1588
|
+
size: "sm",
|
|
1589
|
+
onClick: () => previewRemote(item),
|
|
1590
|
+
children: "安装"
|
|
1591
|
+
}) : item.action === "update" && installed ? jsx(Button, {
|
|
1592
|
+
intent: "primary",
|
|
1593
|
+
emphasis: "ghost",
|
|
1594
|
+
size: "sm",
|
|
1595
|
+
title: `当前 ${item.installed?.version} → ${item.version}`,
|
|
1596
|
+
disabled: updatingName === item.name,
|
|
1597
|
+
onClick: () => requestUpdate({
|
|
1598
|
+
name: item.name,
|
|
1599
|
+
installedVersion: item.installed?.version ?? "",
|
|
1600
|
+
feedVersion: item.version
|
|
1601
|
+
}),
|
|
1602
|
+
children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
|
|
1603
|
+
}) : jsx("span", {
|
|
1604
|
+
style: {
|
|
1605
|
+
fontSize: "var(--snap-text-xs)",
|
|
1606
|
+
color: "var(--snap-color-muted)"
|
|
1607
|
+
},
|
|
1608
|
+
children: item.action === "current" ? "已是最新" : "本地更新"
|
|
1609
|
+
})]
|
|
1610
|
+
}, item.name);
|
|
1611
|
+
}),
|
|
1612
|
+
(searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
|
|
1613
|
+
style: {
|
|
1614
|
+
fontSize: "var(--snap-text-xs)",
|
|
1615
|
+
color: "var(--snap-color-muted)"
|
|
1616
|
+
},
|
|
1617
|
+
children: [
|
|
1618
|
+
"已显示前 ",
|
|
1619
|
+
SEARCH_ROW_CAP,
|
|
1620
|
+
" 条,共 ",
|
|
1621
|
+
searchResults?.length,
|
|
1622
|
+
" 条。"
|
|
1623
|
+
]
|
|
1624
|
+
})
|
|
1625
|
+
]
|
|
1626
|
+
})
|
|
1627
|
+
]
|
|
1628
|
+
}) })]
|
|
1629
|
+
})
|
|
1630
|
+
}),
|
|
1631
|
+
jsx(Dialog, {
|
|
1632
|
+
open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
|
|
1633
|
+
onOpenChange: (next) => {
|
|
1634
|
+
if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
|
|
1635
|
+
},
|
|
1636
|
+
children: jsxs(DialogContent, {
|
|
1637
|
+
presentation: "modal",
|
|
1638
|
+
"aria-describedby": void 0,
|
|
1639
|
+
children: [
|
|
1640
|
+
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}` })] }),
|
|
1641
|
+
jsxs(DialogBody, { children: [
|
|
1642
|
+
phase.kind === "error" && jsx("div", {
|
|
1643
|
+
style: {
|
|
1644
|
+
color: "var(--snap-color-danger)",
|
|
1645
|
+
whiteSpace: "pre-wrap",
|
|
1646
|
+
fontSize: "var(--snap-text-sm)"
|
|
1647
|
+
},
|
|
1648
|
+
children: phase.message
|
|
1649
|
+
}),
|
|
1650
|
+
phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
|
|
1651
|
+
gap: "sm",
|
|
1652
|
+
children: [
|
|
1653
|
+
phase.archive.combo.description !== void 0 && jsx("div", {
|
|
1654
|
+
style: {
|
|
1655
|
+
color: "var(--snap-color-muted)",
|
|
1656
|
+
fontSize: "var(--snap-text-sm)"
|
|
1657
|
+
},
|
|
1658
|
+
children: phase.archive.combo.description
|
|
1659
|
+
}),
|
|
1660
|
+
jsxs("div", {
|
|
1661
|
+
style: {
|
|
1662
|
+
display: "grid",
|
|
1663
|
+
gap: "var(--snap-space-xs)",
|
|
1664
|
+
fontSize: "var(--snap-text-sm)"
|
|
1665
|
+
},
|
|
1666
|
+
children: [jsxs("div", { children: [
|
|
1667
|
+
"插件(",
|
|
1668
|
+
phase.archive.combo.plugins.length,
|
|
1669
|
+
")"
|
|
1670
|
+
] }), phase.archive.combo.plugins.map((plugin) => {
|
|
1671
|
+
const line = signatureText(plugin.signature, phase.viaUrl);
|
|
1672
|
+
const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
|
|
1673
|
+
return jsxs("div", {
|
|
1674
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
1675
|
+
children: [
|
|
1676
|
+
plugin.title ?? plugin.name,
|
|
1677
|
+
" ",
|
|
1678
|
+
plugin.version,
|
|
1679
|
+
" · ",
|
|
1680
|
+
action,
|
|
1681
|
+
line.warning ? " · ⚠ 未验证" : ""
|
|
1682
|
+
]
|
|
1683
|
+
}, plugin.name);
|
|
1684
|
+
})]
|
|
1685
|
+
}),
|
|
1686
|
+
phase.archive.combo.missing.length > 0 && jsxs("div", {
|
|
1687
|
+
style: {
|
|
1688
|
+
color: "var(--snap-color-danger)",
|
|
1689
|
+
fontSize: "var(--snap-text-sm)"
|
|
1690
|
+
},
|
|
1691
|
+
children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
|
|
1692
|
+
})
|
|
1693
|
+
]
|
|
1694
|
+
}),
|
|
1695
|
+
phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
|
|
1696
|
+
gap: "sm",
|
|
1697
|
+
children: [
|
|
1698
|
+
phase.risk ? jsx("div", {
|
|
1699
|
+
"data-plugins-risk": true,
|
|
1700
|
+
style: {
|
|
1701
|
+
color: "var(--snap-color-warning)",
|
|
1702
|
+
fontWeight: 600
|
|
1703
|
+
},
|
|
1704
|
+
children: "⚠ 此插件未经发布者验证"
|
|
1705
|
+
}) : void 0,
|
|
1706
|
+
!phase.risk && jsxs(Stack, {
|
|
1707
|
+
gap: "sm",
|
|
1708
|
+
children: [
|
|
1709
|
+
phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
|
|
1710
|
+
jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
|
|
1711
|
+
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] })
|
|
1712
|
+
]
|
|
1713
|
+
}),
|
|
1714
|
+
(() => {
|
|
1715
|
+
const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
|
|
1716
|
+
return jsxs("div", {
|
|
1717
|
+
"data-plugins-signature": phase.archive.plugin.signature.state,
|
|
1718
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
1719
|
+
children: ["签名:", line.text]
|
|
1720
|
+
});
|
|
1721
|
+
})(),
|
|
1722
|
+
!phase.risk && jsxs(Stack, {
|
|
1723
|
+
gap: "sm",
|
|
1724
|
+
children: [
|
|
1725
|
+
jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
|
|
1726
|
+
phase.archive.plugin.missing.length > 0 && jsxs("div", {
|
|
1727
|
+
style: {
|
|
1728
|
+
color: "var(--snap-color-danger)",
|
|
1729
|
+
fontSize: "var(--snap-text-sm)"
|
|
1730
|
+
},
|
|
1731
|
+
children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
|
|
1732
|
+
}),
|
|
1733
|
+
phase.archive.plugin.action === "blocked" && jsxs("div", {
|
|
1734
|
+
style: {
|
|
1735
|
+
color: "var(--snap-color-danger)",
|
|
1736
|
+
fontSize: "var(--snap-text-sm)"
|
|
1737
|
+
},
|
|
1738
|
+
children: [
|
|
1739
|
+
"已安装 v",
|
|
1740
|
+
phase.archive.plugin.installed?.version,
|
|
1741
|
+
",安装包 v",
|
|
1742
|
+
phase.archive.plugin.version,
|
|
1743
|
+
" 不高于已装版本,无法覆盖。"
|
|
1744
|
+
]
|
|
1745
|
+
})
|
|
1746
|
+
]
|
|
1747
|
+
}),
|
|
1748
|
+
phase.risk && jsx("div", {
|
|
1749
|
+
style: {
|
|
1750
|
+
color: "var(--snap-color-muted)",
|
|
1751
|
+
fontSize: "var(--snap-text-sm)"
|
|
1752
|
+
},
|
|
1753
|
+
children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
|
|
1754
|
+
})
|
|
1755
|
+
]
|
|
1756
|
+
})
|
|
1757
|
+
] }),
|
|
1758
|
+
jsxs(DialogFooter, { children: [
|
|
1759
|
+
phase.kind === "error" && jsx(Button, {
|
|
1760
|
+
intent: "neutral",
|
|
1761
|
+
emphasis: "outline",
|
|
1762
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
1763
|
+
children: "返回"
|
|
1764
|
+
}),
|
|
1765
|
+
phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
|
|
1766
|
+
intent: "neutral",
|
|
1767
|
+
emphasis: "outline",
|
|
1768
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
1769
|
+
children: "取消"
|
|
1770
|
+
}), phase.risk ? jsx(Button, {
|
|
1771
|
+
intent: "primary",
|
|
1772
|
+
"data-plugins-risk-confirm": true,
|
|
1773
|
+
onClick: () => runInstall(phase.zipPath, phase.archive),
|
|
1774
|
+
children: "我知晓风险,仍要安装"
|
|
1775
|
+
}) : jsx(Button, {
|
|
1776
|
+
intent: "primary",
|
|
1777
|
+
"data-plugins-install-confirm": true,
|
|
1778
|
+
disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
|
|
1779
|
+
onClick: () => {
|
|
1780
|
+
if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
|
|
1781
|
+
setPhase({
|
|
1782
|
+
...phase,
|
|
1783
|
+
risk: true
|
|
1784
|
+
});
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
runInstall(phase.zipPath, phase.archive);
|
|
1788
|
+
},
|
|
1789
|
+
children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
|
|
1790
|
+
})] }),
|
|
1791
|
+
phase.kind === "installing" && jsx("span", {
|
|
1792
|
+
style: { color: "var(--snap-color-muted)" },
|
|
1793
|
+
children: "正在安装…"
|
|
1794
|
+
})
|
|
1795
|
+
] })
|
|
1796
|
+
]
|
|
1797
|
+
})
|
|
1798
|
+
}),
|
|
1799
|
+
jsx(Dialog, {
|
|
1800
|
+
open: keyChange !== void 0,
|
|
1801
|
+
onOpenChange: (next) => {
|
|
1802
|
+
if (!next) setKeyChange(void 0);
|
|
1803
|
+
},
|
|
1804
|
+
children: jsxs(DialogContent, {
|
|
1805
|
+
presentation: "modal",
|
|
1806
|
+
children: [
|
|
1807
|
+
jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
|
|
1808
|
+
jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
|
|
1809
|
+
style: { fontSize: "var(--snap-text-sm)" },
|
|
1810
|
+
children: [
|
|
1811
|
+
"已安装 v",
|
|
1812
|
+
keyChange.installedVersion,
|
|
1813
|
+
" → 源上 v",
|
|
1814
|
+
keyChange.feedVersion,
|
|
1815
|
+
"。"
|
|
1816
|
+
]
|
|
1817
|
+
}) }),
|
|
1818
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
1819
|
+
intent: "neutral",
|
|
1820
|
+
emphasis: "outline",
|
|
1821
|
+
onClick: () => setKeyChange(void 0),
|
|
1822
|
+
children: "取消"
|
|
1823
|
+
}), jsx(Button, {
|
|
1824
|
+
intent: "primary",
|
|
1825
|
+
"data-plugins-keychange-confirm": true,
|
|
1826
|
+
onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
|
|
1827
|
+
children: "仍要更新"
|
|
1828
|
+
})] })
|
|
1829
|
+
]
|
|
1830
|
+
})
|
|
1831
|
+
})
|
|
1832
|
+
]
|
|
943
1833
|
});
|
|
944
1834
|
}
|
|
945
1835
|
//#endregion
|
|
@@ -981,6 +1871,19 @@ function GearIcon() {
|
|
|
981
1871
|
}), jsx("path", { d: "M19.4 15a1.7 1.7 0 0 0 .34 1.87l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.7 1.7 0 0 0-1.87-.34 1.7 1.7 0 0 0-1 1.55V21a2 2 0 1 1-4 0v-.09a1.7 1.7 0 0 0-1-1.55 1.7 1.7 0 0 0-1.87.34l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.7 1.7 0 0 0 .34-1.87 1.7 1.7 0 0 0-1.55-1H3a2 2 0 1 1 0-4h.09a1.7 1.7 0 0 0 1.55-1 1.7 1.7 0 0 0-.34-1.87l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.7 1.7 0 0 0 1.87.34h0a1.7 1.7 0 0 0 1-1.55V3a2 2 0 1 1 4 0v.09a1.7 1.7 0 0 0 1 1.55h0a1.7 1.7 0 0 0 1.87-.34l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.7 1.7 0 0 0-.34 1.87v0a1.7 1.7 0 0 0 1.55 1H21a2 2 0 1 1 0 4h-.09a1.7 1.7 0 0 0-1.55 1Z" })]
|
|
982
1872
|
});
|
|
983
1873
|
}
|
|
1874
|
+
/** The close glyph used by the surface's dismiss control. */
|
|
1875
|
+
function CloseIcon() {
|
|
1876
|
+
return jsx("svg", {
|
|
1877
|
+
viewBox: "0 0 24 24",
|
|
1878
|
+
width: "18",
|
|
1879
|
+
height: "18",
|
|
1880
|
+
fill: "none",
|
|
1881
|
+
stroke: "currentColor",
|
|
1882
|
+
strokeWidth: "1.8",
|
|
1883
|
+
"aria-hidden": "true",
|
|
1884
|
+
children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
984
1887
|
/** The default settings trigger; the layout decides placement/presentation. */
|
|
985
1888
|
function SettingsEntry(props) {
|
|
986
1889
|
if (props.presentation === "label") return jsx(Button, {
|
|
@@ -999,12 +1902,13 @@ function SettingsEntry(props) {
|
|
|
999
1902
|
}
|
|
1000
1903
|
/** The default settings surface. */
|
|
1001
1904
|
function SettingsSurface(props) {
|
|
1002
|
-
const { service } = props;
|
|
1905
|
+
const { service, ctx } = props;
|
|
1003
1906
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
1004
1907
|
const open = service.isOpen();
|
|
1005
1908
|
const pages = service.listPages();
|
|
1006
1909
|
const activeId = service.activePage();
|
|
1007
1910
|
const active = pages.find((page) => page.id === activeId);
|
|
1911
|
+
const [feedOpen, setFeedOpen] = useState(false);
|
|
1008
1912
|
const groups = /* @__PURE__ */ new Map();
|
|
1009
1913
|
for (const page of pages) {
|
|
1010
1914
|
const group = page.group ?? "其他";
|
|
@@ -1012,7 +1916,7 @@ function SettingsSurface(props) {
|
|
|
1012
1916
|
if (bucket === void 0) groups.set(group, [page]);
|
|
1013
1917
|
else bucket.push(page);
|
|
1014
1918
|
}
|
|
1015
|
-
return jsx(Dialog, {
|
|
1919
|
+
return jsxs(Fragment, { children: [jsx(Dialog, {
|
|
1016
1920
|
open,
|
|
1017
1921
|
onOpenChange: (next) => {
|
|
1018
1922
|
if (!next) service.close();
|
|
@@ -1026,11 +1930,21 @@ function SettingsSurface(props) {
|
|
|
1026
1930
|
children: [jsxs("header", {
|
|
1027
1931
|
...part("settings", "header"),
|
|
1028
1932
|
className: "snap-settings-header",
|
|
1029
|
-
children: [jsx(DialogTitle, { children: "设置" }),
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1933
|
+
children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
|
|
1934
|
+
style: {
|
|
1935
|
+
display: "flex",
|
|
1936
|
+
alignItems: "center",
|
|
1937
|
+
gap: 4
|
|
1938
|
+
},
|
|
1939
|
+
children: [jsx(IconButton, {
|
|
1940
|
+
icon: jsx(GearIcon, {}),
|
|
1941
|
+
label: "配置插件源",
|
|
1942
|
+
onClick: () => setFeedOpen(true)
|
|
1943
|
+
}), jsx(IconButton, {
|
|
1944
|
+
icon: jsx(CloseIcon, {}),
|
|
1945
|
+
label: "关闭",
|
|
1946
|
+
onClick: () => service.close()
|
|
1947
|
+
})]
|
|
1034
1948
|
})]
|
|
1035
1949
|
}), jsxs("div", {
|
|
1036
1950
|
...part("settings", "body"),
|
|
@@ -1063,10 +1977,7 @@ function SettingsSurface(props) {
|
|
|
1063
1977
|
...part("settings", "content"),
|
|
1064
1978
|
className: "snap-settings-content",
|
|
1065
1979
|
"data-active-page": activeId,
|
|
1066
|
-
children: active === void 0 ? jsx(EmptyState, {
|
|
1067
|
-
title: "暂无设置页",
|
|
1068
|
-
description: "安装或启用一个带设置页的插件后,它会出现在这里。"
|
|
1069
|
-
}) : jsx(SettingsPageBoundary, {
|
|
1980
|
+
children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
|
|
1070
1981
|
page: active.id,
|
|
1071
1982
|
children: active.render()
|
|
1072
1983
|
})
|
|
@@ -1074,7 +1985,11 @@ function SettingsSurface(props) {
|
|
|
1074
1985
|
})]
|
|
1075
1986
|
})
|
|
1076
1987
|
})
|
|
1077
|
-
})
|
|
1988
|
+
}), jsx(PluginFeedDialog, {
|
|
1989
|
+
ctx,
|
|
1990
|
+
open: feedOpen,
|
|
1991
|
+
onOpenChange: setFeedOpen
|
|
1992
|
+
})] });
|
|
1078
1993
|
}
|
|
1079
1994
|
/** Mount the settings registry and its default slot contributions. */
|
|
1080
1995
|
const settingsPlugin = {
|
|
@@ -1178,7 +2093,10 @@ const settingsPlugin = {
|
|
|
1178
2093
|
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
|
|
1179
2094
|
id: "settings.default-surface",
|
|
1180
2095
|
order: 0,
|
|
1181
|
-
render: () => jsx(SettingsSurface, {
|
|
2096
|
+
render: () => jsx(SettingsSurface, {
|
|
2097
|
+
service,
|
|
2098
|
+
ctx
|
|
2099
|
+
})
|
|
1182
2100
|
});
|
|
1183
2101
|
}
|
|
1184
2102
|
};
|