@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/runtime.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { attachBallDrag as attachBallDrag$1 } from "@snap-rail/client-kernel";
|
|
2
3
|
import { rpcErrorText, subscribeFrame } from "@snap-rail/connection";
|
|
3
4
|
import { settingsChangedSchema } from "@snap-rail/station-rpc/contract";
|
|
4
5
|
import { Context } from "@snap-rail/cordis";
|
|
5
6
|
import { TimerService } from "@snap-rail/cordis-plugin-timer";
|
|
6
7
|
import { shellContract } from "@snap-rail/shell/contract";
|
|
7
|
-
import { Component, createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
|
|
8
|
+
import { Component, createContext, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
8
9
|
import { createRoot } from "react-dom/client";
|
|
10
|
+
import "@radix-ui/react-separator";
|
|
9
11
|
import { Slot as Slot$1 } from "@radix-ui/react-slot";
|
|
10
12
|
import "@radix-ui/react-checkbox";
|
|
11
13
|
import "@radix-ui/react-label";
|
|
@@ -14,7 +16,15 @@ import "@radix-ui/react-select";
|
|
|
14
16
|
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
|
15
17
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
16
18
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
17
|
-
import "
|
|
19
|
+
import "react-hook-form";
|
|
20
|
+
import "@hookform/resolvers/zod";
|
|
21
|
+
import "@radix-ui/react-scroll-area";
|
|
22
|
+
import "@radix-ui/react-dropdown-menu";
|
|
23
|
+
import "@radix-ui/react-popover";
|
|
24
|
+
import * as ToastPrimitive from "@radix-ui/react-toast";
|
|
25
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
26
|
+
import "@radix-ui/react-slider";
|
|
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. */
|
|
@@ -324,7 +444,7 @@ function AppShell({ header, sidebar, footer, className, style, children }) {
|
|
|
324
444
|
});
|
|
325
445
|
}
|
|
326
446
|
/** A page body with its own header/actions anatomy. */
|
|
327
|
-
function Page({ header, actions, title, description, className, style, children }) {
|
|
447
|
+
function Page({ header, actions, title, titleExtra, description, className, style, children }) {
|
|
328
448
|
return jsxs("div", {
|
|
329
449
|
...part("page", "root"),
|
|
330
450
|
className: cn("snap-page", className),
|
|
@@ -350,9 +470,19 @@ function Page({ header, actions, title, description, className, style, children
|
|
|
350
470
|
justifyContent: "space-between",
|
|
351
471
|
gap: space("md")
|
|
352
472
|
},
|
|
353
|
-
children: [
|
|
354
|
-
|
|
355
|
-
|
|
473
|
+
children: [jsxs("div", {
|
|
474
|
+
style: {
|
|
475
|
+
display: "flex",
|
|
476
|
+
alignItems: "center",
|
|
477
|
+
gap: space("sm")
|
|
478
|
+
},
|
|
479
|
+
children: [title !== void 0 && jsx("div", {
|
|
480
|
+
...part("page", "title"),
|
|
481
|
+
children: title
|
|
482
|
+
}), titleExtra !== void 0 && jsx("div", {
|
|
483
|
+
...part("page", "title-extra"),
|
|
484
|
+
children: titleExtra
|
|
485
|
+
})]
|
|
356
486
|
}), actions !== void 0 && jsx("div", {
|
|
357
487
|
...part("page", "actions"),
|
|
358
488
|
children: actions
|
|
@@ -409,6 +539,84 @@ function Section({ title, description, actions, className, style, children }) {
|
|
|
409
539
|
});
|
|
410
540
|
}
|
|
411
541
|
//#endregion
|
|
542
|
+
//#region lib/types/components/overlay.js
|
|
543
|
+
/** The tooltip provider; the runtime mounts one, pages only need it standalone. */
|
|
544
|
+
function TooltipProvider(props) {
|
|
545
|
+
return jsx(TooltipPrimitive.Provider, { ...props });
|
|
546
|
+
}
|
|
547
|
+
let toastRecords = [];
|
|
548
|
+
const toastListeners = /* @__PURE__ */ new Set();
|
|
549
|
+
function toastEmit() {
|
|
550
|
+
for (const listener of toastListeners) listener();
|
|
551
|
+
}
|
|
552
|
+
function toastDismiss(id) {
|
|
553
|
+
toastRecords = toastRecords.filter((record) => record.id !== id);
|
|
554
|
+
toastEmit();
|
|
555
|
+
}
|
|
556
|
+
/** The runtime-mounted viewport: renders the shared toast queue. Pages never
|
|
557
|
+
* mount this themselves — the runtime provides one per surface root. */
|
|
558
|
+
function Toaster(props) {
|
|
559
|
+
const records = useSyncExternalStore((onStoreChange) => {
|
|
560
|
+
toastListeners.add(onStoreChange);
|
|
561
|
+
return () => toastListeners.delete(onStoreChange);
|
|
562
|
+
}, () => toastRecords, () => toastRecords);
|
|
563
|
+
return jsxs(ToastPrimitive.Provider, {
|
|
564
|
+
...props,
|
|
565
|
+
children: [records.map((record) => jsxs(ToastPrimitive.Root, {
|
|
566
|
+
...part("toast", "root"),
|
|
567
|
+
className: "snap-toast",
|
|
568
|
+
"data-intent": record.intent ?? "neutral",
|
|
569
|
+
duration: record.duration ?? 5e3,
|
|
570
|
+
onOpenChange: (open) => {
|
|
571
|
+
if (!open) toastDismiss(record.id);
|
|
572
|
+
},
|
|
573
|
+
children: [
|
|
574
|
+
jsx(ToastTitle, { children: record.title }),
|
|
575
|
+
record.description !== void 0 && jsx(ToastDescription, { children: record.description }),
|
|
576
|
+
jsx(ToastClose, { "aria-label": "关闭" })
|
|
577
|
+
]
|
|
578
|
+
}, record.id)), jsx(ToastViewport, {})]
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
/** A toast title with its part tag. */
|
|
582
|
+
function ToastTitle({ className, children, ...props }) {
|
|
583
|
+
return jsx(ToastPrimitive.Title, {
|
|
584
|
+
...part("toast", "title"),
|
|
585
|
+
className: cn("snap-toast-title", className),
|
|
586
|
+
...props,
|
|
587
|
+
children
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
/** A toast description with its part tag. */
|
|
591
|
+
function ToastDescription({ className, children, ...props }) {
|
|
592
|
+
return jsx(ToastPrimitive.Description, {
|
|
593
|
+
...part("toast", "description"),
|
|
594
|
+
className: cn("snap-toast-description", className),
|
|
595
|
+
...props,
|
|
596
|
+
children
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
/** A toast dismissal button. */
|
|
600
|
+
function ToastClose({ className, children, ...props }) {
|
|
601
|
+
return jsx(ToastPrimitive.Close, {
|
|
602
|
+
...part("toast", "close"),
|
|
603
|
+
className: cn("snap-toast-close", className),
|
|
604
|
+
...props,
|
|
605
|
+
children: children ?? jsx("span", {
|
|
606
|
+
"aria-hidden": "true",
|
|
607
|
+
children: "×"
|
|
608
|
+
})
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
/** The toast viewport; only the runtime's {@link Toaster} mounts one. */
|
|
612
|
+
function ToastViewport({ className, ...props }) {
|
|
613
|
+
return jsx(ToastPrimitive.Viewport, {
|
|
614
|
+
...part("toast", "viewport"),
|
|
615
|
+
className: cn("snap-toast-viewport", className),
|
|
616
|
+
...props
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
//#endregion
|
|
412
620
|
//#region lib/types/components/surface.js
|
|
413
621
|
/** A semantic table. */
|
|
414
622
|
function Table({ className, children, ...props }) {
|
|
@@ -874,7 +1082,6 @@ function FallbackShell(props) {
|
|
|
874
1082
|
},
|
|
875
1083
|
children: jsx(EmptyState, {
|
|
876
1084
|
title: "尚未激活业务套件",
|
|
877
|
-
description: "打开设置的「插件管理」页,安装并启用一个业务套件;驱动也在同一处安装。",
|
|
878
1085
|
action: jsx(Button, {
|
|
879
1086
|
intent: "primary",
|
|
880
1087
|
onClick: () => props.ctx.settings.open("plugins"),
|
|
@@ -917,6 +1124,255 @@ const fallbackPlugin = {
|
|
|
917
1124
|
}
|
|
918
1125
|
};
|
|
919
1126
|
//#endregion
|
|
1127
|
+
//#region lib/types/skins.js
|
|
1128
|
+
/** The factory day theme id (cobalt palette, light surfaces). */
|
|
1129
|
+
const DEFAULT_LIGHT_ID = "default-light";
|
|
1130
|
+
/** The factory night theme id (cobalt palette, dark surfaces). */
|
|
1131
|
+
const DEFAULT_DARK_ID = "default-dark";
|
|
1132
|
+
/** The contributor label for the factory themes. */
|
|
1133
|
+
const FACTORY_CALLER = "@snap-rail/ui";
|
|
1134
|
+
const COBALT_DARK_TOKENS = {
|
|
1135
|
+
colorBg: "#0b0f14",
|
|
1136
|
+
colorSurface: "#11161d",
|
|
1137
|
+
colorSurfaceRaised: "#161b22",
|
|
1138
|
+
colorText: "#ced8e3",
|
|
1139
|
+
colorMuted: "#8b949e",
|
|
1140
|
+
colorPrimary: "#4a6cff",
|
|
1141
|
+
colorOnPrimary: "#ffffff",
|
|
1142
|
+
colorDanger: "#f85149",
|
|
1143
|
+
colorSuccess: "#3fb950",
|
|
1144
|
+
colorWarning: "#d29922",
|
|
1145
|
+
colorBorder: "#1f2933",
|
|
1146
|
+
colorFocus: "#4a6cff",
|
|
1147
|
+
chart1: "#4a6cff",
|
|
1148
|
+
chart2: "#3147a1",
|
|
1149
|
+
chart3: "#667fcd",
|
|
1150
|
+
chart4: "#7d8fa5",
|
|
1151
|
+
chart5: "#55677c",
|
|
1152
|
+
chart6: "#33414f",
|
|
1153
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
1154
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
1155
|
+
textXs: "13px",
|
|
1156
|
+
textSm: "15px",
|
|
1157
|
+
textMd: "17px",
|
|
1158
|
+
textLg: "20px",
|
|
1159
|
+
textXl: "24px",
|
|
1160
|
+
weightNormal: "400",
|
|
1161
|
+
weightMedium: "500",
|
|
1162
|
+
weightStrong: "600",
|
|
1163
|
+
leadingTight: "1.2",
|
|
1164
|
+
leadingNormal: "1.55",
|
|
1165
|
+
spaceXs: "4px",
|
|
1166
|
+
spaceSm: "8px",
|
|
1167
|
+
spaceMd: "12px",
|
|
1168
|
+
spaceLg: "20px",
|
|
1169
|
+
spaceXl: "32px",
|
|
1170
|
+
radiusSm: "6px",
|
|
1171
|
+
radiusMd: "8px",
|
|
1172
|
+
radiusLg: "12px",
|
|
1173
|
+
radiusFull: "999px",
|
|
1174
|
+
borderWidth: "1px",
|
|
1175
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
|
|
1176
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
|
|
1177
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
|
|
1178
|
+
durationFast: "120ms",
|
|
1179
|
+
durationNormal: "180ms",
|
|
1180
|
+
durationSlow: "280ms",
|
|
1181
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
1182
|
+
zOverlay: "50",
|
|
1183
|
+
zModal: "60",
|
|
1184
|
+
zToast: "70",
|
|
1185
|
+
controlHeightSm: "40px",
|
|
1186
|
+
controlHeightMd: "48px",
|
|
1187
|
+
controlHeightLg: "56px",
|
|
1188
|
+
density: "comfortable"
|
|
1189
|
+
};
|
|
1190
|
+
/** The factory day theme. Always registered; never the first paint though — the night theme is. */
|
|
1191
|
+
const DEFAULT_LIGHT = {
|
|
1192
|
+
id: DEFAULT_LIGHT_ID,
|
|
1193
|
+
title: "钴蓝·白天",
|
|
1194
|
+
tokens: {
|
|
1195
|
+
colorBg: "#e4e9ef",
|
|
1196
|
+
colorSurface: "#f3f6f9",
|
|
1197
|
+
colorSurfaceRaised: "#ffffff",
|
|
1198
|
+
colorText: "#26323e",
|
|
1199
|
+
colorMuted: "#5d6d7e",
|
|
1200
|
+
colorPrimary: "#3857e8",
|
|
1201
|
+
colorOnPrimary: "#ffffff",
|
|
1202
|
+
colorDanger: "#dc2626",
|
|
1203
|
+
colorSuccess: "#15803d",
|
|
1204
|
+
colorWarning: "#b45309",
|
|
1205
|
+
colorBorder: "#c7d0da",
|
|
1206
|
+
colorFocus: "#3857e8",
|
|
1207
|
+
chart1: "#3857e8",
|
|
1208
|
+
chart2: "#7088ee",
|
|
1209
|
+
chart3: "#667dd0",
|
|
1210
|
+
chart4: "#94a3b8",
|
|
1211
|
+
chart5: "#b3c0cd",
|
|
1212
|
+
chart6: "#ccd6e0",
|
|
1213
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
1214
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
1215
|
+
textXs: "13px",
|
|
1216
|
+
textSm: "15px",
|
|
1217
|
+
textMd: "17px",
|
|
1218
|
+
textLg: "20px",
|
|
1219
|
+
textXl: "24px",
|
|
1220
|
+
weightNormal: "400",
|
|
1221
|
+
weightMedium: "500",
|
|
1222
|
+
weightStrong: "600",
|
|
1223
|
+
leadingTight: "1.2",
|
|
1224
|
+
leadingNormal: "1.55",
|
|
1225
|
+
spaceXs: "4px",
|
|
1226
|
+
spaceSm: "8px",
|
|
1227
|
+
spaceMd: "12px",
|
|
1228
|
+
spaceLg: "20px",
|
|
1229
|
+
spaceXl: "32px",
|
|
1230
|
+
radiusSm: "6px",
|
|
1231
|
+
radiusMd: "8px",
|
|
1232
|
+
radiusLg: "12px",
|
|
1233
|
+
radiusFull: "999px",
|
|
1234
|
+
borderWidth: "1px",
|
|
1235
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
|
|
1236
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
|
|
1237
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
|
|
1238
|
+
durationFast: "120ms",
|
|
1239
|
+
durationNormal: "180ms",
|
|
1240
|
+
durationSlow: "280ms",
|
|
1241
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
1242
|
+
zOverlay: "50",
|
|
1243
|
+
zModal: "60",
|
|
1244
|
+
zToast: "70",
|
|
1245
|
+
controlHeightSm: "40px",
|
|
1246
|
+
controlHeightMd: "48px",
|
|
1247
|
+
controlHeightLg: "56px",
|
|
1248
|
+
density: "comfortable"
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
/** The factory night theme and the registry's fallback. */
|
|
1252
|
+
const DEFAULT_DARK = {
|
|
1253
|
+
id: DEFAULT_DARK_ID,
|
|
1254
|
+
title: "钴蓝·黑夜",
|
|
1255
|
+
tokens: COBALT_DARK_TOKENS
|
|
1256
|
+
};
|
|
1257
|
+
/** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
|
|
1258
|
+
function skinTokenVar(key) {
|
|
1259
|
+
return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
|
|
1260
|
+
}
|
|
1261
|
+
/** Apply the active theme to the document root. */
|
|
1262
|
+
function applySkin(skin) {
|
|
1263
|
+
if (typeof document === "undefined") return;
|
|
1264
|
+
const root = document.documentElement;
|
|
1265
|
+
root.dataset["snapSkin"] = skin.id;
|
|
1266
|
+
for (const [key, value] of Object.entries(skin.tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
1267
|
+
}
|
|
1268
|
+
/** Mount the `ctx.skins` registry. */
|
|
1269
|
+
const skinsPlugin = {
|
|
1270
|
+
name: "snap-rail ui skins",
|
|
1271
|
+
apply(ctx) {
|
|
1272
|
+
const skins = /* @__PURE__ */ new Map();
|
|
1273
|
+
const callers = /* @__PURE__ */ new Map();
|
|
1274
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1275
|
+
const styleTags = /* @__PURE__ */ new Map();
|
|
1276
|
+
let activeId = DEFAULT_DARK_ID;
|
|
1277
|
+
let revision = 0;
|
|
1278
|
+
skins.set(DEFAULT_LIGHT_ID, DEFAULT_LIGHT);
|
|
1279
|
+
callers.set(DEFAULT_LIGHT_ID, FACTORY_CALLER);
|
|
1280
|
+
skins.set(DEFAULT_DARK_ID, DEFAULT_DARK);
|
|
1281
|
+
callers.set(DEFAULT_DARK_ID, FACTORY_CALLER);
|
|
1282
|
+
const notify = () => {
|
|
1283
|
+
revision += 1;
|
|
1284
|
+
for (const listener of listeners) listener();
|
|
1285
|
+
ctx.emit("skins/changed");
|
|
1286
|
+
};
|
|
1287
|
+
const ensureStyleTag = (skin) => {
|
|
1288
|
+
if (typeof document === "undefined" || skin.css === void 0) return;
|
|
1289
|
+
if (styleTags.has(skin.id)) return;
|
|
1290
|
+
const tag = document.createElement("style");
|
|
1291
|
+
tag.dataset["snapSkinStyle"] = skin.id;
|
|
1292
|
+
tag.textContent = skin.css;
|
|
1293
|
+
document.head.append(tag);
|
|
1294
|
+
styleTags.set(skin.id, tag);
|
|
1295
|
+
};
|
|
1296
|
+
const refresh = () => {
|
|
1297
|
+
const skin = skins.get(activeId) ?? DEFAULT_DARK;
|
|
1298
|
+
activeId = skin.id;
|
|
1299
|
+
ensureStyleTag(skin);
|
|
1300
|
+
applySkin(skin);
|
|
1301
|
+
notify();
|
|
1302
|
+
};
|
|
1303
|
+
ctx.provide("skins", {
|
|
1304
|
+
register(caller, skin) {
|
|
1305
|
+
skins.set(skin.id, skin);
|
|
1306
|
+
callers.set(skin.id, caller.fiber.name);
|
|
1307
|
+
refresh();
|
|
1308
|
+
const remove = () => {
|
|
1309
|
+
if (!skins.delete(skin.id)) return;
|
|
1310
|
+
callers.delete(skin.id);
|
|
1311
|
+
const tag = styleTags.get(skin.id);
|
|
1312
|
+
if (tag !== void 0) {
|
|
1313
|
+
tag.remove();
|
|
1314
|
+
styleTags.delete(skin.id);
|
|
1315
|
+
}
|
|
1316
|
+
if (activeId === skin.id) activeId = DEFAULT_DARK_ID;
|
|
1317
|
+
refresh();
|
|
1318
|
+
};
|
|
1319
|
+
caller.effect(() => remove);
|
|
1320
|
+
return remove;
|
|
1321
|
+
},
|
|
1322
|
+
activate(selection) {
|
|
1323
|
+
let next = skins.has(selection) ? selection : void 0;
|
|
1324
|
+
if (next === void 0) {
|
|
1325
|
+
for (const [id, owner] of callers) if (id !== selection && owner === selection && skins.has(id)) {
|
|
1326
|
+
next = id;
|
|
1327
|
+
break;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
if (next === void 0) return false;
|
|
1331
|
+
if (next === activeId) return true;
|
|
1332
|
+
activeId = next;
|
|
1333
|
+
refresh();
|
|
1334
|
+
return true;
|
|
1335
|
+
},
|
|
1336
|
+
list: () => [...skins.values()].map((skin) => ({
|
|
1337
|
+
id: skin.id,
|
|
1338
|
+
title: skin.title,
|
|
1339
|
+
caller: callers.get(skin.id) ?? FACTORY_CALLER
|
|
1340
|
+
})),
|
|
1341
|
+
active: () => skins.get(activeId) ?? DEFAULT_DARK,
|
|
1342
|
+
tokens: () => (skins.get(activeId) ?? DEFAULT_DARK).tokens,
|
|
1343
|
+
subscribe(listener) {
|
|
1344
|
+
listeners.add(listener);
|
|
1345
|
+
return () => {
|
|
1346
|
+
listeners.delete(listener);
|
|
1347
|
+
};
|
|
1348
|
+
},
|
|
1349
|
+
version: () => revision
|
|
1350
|
+
});
|
|
1351
|
+
refresh();
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
/** The React context carrying the skin service. */
|
|
1355
|
+
const SkinsContext = createContext(null);
|
|
1356
|
+
/** Provide the skin service to a renderer tree. */
|
|
1357
|
+
function SkinsProvider(props) {
|
|
1358
|
+
return jsx(SkinsContext.Provider, {
|
|
1359
|
+
value: props.service,
|
|
1360
|
+
children: props.children
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
/** Read the skin service. */
|
|
1364
|
+
function useSkins() {
|
|
1365
|
+
const service = useContext(SkinsContext);
|
|
1366
|
+
if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
|
|
1367
|
+
return service;
|
|
1368
|
+
}
|
|
1369
|
+
/** Re-render on theme changes and return the active theme id. */
|
|
1370
|
+
function useSkinId() {
|
|
1371
|
+
const service = useSkins();
|
|
1372
|
+
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
1373
|
+
return service.active().id;
|
|
1374
|
+
}
|
|
1375
|
+
//#endregion
|
|
920
1376
|
//#region lib/types/settings-pages/appearance.js
|
|
921
1377
|
const THEME_KEY = "ui.theme";
|
|
922
1378
|
const WINDOW_KEY = "ui.window";
|
|
@@ -965,24 +1421,21 @@ async function writeSetting(link, key, value) {
|
|
|
965
1421
|
/** The appearance/display page. */
|
|
966
1422
|
function AppearancePage() {
|
|
967
1423
|
const { link } = useClient();
|
|
968
|
-
const
|
|
1424
|
+
const skins = useSkins();
|
|
1425
|
+
const activeId = useSkinId();
|
|
1426
|
+
const [packages, setPackages] = useState([]);
|
|
969
1427
|
const [windowPreset, setWindowPreset] = useState(void 0);
|
|
970
1428
|
const [ballSize, setBallSize] = useState(128);
|
|
971
1429
|
const [ballEnabled, setBallEnabled] = useState(true);
|
|
972
|
-
const [ballDockable, setBallDockable] = useState(true);
|
|
973
1430
|
const [ballCollapse, setBallCollapse] = useState(true);
|
|
974
|
-
const [skins, setSkins] = useState([]);
|
|
975
1431
|
const [error, setError] = useState(void 0);
|
|
976
1432
|
const [busy, setBusy] = useState(false);
|
|
977
1433
|
useEffect(() => {
|
|
978
1434
|
Promise.all([
|
|
979
|
-
readSetting(link, THEME_KEY),
|
|
980
1435
|
readSetting(link, WINDOW_KEY),
|
|
981
1436
|
readSetting(link, BALL_KEY),
|
|
982
1437
|
link.call("plugins.list", {})
|
|
983
|
-
]).then(([
|
|
984
|
-
const themeMode = theme?.mode;
|
|
985
|
-
if (themeMode === "system" || themeMode === "light" || themeMode === "dark") setMode(themeMode);
|
|
1438
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
986
1439
|
const windowProfile = windowRow;
|
|
987
1440
|
if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
|
|
988
1441
|
const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
@@ -991,9 +1444,8 @@ function AppearancePage() {
|
|
|
991
1444
|
const ballProfile = ballRow;
|
|
992
1445
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
|
|
993
1446
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
|
|
994
|
-
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.dockable === "boolean") setBallDockable(ballProfile.dockable);
|
|
995
1447
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
|
|
996
|
-
if (plugins.ok)
|
|
1448
|
+
if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
|
|
997
1449
|
name: plugin.packageName,
|
|
998
1450
|
title: plugin.title ?? plugin.packageName,
|
|
999
1451
|
enabled: plugin.enabled
|
|
@@ -1001,19 +1453,7 @@ function AppearancePage() {
|
|
|
1001
1453
|
}).catch((cause) => {
|
|
1002
1454
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1003
1455
|
});
|
|
1004
|
-
return subscribeFrame(link, "settings/changed", settingsChangedSchema, (change) => {
|
|
1005
|
-
if (change.key === THEME_KEY) {
|
|
1006
|
-
const next = change.value?.mode;
|
|
1007
|
-
if (next === "system" || next === "light" || next === "dark") setMode(next);
|
|
1008
|
-
}
|
|
1009
|
-
});
|
|
1010
1456
|
}, [link]);
|
|
1011
|
-
const saveTheme = (next) => {
|
|
1012
|
-
setMode(next);
|
|
1013
|
-
writeSetting(link, THEME_KEY, { mode: next }).catch((cause) => {
|
|
1014
|
-
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1015
|
-
});
|
|
1016
|
-
};
|
|
1017
1457
|
const saveWindow = (width, height, label) => {
|
|
1018
1458
|
setWindowPreset(label);
|
|
1019
1459
|
writeSetting(link, WINDOW_KEY, {
|
|
@@ -1035,31 +1475,45 @@ function AppearancePage() {
|
|
|
1035
1475
|
const next = {
|
|
1036
1476
|
size: patch.size ?? ballSize,
|
|
1037
1477
|
enabled: patch.enabled ?? ballEnabled,
|
|
1038
|
-
dockable: patch.dockable ?? ballDockable,
|
|
1039
1478
|
collapse: patch.collapse ?? ballCollapse
|
|
1040
1479
|
};
|
|
1041
1480
|
if (patch.size !== void 0) setBallSize(patch.size);
|
|
1042
1481
|
if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
|
|
1043
|
-
if (patch.dockable !== void 0) setBallDockable(patch.dockable);
|
|
1044
1482
|
if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
|
|
1045
1483
|
writeSetting(link, BALL_KEY, next).catch((cause) => {
|
|
1046
1484
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1047
1485
|
});
|
|
1048
1486
|
};
|
|
1049
|
-
const
|
|
1487
|
+
const tabs = [...skins.list().map((row) => ({
|
|
1488
|
+
id: row.id,
|
|
1489
|
+
title: row.title
|
|
1490
|
+
})), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
|
|
1491
|
+
id: pkg.name,
|
|
1492
|
+
title: pkg.title,
|
|
1493
|
+
enable: pkg.name
|
|
1494
|
+
}))];
|
|
1495
|
+
const selectTheme = (tab) => {
|
|
1496
|
+
if (busy) return;
|
|
1497
|
+
if (tab.enable === void 0) {
|
|
1498
|
+
writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
|
|
1499
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1500
|
+
});
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1050
1503
|
setBusy(true);
|
|
1051
1504
|
link.call("plugins.set-enabled", {
|
|
1052
|
-
name:
|
|
1053
|
-
enabled:
|
|
1505
|
+
name: tab.enable,
|
|
1506
|
+
enabled: true
|
|
1054
1507
|
}).then((result) => {
|
|
1055
1508
|
if (!result.ok) {
|
|
1056
1509
|
setError(rpcErrorText(result.error));
|
|
1057
1510
|
return;
|
|
1058
1511
|
}
|
|
1059
|
-
|
|
1060
|
-
...
|
|
1061
|
-
enabled:
|
|
1062
|
-
} :
|
|
1512
|
+
setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
|
|
1513
|
+
...pkg,
|
|
1514
|
+
enabled: true
|
|
1515
|
+
} : pkg));
|
|
1516
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
1063
1517
|
}).catch((cause) => {
|
|
1064
1518
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1065
1519
|
}).finally(() => {
|
|
@@ -1068,83 +1522,34 @@ function AppearancePage() {
|
|
|
1068
1522
|
};
|
|
1069
1523
|
return jsx(Page, {
|
|
1070
1524
|
title: "外观与显示",
|
|
1071
|
-
description: "
|
|
1525
|
+
description: "主题、主窗口尺寸和悬浮球外观。",
|
|
1072
1526
|
children: jsxs(Stack, {
|
|
1073
1527
|
gap: "lg",
|
|
1074
1528
|
children: [
|
|
1075
|
-
error !== void 0 && jsx(
|
|
1076
|
-
|
|
1077
|
-
style: { color: "var(--snap-color-danger)" },
|
|
1529
|
+
error !== void 0 && jsx(Alert, {
|
|
1530
|
+
intent: "danger",
|
|
1078
1531
|
children: error
|
|
1079
1532
|
}),
|
|
1080
1533
|
jsx(Section, {
|
|
1081
|
-
title: "
|
|
1534
|
+
title: "主题",
|
|
1082
1535
|
children: jsx(Tabs, {
|
|
1083
|
-
value:
|
|
1084
|
-
onValueChange: (value) =>
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
}),
|
|
1096
|
-
jsx(TabsTrigger, {
|
|
1097
|
-
value: "dark",
|
|
1098
|
-
children: "黑夜"
|
|
1099
|
-
})
|
|
1100
|
-
]
|
|
1536
|
+
value: activeId,
|
|
1537
|
+
onValueChange: (value) => {
|
|
1538
|
+
const tab = tabs.find((item) => item.id === value);
|
|
1539
|
+
if (tab !== void 0) selectTheme(tab);
|
|
1540
|
+
},
|
|
1541
|
+
children: jsx(TabsList, {
|
|
1542
|
+
"aria-label": "主题",
|
|
1543
|
+
children: tabs.map((tab) => jsx(TabsTrigger, {
|
|
1544
|
+
value: tab.id,
|
|
1545
|
+
disabled: busy,
|
|
1546
|
+
children: tab.title
|
|
1547
|
+
}, tab.id))
|
|
1101
1548
|
})
|
|
1102
1549
|
})
|
|
1103
1550
|
}),
|
|
1104
|
-
jsx(Section, {
|
|
1105
|
-
title: "界面皮肤",
|
|
1106
|
-
description: "皮肤由独立插件提供;启用后需要重启终端。",
|
|
1107
|
-
children: jsxs(Stack, {
|
|
1108
|
-
gap: "sm",
|
|
1109
|
-
children: [jsxs(Row, {
|
|
1110
|
-
gap: "sm",
|
|
1111
|
-
align: "center",
|
|
1112
|
-
children: [jsx(Badge, {
|
|
1113
|
-
intent: "success",
|
|
1114
|
-
children: "默认(内置)"
|
|
1115
|
-
}), jsx("span", {
|
|
1116
|
-
style: {
|
|
1117
|
-
color: "var(--snap-color-muted)",
|
|
1118
|
-
fontSize: "var(--snap-text-sm)"
|
|
1119
|
-
},
|
|
1120
|
-
children: "工业钴蓝,始终可用"
|
|
1121
|
-
})]
|
|
1122
|
-
}), skins.length === 0 ? jsx("span", {
|
|
1123
|
-
style: { color: "var(--snap-color-muted)" },
|
|
1124
|
-
children: "尚未安装其他皮肤插件。"
|
|
1125
|
-
}) : skins.map((skin) => jsxs(Row, {
|
|
1126
|
-
gap: "sm",
|
|
1127
|
-
align: "center",
|
|
1128
|
-
children: [
|
|
1129
|
-
jsx("span", { children: skin.title }),
|
|
1130
|
-
jsx(Badge, {
|
|
1131
|
-
intent: skin.enabled ? "success" : "neutral",
|
|
1132
|
-
children: skin.enabled ? "已启用" : "未启用"
|
|
1133
|
-
}),
|
|
1134
|
-
jsx(Button, {
|
|
1135
|
-
size: "sm",
|
|
1136
|
-
emphasis: "outline",
|
|
1137
|
-
disabled: busy,
|
|
1138
|
-
onClick: () => toggleSkin(skin),
|
|
1139
|
-
children: skin.enabled ? "停用" : "启用"
|
|
1140
|
-
})
|
|
1141
|
-
]
|
|
1142
|
-
}, skin.name))]
|
|
1143
|
-
})
|
|
1144
|
-
}),
|
|
1145
1551
|
jsx(Section, {
|
|
1146
1552
|
title: "主窗口",
|
|
1147
|
-
description: "布局/套件会声明推荐尺寸;这里的选择会覆盖布局推荐。",
|
|
1148
1553
|
children: jsxs(Stack, {
|
|
1149
1554
|
gap: "sm",
|
|
1150
1555
|
children: [jsxs(Row, {
|
|
@@ -1173,7 +1578,7 @@ function AppearancePage() {
|
|
|
1173
1578
|
}),
|
|
1174
1579
|
jsx(Section, {
|
|
1175
1580
|
title: "悬浮球",
|
|
1176
|
-
description: "
|
|
1581
|
+
description: "球面尺寸与停泊行为。",
|
|
1177
1582
|
children: jsxs(Stack, {
|
|
1178
1583
|
gap: "md",
|
|
1179
1584
|
children: [jsx(Row, {
|
|
@@ -1191,23 +1596,15 @@ function AppearancePage() {
|
|
|
1191
1596
|
gap: "lg",
|
|
1192
1597
|
wrap: true,
|
|
1193
1598
|
align: "center",
|
|
1194
|
-
children: [
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
onCheckedChange: (dockable) => saveBall({ dockable })
|
|
1204
|
-
}),
|
|
1205
|
-
jsx(Switch, {
|
|
1206
|
-
label: "贴边后收起",
|
|
1207
|
-
checked: ballCollapse,
|
|
1208
|
-
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
1209
|
-
})
|
|
1210
|
-
]
|
|
1599
|
+
children: [jsx(Switch, {
|
|
1600
|
+
label: "启用悬浮球",
|
|
1601
|
+
checked: ballEnabled,
|
|
1602
|
+
onCheckedChange: (enabled) => saveBall({ enabled })
|
|
1603
|
+
}), jsx(Switch, {
|
|
1604
|
+
label: "允许贴边收起",
|
|
1605
|
+
checked: ballCollapse,
|
|
1606
|
+
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
1607
|
+
})]
|
|
1211
1608
|
})]
|
|
1212
1609
|
})
|
|
1213
1610
|
})
|
|
@@ -1216,7 +1613,157 @@ function AppearancePage() {
|
|
|
1216
1613
|
});
|
|
1217
1614
|
}
|
|
1218
1615
|
//#endregion
|
|
1616
|
+
//#region lib/types/settings-pages/plugin-feed.js
|
|
1617
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
1618
|
+
function PluginFeedDialog(props) {
|
|
1619
|
+
const { open } = props;
|
|
1620
|
+
const link = props.ctx.client.link;
|
|
1621
|
+
const [urls, setUrls] = useState([]);
|
|
1622
|
+
const [draft, setDraft] = useState("");
|
|
1623
|
+
const [error, setError] = useState(void 0);
|
|
1624
|
+
useEffect(() => {
|
|
1625
|
+
if (!open) return;
|
|
1626
|
+
link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
|
|
1627
|
+
if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
|
|
1628
|
+
}).catch(() => void 0);
|
|
1629
|
+
}, [open, link]);
|
|
1630
|
+
const save = () => {
|
|
1631
|
+
for (const url of urls) try {
|
|
1632
|
+
const parsed = new URL(url);
|
|
1633
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
1634
|
+
} catch {
|
|
1635
|
+
setError("插件源地址需要以 http(s) 开头");
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
setError(void 0);
|
|
1639
|
+
link.call("settings.set", {
|
|
1640
|
+
key: PLUGINS_FEED_URLS_KEY,
|
|
1641
|
+
value: urls
|
|
1642
|
+
}).then((result) => {
|
|
1643
|
+
if (!result.ok) {
|
|
1644
|
+
setError(rpcErrorText(result.error));
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
props.onOpenChange(false);
|
|
1648
|
+
}).catch((cause) => setError(String(cause)));
|
|
1649
|
+
};
|
|
1650
|
+
const append = () => {
|
|
1651
|
+
const value = draft.trim();
|
|
1652
|
+
if (value === "") return;
|
|
1653
|
+
try {
|
|
1654
|
+
const parsed = new URL(value);
|
|
1655
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
1656
|
+
} catch {
|
|
1657
|
+
setError("请填写 http(s) 开头的插件源地址");
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
setError(void 0);
|
|
1661
|
+
setDraft("");
|
|
1662
|
+
setUrls((current) => current.includes(value) ? current : [...current, value]);
|
|
1663
|
+
};
|
|
1664
|
+
return jsx(Dialog, {
|
|
1665
|
+
open,
|
|
1666
|
+
onOpenChange: props.onOpenChange,
|
|
1667
|
+
children: jsxs(DialogContent, {
|
|
1668
|
+
presentation: "modal",
|
|
1669
|
+
"aria-describedby": void 0,
|
|
1670
|
+
children: [
|
|
1671
|
+
jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
|
|
1672
|
+
jsx(DialogBody, { children: jsxs(Stack, {
|
|
1673
|
+
gap: "sm",
|
|
1674
|
+
children: [
|
|
1675
|
+
urls.length === 0 && jsx("div", {
|
|
1676
|
+
style: {
|
|
1677
|
+
fontSize: "var(--snap-text-xs)",
|
|
1678
|
+
color: "var(--snap-color-muted)"
|
|
1679
|
+
},
|
|
1680
|
+
children: "尚未添加自定义源(当前使用出厂默认源)。"
|
|
1681
|
+
}),
|
|
1682
|
+
urls.map((url, index) => jsxs("div", {
|
|
1683
|
+
style: {
|
|
1684
|
+
display: "flex",
|
|
1685
|
+
gap: "var(--snap-space-sm)",
|
|
1686
|
+
alignItems: "center"
|
|
1687
|
+
},
|
|
1688
|
+
children: [jsx("span", {
|
|
1689
|
+
style: {
|
|
1690
|
+
flex: 1,
|
|
1691
|
+
minWidth: 0,
|
|
1692
|
+
overflow: "hidden",
|
|
1693
|
+
textOverflow: "ellipsis",
|
|
1694
|
+
whiteSpace: "nowrap",
|
|
1695
|
+
fontSize: "var(--snap-text-xs)"
|
|
1696
|
+
},
|
|
1697
|
+
children: url
|
|
1698
|
+
}), jsx(Button, {
|
|
1699
|
+
intent: "neutral",
|
|
1700
|
+
emphasis: "ghost",
|
|
1701
|
+
size: "sm",
|
|
1702
|
+
"aria-label": `移除 ${url}`,
|
|
1703
|
+
onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
|
|
1704
|
+
children: "✕"
|
|
1705
|
+
})]
|
|
1706
|
+
}, url)),
|
|
1707
|
+
jsxs("div", {
|
|
1708
|
+
style: {
|
|
1709
|
+
display: "flex",
|
|
1710
|
+
gap: "var(--snap-space-sm)",
|
|
1711
|
+
width: "100%"
|
|
1712
|
+
},
|
|
1713
|
+
children: [jsx(Input, {
|
|
1714
|
+
value: draft,
|
|
1715
|
+
placeholder: "https://…",
|
|
1716
|
+
style: {
|
|
1717
|
+
flex: 1,
|
|
1718
|
+
minWidth: 0
|
|
1719
|
+
},
|
|
1720
|
+
onChange: (event) => setDraft(event.target.value),
|
|
1721
|
+
onKeyDown: (event) => {
|
|
1722
|
+
if (event.key === "Enter") append();
|
|
1723
|
+
}
|
|
1724
|
+
}), jsx(Button, {
|
|
1725
|
+
intent: "neutral",
|
|
1726
|
+
emphasis: "outline",
|
|
1727
|
+
onClick: append,
|
|
1728
|
+
children: "添加源"
|
|
1729
|
+
})]
|
|
1730
|
+
}),
|
|
1731
|
+
error !== void 0 && jsx("div", {
|
|
1732
|
+
role: "alert",
|
|
1733
|
+
style: {
|
|
1734
|
+
color: "var(--snap-color-danger)",
|
|
1735
|
+
fontSize: "var(--snap-text-sm)"
|
|
1736
|
+
},
|
|
1737
|
+
children: error
|
|
1738
|
+
})
|
|
1739
|
+
]
|
|
1740
|
+
}) }),
|
|
1741
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
1742
|
+
intent: "neutral",
|
|
1743
|
+
emphasis: "outline",
|
|
1744
|
+
onClick: () => props.onOpenChange(false),
|
|
1745
|
+
children: "取消"
|
|
1746
|
+
}), jsx(Button, {
|
|
1747
|
+
intent: "primary",
|
|
1748
|
+
"data-plugins-feed-save": true,
|
|
1749
|
+
onClick: save,
|
|
1750
|
+
children: "保存"
|
|
1751
|
+
})] })
|
|
1752
|
+
]
|
|
1753
|
+
})
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
//#endregion
|
|
1219
1757
|
//#region lib/types/settings-pages/plugins.js
|
|
1758
|
+
/** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
|
|
1759
|
+
* Electron or in tests. Inlined rather than imported from the app-internal
|
|
1760
|
+
* kernel package: it never ships in the installer, and the packaged-app gate
|
|
1761
|
+
* refuses any shipped `@snap-rail/ui` lib that requires it. */
|
|
1762
|
+
function droppedZipPath(file) {
|
|
1763
|
+
const zipPathOf = globalThis.snapRail?.zipPathOf;
|
|
1764
|
+
if (typeof zipPathOf !== "function") return null;
|
|
1765
|
+
return zipPathOf(file);
|
|
1766
|
+
}
|
|
1220
1767
|
/** Human labels for the package kinds. */
|
|
1221
1768
|
const KIND_LABELS = {
|
|
1222
1769
|
skin: "界面风格",
|
|
@@ -1229,6 +1776,22 @@ const PROFILE_LABELS = {
|
|
|
1229
1776
|
integrated: "图表桥接",
|
|
1230
1777
|
custom: "自定义界面"
|
|
1231
1778
|
};
|
|
1779
|
+
/** Search rows shown before the tail is folded into a counter. */
|
|
1780
|
+
const SEARCH_ROW_CAP = 20;
|
|
1781
|
+
/** The plus glyph for the page's install entry. */
|
|
1782
|
+
function PlusIcon() {
|
|
1783
|
+
return jsx("svg", {
|
|
1784
|
+
viewBox: "0 0 24 24",
|
|
1785
|
+
width: "18",
|
|
1786
|
+
height: "18",
|
|
1787
|
+
fill: "none",
|
|
1788
|
+
stroke: "currentColor",
|
|
1789
|
+
strokeWidth: "2.4",
|
|
1790
|
+
strokeLinecap: "round",
|
|
1791
|
+
"aria-hidden": "true",
|
|
1792
|
+
children: jsx("path", { d: "M12 5v14M5 12h14" })
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1232
1795
|
/** Collapse entry rows into package rows (one master switch per package). */
|
|
1233
1796
|
function packageRows(plugins) {
|
|
1234
1797
|
const byPackage = /* @__PURE__ */ new Map();
|
|
@@ -1254,15 +1817,44 @@ function packageRows(plugins) {
|
|
|
1254
1817
|
}
|
|
1255
1818
|
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
1256
1819
|
}
|
|
1820
|
+
/** The preview's signature line (one row in the confirm card). */
|
|
1821
|
+
function signatureText(signature, viaUrl) {
|
|
1822
|
+
if (signature.state === "verified") return {
|
|
1823
|
+
text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
|
|
1824
|
+
warning: false
|
|
1825
|
+
};
|
|
1826
|
+
const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
|
|
1827
|
+
return {
|
|
1828
|
+
text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
|
|
1829
|
+
warning: true
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
/** Does the input name an http(s) address? */
|
|
1833
|
+
const isHttpUrl = (text) => /^https?:\/\//i.test(text);
|
|
1834
|
+
/** Does the input look like a filesystem path (drive letter, UNC, posix
|
|
1835
|
+
* root, or a .zip name with a separator in it)? */
|
|
1836
|
+
const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
|
|
1257
1837
|
/** The plugin management page. */
|
|
1258
1838
|
function PluginsPage({ ctx }) {
|
|
1259
1839
|
const [rows, setRows] = useState([]);
|
|
1260
1840
|
const [error, setError] = useState(void 0);
|
|
1261
1841
|
const [busy, setBusy] = useState(void 0);
|
|
1262
1842
|
const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
|
|
1843
|
+
const [restartNeeded, setRestartNeeded] = useState(false);
|
|
1844
|
+
const [installOpen, setInstallOpen] = useState(false);
|
|
1845
|
+
const [phase, setPhase] = useState({ kind: "idle" });
|
|
1846
|
+
const [message, setMessage] = useState(void 0);
|
|
1847
|
+
const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
|
|
1848
|
+
const [updatingName, setUpdatingName] = useState(void 0);
|
|
1849
|
+
const [keyChange, setKeyChange] = useState(void 0);
|
|
1850
|
+
const [query, setQuery] = useState("");
|
|
1851
|
+
const [searchResults, setSearchResults] = useState(void 0);
|
|
1852
|
+
const [searching, setSearching] = useState(false);
|
|
1853
|
+
const [dragging, setDragging] = useState(false);
|
|
1854
|
+
const link = ctx.client.link;
|
|
1263
1855
|
const load = () => {
|
|
1264
1856
|
setError(void 0);
|
|
1265
|
-
|
|
1857
|
+
link.call("plugins.list", {}).then((result) => {
|
|
1266
1858
|
if (!result.ok) {
|
|
1267
1859
|
setError(rpcErrorText(result.error));
|
|
1268
1860
|
return;
|
|
@@ -1271,11 +1863,30 @@ function PluginsPage({ ctx }) {
|
|
|
1271
1863
|
}).catch((cause) => {
|
|
1272
1864
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1273
1865
|
});
|
|
1866
|
+
link.call("plugins.updates-check", {}).then((result) => {
|
|
1867
|
+
if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
|
|
1868
|
+
}).catch(() => void 0);
|
|
1869
|
+
};
|
|
1870
|
+
useEffect(() => {
|
|
1871
|
+
load();
|
|
1872
|
+
}, [link]);
|
|
1873
|
+
const openInstall = () => {
|
|
1874
|
+
setQuery("");
|
|
1875
|
+
setSearchResults(void 0);
|
|
1876
|
+
setMessage(void 0);
|
|
1877
|
+
setDragging(false);
|
|
1878
|
+
setInstallOpen(true);
|
|
1879
|
+
};
|
|
1880
|
+
const closeInstall = () => {
|
|
1881
|
+
setInstallOpen(false);
|
|
1882
|
+
setQuery("");
|
|
1883
|
+
setSearchResults(void 0);
|
|
1884
|
+
setMessage(void 0);
|
|
1885
|
+
setDragging(false);
|
|
1274
1886
|
};
|
|
1275
|
-
useEffect(load, []);
|
|
1276
1887
|
const toggle = (row, enabled) => {
|
|
1277
1888
|
setBusy(row.packageName);
|
|
1278
|
-
|
|
1889
|
+
link.call("plugins.set-enabled", {
|
|
1279
1890
|
name: row.packageName,
|
|
1280
1891
|
enabled
|
|
1281
1892
|
}).then((result) => {
|
|
@@ -1297,12 +1908,13 @@ function PluginsPage({ ctx }) {
|
|
|
1297
1908
|
const uninstall = (row) => {
|
|
1298
1909
|
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
|
|
1299
1910
|
setBusy(row.packageName);
|
|
1300
|
-
|
|
1911
|
+
link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
|
|
1301
1912
|
if (!result.ok) {
|
|
1302
1913
|
setError(rpcErrorText(result.error));
|
|
1303
1914
|
return;
|
|
1304
1915
|
}
|
|
1305
1916
|
setTouched((current) => new Set(current).add(row.packageName));
|
|
1917
|
+
setRestartNeeded(true);
|
|
1306
1918
|
load();
|
|
1307
1919
|
}).catch((cause) => {
|
|
1308
1920
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
@@ -1310,100 +1922,689 @@ function PluginsPage({ ctx }) {
|
|
|
1310
1922
|
setBusy(void 0);
|
|
1311
1923
|
});
|
|
1312
1924
|
};
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1925
|
+
const inspectPath = (zipPath) => {
|
|
1926
|
+
setMessage(void 0);
|
|
1927
|
+
link.call("plugins.inspect", { zipPath }).then((result) => {
|
|
1928
|
+
if (!result.ok) {
|
|
1929
|
+
setPhase({
|
|
1930
|
+
kind: "error",
|
|
1931
|
+
message: `读取插件包失败:${rpcErrorText(result.error)}`
|
|
1932
|
+
});
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
setPhase({
|
|
1936
|
+
kind: "confirm",
|
|
1937
|
+
zipPath,
|
|
1938
|
+
archive: result.value.archive,
|
|
1939
|
+
viaUrl: false,
|
|
1940
|
+
risk: false
|
|
1941
|
+
});
|
|
1942
|
+
}).catch((cause) => setPhase({
|
|
1943
|
+
kind: "error",
|
|
1944
|
+
message: String(cause)
|
|
1945
|
+
}));
|
|
1946
|
+
};
|
|
1947
|
+
const inspectFromUrl = (url) => {
|
|
1948
|
+
setMessage(void 0);
|
|
1949
|
+
link.call("plugins.inspect-from-url", { url }).then((result) => {
|
|
1950
|
+
if (!result.ok) {
|
|
1951
|
+
setPhase({
|
|
1952
|
+
kind: "error",
|
|
1953
|
+
message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
|
|
1954
|
+
});
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
setPhase({
|
|
1958
|
+
kind: "confirm",
|
|
1959
|
+
zipPath: result.value.zipPath,
|
|
1960
|
+
archive: result.value.archive,
|
|
1961
|
+
viaUrl: true,
|
|
1962
|
+
risk: false
|
|
1963
|
+
});
|
|
1964
|
+
}).catch((cause) => setPhase({
|
|
1965
|
+
kind: "error",
|
|
1966
|
+
message: String(cause)
|
|
1967
|
+
}));
|
|
1968
|
+
};
|
|
1969
|
+
const runInstall = (zipPath, archive) => {
|
|
1970
|
+
setPhase({ kind: "installing" });
|
|
1971
|
+
(archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
|
|
1972
|
+
if (!result.ok) {
|
|
1973
|
+
setPhase({
|
|
1974
|
+
kind: "error",
|
|
1975
|
+
message: `安装失败:${rpcErrorText(result.error)}`
|
|
1976
|
+
});
|
|
1977
|
+
return;
|
|
1978
|
+
}
|
|
1979
|
+
setPhase({ kind: "idle" });
|
|
1980
|
+
closeInstall();
|
|
1981
|
+
setRestartNeeded(true);
|
|
1982
|
+
load();
|
|
1983
|
+
}).catch((cause) => setPhase({
|
|
1984
|
+
kind: "error",
|
|
1985
|
+
message: String(cause)
|
|
1986
|
+
}));
|
|
1987
|
+
};
|
|
1988
|
+
/** The update pill's click: a plain update installs directly; a key
|
|
1989
|
+
* change confirmation intercepts first. */
|
|
1990
|
+
const requestUpdate = (update) => {
|
|
1991
|
+
if (update.keyChanged === true) {
|
|
1992
|
+
setKeyChange(update);
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
updateNow(update.name);
|
|
1996
|
+
};
|
|
1997
|
+
/** The update itself: the feed's entry, no preview. */
|
|
1998
|
+
const updateNow = (name) => {
|
|
1999
|
+
setKeyChange(void 0);
|
|
2000
|
+
setUpdatingName(name);
|
|
2001
|
+
setMessage(void 0);
|
|
2002
|
+
link.call("plugins.remote-install", { name }).then((result) => {
|
|
2003
|
+
setUpdatingName(void 0);
|
|
2004
|
+
if (!result.ok) {
|
|
2005
|
+
setMessage({
|
|
2006
|
+
kind: "error",
|
|
2007
|
+
text: rpcErrorText(result.error)
|
|
2008
|
+
});
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
setRestartNeeded(true);
|
|
2012
|
+
load();
|
|
2013
|
+
}).catch(() => setUpdatingName(void 0));
|
|
2014
|
+
};
|
|
2015
|
+
/** The tri-form input: address/path → inspect, anything else → feed search. */
|
|
2016
|
+
const submitQuery = () => {
|
|
2017
|
+
const text = query.trim();
|
|
2018
|
+
if (text === "") return;
|
|
2019
|
+
setMessage(void 0);
|
|
2020
|
+
if (isHttpUrl(text)) {
|
|
2021
|
+
inspectFromUrl(text);
|
|
2022
|
+
return;
|
|
2023
|
+
}
|
|
2024
|
+
if (looksLikePath(text)) {
|
|
2025
|
+
inspectPath(text);
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
runSearch(text);
|
|
2029
|
+
};
|
|
2030
|
+
const runSearch = (text) => {
|
|
2031
|
+
setSearching(true);
|
|
2032
|
+
setSearchResults(void 0);
|
|
2033
|
+
link.call("plugins.remote-list", {}).then((result) => {
|
|
2034
|
+
setSearching(false);
|
|
2035
|
+
if (!result.ok) {
|
|
2036
|
+
setMessage({
|
|
2037
|
+
kind: "error",
|
|
2038
|
+
text: `搜索失败:${rpcErrorText(result.error)}`
|
|
2039
|
+
});
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
const needle = text.toLowerCase();
|
|
2043
|
+
setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
|
|
2044
|
+
}).catch((cause) => {
|
|
2045
|
+
setSearching(false);
|
|
2046
|
+
setMessage({
|
|
2047
|
+
kind: "error",
|
|
2048
|
+
text: String(cause)
|
|
2049
|
+
});
|
|
2050
|
+
});
|
|
2051
|
+
};
|
|
2052
|
+
/** A search-result entry that is not installed yet: preview first. The
|
|
2053
|
+
* entry's own coordinates decide where the zip comes from — a federation
|
|
2054
|
+
* row downloads from the author's release, a same-directory row from its
|
|
2055
|
+
* feed base. */
|
|
2056
|
+
const previewRemote = (item) => {
|
|
2057
|
+
if (item.url !== void 0) {
|
|
2058
|
+
inspectFromUrl(item.url);
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
if (item.feedUrl === void 0 || item.file === void 0) return;
|
|
2062
|
+
const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
|
|
2063
|
+
inspectFromUrl(`${base}${item.file}`);
|
|
2064
|
+
};
|
|
2065
|
+
const onDrop = (event) => {
|
|
2066
|
+
event.preventDefault();
|
|
2067
|
+
setDragging(false);
|
|
2068
|
+
const file = event.dataTransfer.files[0];
|
|
2069
|
+
if (file === void 0) return;
|
|
2070
|
+
if (!file.name.toLowerCase().endsWith(".zip")) {
|
|
2071
|
+
setMessage({
|
|
2072
|
+
kind: "error",
|
|
2073
|
+
text: "只支持 .zip 插件包或组合包"
|
|
2074
|
+
});
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
const zipPath = droppedZipPath(file);
|
|
2078
|
+
if (zipPath === null) {
|
|
2079
|
+
setMessage({
|
|
2080
|
+
kind: "error",
|
|
2081
|
+
text: "当前环境不支持拖拽安装(缺少路径桥)"
|
|
2082
|
+
});
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
inspectPath(zipPath);
|
|
2086
|
+
};
|
|
2087
|
+
const restart = () => {
|
|
2088
|
+
link.call("window.relaunch", {});
|
|
2089
|
+
};
|
|
2090
|
+
const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
|
|
2091
|
+
const spans = /* @__PURE__ */ new Map();
|
|
2092
|
+
for (let index = 0; index < rows.length;) {
|
|
2093
|
+
const category = rows[index].category;
|
|
2094
|
+
let end = index + 1;
|
|
2095
|
+
while (end < rows.length && rows[end].category === category) end += 1;
|
|
2096
|
+
spans.set(index, end - index);
|
|
2097
|
+
index = end;
|
|
1318
2098
|
}
|
|
1319
|
-
return
|
|
2099
|
+
return jsxs(Page, {
|
|
1320
2100
|
title: "插件管理",
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
onClick: load,
|
|
1326
|
-
children: "刷新"
|
|
2101
|
+
titleExtra: jsx(IconButton, {
|
|
2102
|
+
icon: jsx(PlusIcon, {}),
|
|
2103
|
+
label: "安装插件",
|
|
2104
|
+
onClick: openInstall
|
|
1327
2105
|
}),
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
jsx(
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
2106
|
+
actions: restartNeeded ? jsx(Button, {
|
|
2107
|
+
intent: "primary",
|
|
2108
|
+
onClick: restart,
|
|
2109
|
+
children: "重启生效"
|
|
2110
|
+
}) : void 0,
|
|
2111
|
+
children: [
|
|
2112
|
+
jsxs(Stack, {
|
|
2113
|
+
gap: "lg",
|
|
2114
|
+
children: [error !== void 0 && jsx(Alert, {
|
|
2115
|
+
intent: "danger",
|
|
2116
|
+
children: error
|
|
2117
|
+
}), rows.length === 0 ? jsx(EmptyState, {
|
|
2118
|
+
title: "还没有安装插件",
|
|
2119
|
+
action: jsx(Button, {
|
|
2120
|
+
intent: "primary",
|
|
2121
|
+
onClick: openInstall,
|
|
2122
|
+
children: "安装插件"
|
|
2123
|
+
})
|
|
2124
|
+
}) : jsxs(Table, {
|
|
2125
|
+
"data-plugins-table": true,
|
|
2126
|
+
children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
|
|
2127
|
+
jsx(TableHead, {
|
|
2128
|
+
style: { width: "6em" },
|
|
2129
|
+
children: "分类"
|
|
2130
|
+
}),
|
|
2131
|
+
jsx(TableHead, { children: "名称" }),
|
|
2132
|
+
jsx(TableHead, { children: "类型" }),
|
|
2133
|
+
jsx(TableHead, { children: "版本" }),
|
|
2134
|
+
jsx(TableHead, { children: "状态" }),
|
|
2135
|
+
jsx(TableHead, { children: "操作" })
|
|
2136
|
+
] }) }), jsx(TableBody, { children: rows.map((row, index) => {
|
|
2137
|
+
const update = updates.get(row.packageName);
|
|
2138
|
+
const span = spans.get(index);
|
|
2139
|
+
return jsxs(TableRow, { children: [
|
|
2140
|
+
span !== void 0 && jsx(TableCell, {
|
|
2141
|
+
rowSpan: span,
|
|
2142
|
+
style: {
|
|
2143
|
+
verticalAlign: "middle",
|
|
2144
|
+
color: "var(--snap-color-muted)",
|
|
2145
|
+
fontWeight: 600
|
|
2146
|
+
},
|
|
2147
|
+
children: row.category
|
|
2148
|
+
}),
|
|
2149
|
+
jsx(TableCell, { children: jsxs("div", {
|
|
2150
|
+
style: {
|
|
2151
|
+
display: "flex",
|
|
2152
|
+
flexDirection: "column"
|
|
2153
|
+
},
|
|
2154
|
+
children: [jsxs("span", {
|
|
2155
|
+
style: {
|
|
2156
|
+
display: "flex",
|
|
2157
|
+
alignItems: "center",
|
|
2158
|
+
gap: "var(--snap-space-sm)"
|
|
2159
|
+
},
|
|
2160
|
+
children: [row.title, row.builtinDefault && jsx(Badge, {
|
|
2161
|
+
intent: "neutral",
|
|
2162
|
+
children: "内置默认"
|
|
2163
|
+
})]
|
|
2164
|
+
}), jsx("span", {
|
|
2165
|
+
style: {
|
|
2166
|
+
color: "var(--snap-color-muted)",
|
|
2167
|
+
fontSize: "var(--snap-text-xs)"
|
|
2168
|
+
},
|
|
2169
|
+
children: row.packageName
|
|
2170
|
+
})]
|
|
2171
|
+
}) }),
|
|
2172
|
+
jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
|
|
1358
2173
|
intent: "neutral",
|
|
1359
|
-
children:
|
|
1360
|
-
})]
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
children: "
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
2174
|
+
children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
|
|
2175
|
+
})] }),
|
|
2176
|
+
jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
|
|
2177
|
+
intent: "primary",
|
|
2178
|
+
emphasis: "ghost",
|
|
2179
|
+
size: "sm",
|
|
2180
|
+
title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
|
|
2181
|
+
disabled: updatingName === row.packageName,
|
|
2182
|
+
onClick: () => requestUpdate(update),
|
|
2183
|
+
children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
|
|
2184
|
+
}) : row.version ?? "—" }),
|
|
2185
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
|
|
2186
|
+
checked: true,
|
|
2187
|
+
disabled: true,
|
|
2188
|
+
"aria-label": `启用 ${row.title}`
|
|
2189
|
+
}) : jsxs("div", {
|
|
2190
|
+
style: {
|
|
2191
|
+
display: "flex",
|
|
2192
|
+
alignItems: "center",
|
|
2193
|
+
gap: "var(--snap-space-sm)"
|
|
2194
|
+
},
|
|
2195
|
+
children: [jsx(Switch, {
|
|
2196
|
+
checked: row.enabled,
|
|
2197
|
+
disabled: busy === row.packageName,
|
|
2198
|
+
onCheckedChange: (next) => toggle(row, next),
|
|
2199
|
+
"aria-label": `启用 ${row.title}`
|
|
2200
|
+
}), touched.has(row.packageName) && jsx(Badge, {
|
|
2201
|
+
intent: "warning",
|
|
2202
|
+
children: "待重启"
|
|
2203
|
+
})]
|
|
2204
|
+
}) }),
|
|
2205
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
|
|
2206
|
+
style: { color: "var(--snap-color-muted)" },
|
|
2207
|
+
children: "内置默认不可卸载"
|
|
2208
|
+
}) : jsx(Button, {
|
|
2209
|
+
intent: "danger",
|
|
2210
|
+
emphasis: "ghost",
|
|
2211
|
+
size: "sm",
|
|
2212
|
+
disabled: busy === row.packageName,
|
|
2213
|
+
onClick: () => uninstall(row),
|
|
2214
|
+
children: "卸载"
|
|
2215
|
+
}) })
|
|
2216
|
+
] }, row.packageName);
|
|
2217
|
+
}) })]
|
|
2218
|
+
})]
|
|
2219
|
+
}),
|
|
2220
|
+
jsx(Dialog, {
|
|
2221
|
+
open: installOpen,
|
|
2222
|
+
onOpenChange: (next) => {
|
|
2223
|
+
if (!next) closeInstall();
|
|
2224
|
+
},
|
|
2225
|
+
children: jsxs(DialogContent, {
|
|
2226
|
+
presentation: "modal",
|
|
2227
|
+
size: "lg",
|
|
2228
|
+
"data-plugins-dropzone": true,
|
|
2229
|
+
"aria-describedby": void 0,
|
|
2230
|
+
onDragOver: (event) => {
|
|
2231
|
+
event.preventDefault();
|
|
2232
|
+
setDragging(true);
|
|
2233
|
+
},
|
|
2234
|
+
onDragLeave: (event) => {
|
|
2235
|
+
if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
|
|
2236
|
+
},
|
|
2237
|
+
onDrop,
|
|
2238
|
+
children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
|
|
2239
|
+
gap: "sm",
|
|
2240
|
+
children: [
|
|
2241
|
+
jsx("div", {
|
|
2242
|
+
"data-plugins-drop-hint": true,
|
|
2243
|
+
style: {
|
|
2244
|
+
height: "calc(var(--snap-control-height-md) * 3)",
|
|
2245
|
+
display: "flex",
|
|
2246
|
+
alignItems: "center",
|
|
2247
|
+
justifyContent: "center",
|
|
2248
|
+
border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
|
|
2249
|
+
borderRadius: "var(--snap-radius-md)",
|
|
2250
|
+
background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
|
|
2251
|
+
color: "var(--snap-color-muted)",
|
|
2252
|
+
fontSize: "var(--snap-text-sm)"
|
|
2253
|
+
},
|
|
2254
|
+
children: dragging ? "释放以安装" : "拖入 .zip 安装"
|
|
2255
|
+
}),
|
|
2256
|
+
jsxs("div", {
|
|
2257
|
+
style: {
|
|
2258
|
+
display: "flex",
|
|
2259
|
+
gap: "var(--snap-space-sm)"
|
|
2260
|
+
},
|
|
2261
|
+
children: [jsx(Input, {
|
|
2262
|
+
value: query,
|
|
2263
|
+
placeholder: "本地路径 / https://… / 插件名",
|
|
2264
|
+
style: {
|
|
2265
|
+
flex: 1,
|
|
2266
|
+
minWidth: 0
|
|
2267
|
+
},
|
|
2268
|
+
onChange: (event) => setQuery(event.target.value),
|
|
2269
|
+
onKeyDown: (event) => {
|
|
2270
|
+
if (event.key === "Enter") submitQuery();
|
|
2271
|
+
}
|
|
2272
|
+
}), jsx(Button, {
|
|
2273
|
+
intent: "neutral",
|
|
2274
|
+
emphasis: "outline",
|
|
2275
|
+
disabled: searching,
|
|
2276
|
+
onClick: submitQuery,
|
|
2277
|
+
children: searching ? "搜索中…" : "搜索"
|
|
2278
|
+
})]
|
|
2279
|
+
}),
|
|
2280
|
+
message !== void 0 && jsx("div", {
|
|
2281
|
+
role: message.kind === "error" ? "alert" : "status",
|
|
2282
|
+
style: {
|
|
2283
|
+
fontSize: "var(--snap-text-xs)",
|
|
2284
|
+
color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
|
|
2285
|
+
},
|
|
2286
|
+
children: message.text
|
|
2287
|
+
}),
|
|
2288
|
+
visibleResults !== void 0 && jsxs(Stack, {
|
|
2289
|
+
gap: "sm",
|
|
2290
|
+
children: [
|
|
2291
|
+
jsxs("div", {
|
|
2292
|
+
style: {
|
|
2293
|
+
display: "flex",
|
|
2294
|
+
justifyContent: "space-between",
|
|
2295
|
+
alignItems: "center"
|
|
2296
|
+
},
|
|
2297
|
+
children: [jsxs("span", {
|
|
2298
|
+
style: {
|
|
2299
|
+
fontSize: "var(--snap-text-sm)",
|
|
2300
|
+
color: "var(--snap-color-muted)"
|
|
2301
|
+
},
|
|
2302
|
+
children: [
|
|
2303
|
+
"搜索“",
|
|
2304
|
+
query.trim(),
|
|
2305
|
+
"”(",
|
|
2306
|
+
searchResults?.length ?? 0,
|
|
2307
|
+
")"
|
|
2308
|
+
]
|
|
2309
|
+
}), jsx(Button, {
|
|
2310
|
+
intent: "neutral",
|
|
2311
|
+
emphasis: "ghost",
|
|
2312
|
+
size: "sm",
|
|
2313
|
+
onClick: () => setSearchResults(void 0),
|
|
2314
|
+
children: "✕"
|
|
2315
|
+
})]
|
|
2316
|
+
}),
|
|
2317
|
+
visibleResults.length === 0 && jsx("div", {
|
|
2318
|
+
style: {
|
|
2319
|
+
padding: "12px 0",
|
|
2320
|
+
textAlign: "center",
|
|
2321
|
+
color: "var(--snap-color-muted)",
|
|
2322
|
+
fontSize: "var(--snap-text-sm)"
|
|
2323
|
+
},
|
|
2324
|
+
children: "没有匹配的插件。"
|
|
2325
|
+
}),
|
|
2326
|
+
visibleResults.map((item) => {
|
|
2327
|
+
const installed = item.installed !== void 0;
|
|
2328
|
+
return jsxs("div", {
|
|
2329
|
+
style: {
|
|
2330
|
+
display: "flex",
|
|
2331
|
+
gap: "var(--snap-space-md)",
|
|
2332
|
+
alignItems: "center",
|
|
2333
|
+
justifyContent: "space-between",
|
|
2334
|
+
borderBottom: "1px solid var(--snap-color-border)",
|
|
2335
|
+
paddingBottom: "var(--snap-space-sm)"
|
|
2336
|
+
},
|
|
2337
|
+
children: [jsxs("div", {
|
|
2338
|
+
style: { minWidth: 0 },
|
|
2339
|
+
children: [jsxs("div", {
|
|
2340
|
+
style: {
|
|
2341
|
+
display: "flex",
|
|
2342
|
+
gap: "var(--snap-space-sm)",
|
|
2343
|
+
alignItems: "center"
|
|
2344
|
+
},
|
|
2345
|
+
children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
|
|
2346
|
+
intent: "neutral",
|
|
2347
|
+
children: item.source
|
|
2348
|
+
})]
|
|
2349
|
+
}), jsxs("div", {
|
|
2350
|
+
style: {
|
|
2351
|
+
fontSize: "var(--snap-text-xs)",
|
|
2352
|
+
color: "var(--snap-color-muted)"
|
|
2353
|
+
},
|
|
2354
|
+
children: [
|
|
2355
|
+
item.name,
|
|
2356
|
+
" · ",
|
|
2357
|
+
item.version
|
|
2358
|
+
]
|
|
2359
|
+
})]
|
|
2360
|
+
}), item.action === "install" ? jsx(Button, {
|
|
2361
|
+
intent: "primary",
|
|
2362
|
+
emphasis: "outline",
|
|
2363
|
+
size: "sm",
|
|
2364
|
+
onClick: () => previewRemote(item),
|
|
2365
|
+
children: "安装"
|
|
2366
|
+
}) : item.action === "update" && installed ? jsx(Button, {
|
|
2367
|
+
intent: "primary",
|
|
2368
|
+
emphasis: "ghost",
|
|
2369
|
+
size: "sm",
|
|
2370
|
+
title: `当前 ${item.installed?.version} → ${item.version}`,
|
|
2371
|
+
disabled: updatingName === item.name,
|
|
2372
|
+
onClick: () => requestUpdate({
|
|
2373
|
+
name: item.name,
|
|
2374
|
+
installedVersion: item.installed?.version ?? "",
|
|
2375
|
+
feedVersion: item.version
|
|
2376
|
+
}),
|
|
2377
|
+
children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
|
|
2378
|
+
}) : jsx("span", {
|
|
2379
|
+
style: {
|
|
2380
|
+
fontSize: "var(--snap-text-xs)",
|
|
2381
|
+
color: "var(--snap-color-muted)"
|
|
2382
|
+
},
|
|
2383
|
+
children: item.action === "current" ? "已是最新" : "本地更新"
|
|
2384
|
+
})]
|
|
2385
|
+
}, item.name);
|
|
2386
|
+
}),
|
|
2387
|
+
(searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
|
|
2388
|
+
style: {
|
|
2389
|
+
fontSize: "var(--snap-text-xs)",
|
|
2390
|
+
color: "var(--snap-color-muted)"
|
|
2391
|
+
},
|
|
2392
|
+
children: [
|
|
2393
|
+
"已显示前 ",
|
|
2394
|
+
SEARCH_ROW_CAP,
|
|
2395
|
+
" 条,共 ",
|
|
2396
|
+
searchResults?.length,
|
|
2397
|
+
" 条。"
|
|
2398
|
+
]
|
|
2399
|
+
})
|
|
2400
|
+
]
|
|
2401
|
+
})
|
|
2402
|
+
]
|
|
2403
|
+
}) })]
|
|
2404
|
+
})
|
|
2405
|
+
}),
|
|
2406
|
+
jsx(Dialog, {
|
|
2407
|
+
open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
|
|
2408
|
+
onOpenChange: (next) => {
|
|
2409
|
+
if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
|
|
2410
|
+
},
|
|
2411
|
+
children: jsxs(DialogContent, {
|
|
2412
|
+
presentation: "modal",
|
|
2413
|
+
"aria-describedby": void 0,
|
|
2414
|
+
children: [
|
|
2415
|
+
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}` })] }),
|
|
2416
|
+
jsxs(DialogBody, { children: [
|
|
2417
|
+
phase.kind === "error" && jsx("div", {
|
|
2418
|
+
style: {
|
|
2419
|
+
color: "var(--snap-color-danger)",
|
|
2420
|
+
whiteSpace: "pre-wrap",
|
|
2421
|
+
fontSize: "var(--snap-text-sm)"
|
|
2422
|
+
},
|
|
2423
|
+
children: phase.message
|
|
2424
|
+
}),
|
|
2425
|
+
phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
|
|
2426
|
+
gap: "sm",
|
|
2427
|
+
children: [
|
|
2428
|
+
phase.archive.combo.description !== void 0 && jsx("div", {
|
|
2429
|
+
style: {
|
|
2430
|
+
color: "var(--snap-color-muted)",
|
|
2431
|
+
fontSize: "var(--snap-text-sm)"
|
|
2432
|
+
},
|
|
2433
|
+
children: phase.archive.combo.description
|
|
2434
|
+
}),
|
|
2435
|
+
jsxs("div", {
|
|
2436
|
+
style: {
|
|
2437
|
+
display: "grid",
|
|
2438
|
+
gap: "var(--snap-space-xs)",
|
|
2439
|
+
fontSize: "var(--snap-text-sm)"
|
|
2440
|
+
},
|
|
2441
|
+
children: [jsxs("div", { children: [
|
|
2442
|
+
"插件(",
|
|
2443
|
+
phase.archive.combo.plugins.length,
|
|
2444
|
+
")"
|
|
2445
|
+
] }), phase.archive.combo.plugins.map((plugin) => {
|
|
2446
|
+
const line = signatureText(plugin.signature, phase.viaUrl);
|
|
2447
|
+
const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
|
|
2448
|
+
return jsxs("div", {
|
|
2449
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
2450
|
+
children: [
|
|
2451
|
+
plugin.title ?? plugin.name,
|
|
2452
|
+
" ",
|
|
2453
|
+
plugin.version,
|
|
2454
|
+
" · ",
|
|
2455
|
+
action,
|
|
2456
|
+
line.warning ? " · ⚠ 未验证" : ""
|
|
2457
|
+
]
|
|
2458
|
+
}, plugin.name);
|
|
2459
|
+
})]
|
|
2460
|
+
}),
|
|
2461
|
+
phase.archive.combo.missing.length > 0 && jsxs("div", {
|
|
2462
|
+
style: {
|
|
2463
|
+
color: "var(--snap-color-danger)",
|
|
2464
|
+
fontSize: "var(--snap-text-sm)"
|
|
2465
|
+
},
|
|
2466
|
+
children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
|
|
2467
|
+
})
|
|
2468
|
+
]
|
|
2469
|
+
}),
|
|
2470
|
+
phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
|
|
2471
|
+
gap: "sm",
|
|
2472
|
+
children: [
|
|
2473
|
+
phase.risk ? jsx("div", {
|
|
2474
|
+
"data-plugins-risk": true,
|
|
2475
|
+
style: {
|
|
2476
|
+
color: "var(--snap-color-warning)",
|
|
2477
|
+
fontWeight: 600
|
|
2478
|
+
},
|
|
2479
|
+
children: "⚠ 此插件未经发布者验证"
|
|
2480
|
+
}) : void 0,
|
|
2481
|
+
!phase.risk && jsxs(Stack, {
|
|
2482
|
+
gap: "sm",
|
|
2483
|
+
children: [
|
|
2484
|
+
phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
|
|
2485
|
+
jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
|
|
2486
|
+
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] })
|
|
2487
|
+
]
|
|
2488
|
+
}),
|
|
2489
|
+
(() => {
|
|
2490
|
+
const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
|
|
2491
|
+
return jsxs("div", {
|
|
2492
|
+
"data-plugins-signature": phase.archive.plugin.signature.state,
|
|
2493
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
2494
|
+
children: ["签名:", line.text]
|
|
2495
|
+
});
|
|
2496
|
+
})(),
|
|
2497
|
+
!phase.risk && jsxs(Stack, {
|
|
2498
|
+
gap: "sm",
|
|
2499
|
+
children: [
|
|
2500
|
+
jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
|
|
2501
|
+
phase.archive.plugin.missing.length > 0 && jsxs("div", {
|
|
2502
|
+
style: {
|
|
2503
|
+
color: "var(--snap-color-danger)",
|
|
2504
|
+
fontSize: "var(--snap-text-sm)"
|
|
2505
|
+
},
|
|
2506
|
+
children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
|
|
2507
|
+
}),
|
|
2508
|
+
phase.archive.plugin.action === "blocked" && jsxs("div", {
|
|
2509
|
+
style: {
|
|
2510
|
+
color: "var(--snap-color-danger)",
|
|
2511
|
+
fontSize: "var(--snap-text-sm)"
|
|
2512
|
+
},
|
|
2513
|
+
children: [
|
|
2514
|
+
"已安装 v",
|
|
2515
|
+
phase.archive.plugin.installed?.version,
|
|
2516
|
+
",安装包 v",
|
|
2517
|
+
phase.archive.plugin.version,
|
|
2518
|
+
" 不高于已装版本,无法覆盖。"
|
|
2519
|
+
]
|
|
2520
|
+
})
|
|
2521
|
+
]
|
|
2522
|
+
}),
|
|
2523
|
+
phase.risk && jsx("div", {
|
|
2524
|
+
style: {
|
|
2525
|
+
color: "var(--snap-color-muted)",
|
|
2526
|
+
fontSize: "var(--snap-text-sm)"
|
|
2527
|
+
},
|
|
2528
|
+
children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
|
|
2529
|
+
})
|
|
2530
|
+
]
|
|
2531
|
+
})
|
|
2532
|
+
] }),
|
|
2533
|
+
jsxs(DialogFooter, { children: [
|
|
2534
|
+
phase.kind === "error" && jsx(Button, {
|
|
2535
|
+
intent: "neutral",
|
|
2536
|
+
emphasis: "outline",
|
|
2537
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
2538
|
+
children: "返回"
|
|
2539
|
+
}),
|
|
2540
|
+
phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
|
|
2541
|
+
intent: "neutral",
|
|
2542
|
+
emphasis: "outline",
|
|
2543
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
2544
|
+
children: "取消"
|
|
2545
|
+
}), phase.risk ? jsx(Button, {
|
|
2546
|
+
intent: "primary",
|
|
2547
|
+
"data-plugins-risk-confirm": true,
|
|
2548
|
+
onClick: () => runInstall(phase.zipPath, phase.archive),
|
|
2549
|
+
children: "我知晓风险,仍要安装"
|
|
2550
|
+
}) : jsx(Button, {
|
|
2551
|
+
intent: "primary",
|
|
2552
|
+
"data-plugins-install-confirm": true,
|
|
2553
|
+
disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
|
|
2554
|
+
onClick: () => {
|
|
2555
|
+
if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
|
|
2556
|
+
setPhase({
|
|
2557
|
+
...phase,
|
|
2558
|
+
risk: true
|
|
2559
|
+
});
|
|
2560
|
+
return;
|
|
2561
|
+
}
|
|
2562
|
+
runInstall(phase.zipPath, phase.archive);
|
|
2563
|
+
},
|
|
2564
|
+
children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
|
|
2565
|
+
})] }),
|
|
2566
|
+
phase.kind === "installing" && jsx("span", {
|
|
2567
|
+
style: { color: "var(--snap-color-muted)" },
|
|
2568
|
+
children: "正在安装…"
|
|
2569
|
+
})
|
|
2570
|
+
] })
|
|
2571
|
+
]
|
|
2572
|
+
})
|
|
2573
|
+
}),
|
|
2574
|
+
jsx(Dialog, {
|
|
2575
|
+
open: keyChange !== void 0,
|
|
2576
|
+
onOpenChange: (next) => {
|
|
2577
|
+
if (!next) setKeyChange(void 0);
|
|
2578
|
+
},
|
|
2579
|
+
children: jsxs(DialogContent, {
|
|
2580
|
+
presentation: "modal",
|
|
2581
|
+
children: [
|
|
2582
|
+
jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
|
|
2583
|
+
jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
|
|
2584
|
+
style: { fontSize: "var(--snap-text-sm)" },
|
|
2585
|
+
children: [
|
|
2586
|
+
"已安装 v",
|
|
2587
|
+
keyChange.installedVersion,
|
|
2588
|
+
" → 源上 v",
|
|
2589
|
+
keyChange.feedVersion,
|
|
2590
|
+
"。"
|
|
2591
|
+
]
|
|
2592
|
+
}) }),
|
|
2593
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
2594
|
+
intent: "neutral",
|
|
2595
|
+
emphasis: "outline",
|
|
2596
|
+
onClick: () => setKeyChange(void 0),
|
|
2597
|
+
children: "取消"
|
|
2598
|
+
}), jsx(Button, {
|
|
2599
|
+
intent: "primary",
|
|
2600
|
+
"data-plugins-keychange-confirm": true,
|
|
2601
|
+
onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
|
|
2602
|
+
children: "仍要更新"
|
|
2603
|
+
})] })
|
|
2604
|
+
]
|
|
2605
|
+
})
|
|
2606
|
+
})
|
|
2607
|
+
]
|
|
1407
2608
|
});
|
|
1408
2609
|
}
|
|
1409
2610
|
//#endregion
|
|
@@ -1445,6 +2646,19 @@ function GearIcon() {
|
|
|
1445
2646
|
}), 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" })]
|
|
1446
2647
|
});
|
|
1447
2648
|
}
|
|
2649
|
+
/** The close glyph used by the surface's dismiss control. */
|
|
2650
|
+
function CloseIcon() {
|
|
2651
|
+
return jsx("svg", {
|
|
2652
|
+
viewBox: "0 0 24 24",
|
|
2653
|
+
width: "18",
|
|
2654
|
+
height: "18",
|
|
2655
|
+
fill: "none",
|
|
2656
|
+
stroke: "currentColor",
|
|
2657
|
+
strokeWidth: "1.8",
|
|
2658
|
+
"aria-hidden": "true",
|
|
2659
|
+
children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
1448
2662
|
/** The default settings trigger; the layout decides placement/presentation. */
|
|
1449
2663
|
function SettingsEntry(props) {
|
|
1450
2664
|
if (props.presentation === "label") return jsx(Button, {
|
|
@@ -1463,12 +2677,13 @@ function SettingsEntry(props) {
|
|
|
1463
2677
|
}
|
|
1464
2678
|
/** The default settings surface. */
|
|
1465
2679
|
function SettingsSurface(props) {
|
|
1466
|
-
const { service } = props;
|
|
2680
|
+
const { service, ctx } = props;
|
|
1467
2681
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
1468
2682
|
const open = service.isOpen();
|
|
1469
2683
|
const pages = service.listPages();
|
|
1470
2684
|
const activeId = service.activePage();
|
|
1471
2685
|
const active = pages.find((page) => page.id === activeId);
|
|
2686
|
+
const [feedOpen, setFeedOpen] = useState(false);
|
|
1472
2687
|
const groups = /* @__PURE__ */ new Map();
|
|
1473
2688
|
for (const page of pages) {
|
|
1474
2689
|
const group = page.group ?? "其他";
|
|
@@ -1476,7 +2691,7 @@ function SettingsSurface(props) {
|
|
|
1476
2691
|
if (bucket === void 0) groups.set(group, [page]);
|
|
1477
2692
|
else bucket.push(page);
|
|
1478
2693
|
}
|
|
1479
|
-
return jsx(Dialog, {
|
|
2694
|
+
return jsxs(Fragment, { children: [jsx(Dialog, {
|
|
1480
2695
|
open,
|
|
1481
2696
|
onOpenChange: (next) => {
|
|
1482
2697
|
if (!next) service.close();
|
|
@@ -1490,11 +2705,21 @@ function SettingsSurface(props) {
|
|
|
1490
2705
|
children: [jsxs("header", {
|
|
1491
2706
|
...part("settings", "header"),
|
|
1492
2707
|
className: "snap-settings-header",
|
|
1493
|
-
children: [jsx(DialogTitle, { children: "设置" }),
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
2708
|
+
children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
|
|
2709
|
+
style: {
|
|
2710
|
+
display: "flex",
|
|
2711
|
+
alignItems: "center",
|
|
2712
|
+
gap: 4
|
|
2713
|
+
},
|
|
2714
|
+
children: [jsx(IconButton, {
|
|
2715
|
+
icon: jsx(GearIcon, {}),
|
|
2716
|
+
label: "配置插件源",
|
|
2717
|
+
onClick: () => setFeedOpen(true)
|
|
2718
|
+
}), jsx(IconButton, {
|
|
2719
|
+
icon: jsx(CloseIcon, {}),
|
|
2720
|
+
label: "关闭",
|
|
2721
|
+
onClick: () => service.close()
|
|
2722
|
+
})]
|
|
1498
2723
|
})]
|
|
1499
2724
|
}), jsxs("div", {
|
|
1500
2725
|
...part("settings", "body"),
|
|
@@ -1527,10 +2752,7 @@ function SettingsSurface(props) {
|
|
|
1527
2752
|
...part("settings", "content"),
|
|
1528
2753
|
className: "snap-settings-content",
|
|
1529
2754
|
"data-active-page": activeId,
|
|
1530
|
-
children: active === void 0 ? jsx(EmptyState, {
|
|
1531
|
-
title: "暂无设置页",
|
|
1532
|
-
description: "安装或启用一个带设置页的插件后,它会出现在这里。"
|
|
1533
|
-
}) : jsx(SettingsPageBoundary, {
|
|
2755
|
+
children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
|
|
1534
2756
|
page: active.id,
|
|
1535
2757
|
children: active.render()
|
|
1536
2758
|
})
|
|
@@ -1538,7 +2760,11 @@ function SettingsSurface(props) {
|
|
|
1538
2760
|
})]
|
|
1539
2761
|
})
|
|
1540
2762
|
})
|
|
1541
|
-
})
|
|
2763
|
+
}), jsx(PluginFeedDialog, {
|
|
2764
|
+
ctx,
|
|
2765
|
+
open: feedOpen,
|
|
2766
|
+
onOpenChange: setFeedOpen
|
|
2767
|
+
})] });
|
|
1542
2768
|
}
|
|
1543
2769
|
/** Mount the settings registry and its default slot contributions. */
|
|
1544
2770
|
const settingsPlugin = {
|
|
@@ -1642,242 +2868,24 @@ const settingsPlugin = {
|
|
|
1642
2868
|
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
|
|
1643
2869
|
id: "settings.default-surface",
|
|
1644
2870
|
order: 0,
|
|
1645
|
-
render: () => jsx(SettingsSurface, {
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
//#endregion
|
|
1650
|
-
//#region lib/types/skins.js
|
|
1651
|
-
/** The built-in default skin id. */
|
|
1652
|
-
const DEFAULT_SKIN_ID = "default";
|
|
1653
|
-
/** The factory cobalt/steel skin. Extra skins override it through the registry. */
|
|
1654
|
-
const DEFAULT_SKIN = {
|
|
1655
|
-
id: DEFAULT_SKIN_ID,
|
|
1656
|
-
title: "工业钴蓝",
|
|
1657
|
-
presentations: {
|
|
1658
|
-
dialog: "modal",
|
|
1659
|
-
select: "popover",
|
|
1660
|
-
tabs: "inline",
|
|
1661
|
-
toast: "inline"
|
|
1662
|
-
},
|
|
1663
|
-
tokens: {
|
|
1664
|
-
dark: {
|
|
1665
|
-
colorBg: "#0b0f14",
|
|
1666
|
-
colorSurface: "#11161d",
|
|
1667
|
-
colorSurfaceRaised: "#161b22",
|
|
1668
|
-
colorText: "#ced8e3",
|
|
1669
|
-
colorMuted: "#8b949e",
|
|
1670
|
-
colorPrimary: "#4a6cff",
|
|
1671
|
-
colorOnPrimary: "#ffffff",
|
|
1672
|
-
colorDanger: "#f85149",
|
|
1673
|
-
colorSuccess: "#3fb950",
|
|
1674
|
-
colorWarning: "#d29922",
|
|
1675
|
-
colorBorder: "#1f2933",
|
|
1676
|
-
colorFocus: "#4a6cff",
|
|
1677
|
-
chart1: "#4a6cff",
|
|
1678
|
-
chart2: "#3147a1",
|
|
1679
|
-
chart3: "#667fcd",
|
|
1680
|
-
chart4: "#7d8fa5",
|
|
1681
|
-
chart5: "#55677c",
|
|
1682
|
-
chart6: "#33414f",
|
|
1683
|
-
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
1684
|
-
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
1685
|
-
textXs: "13px",
|
|
1686
|
-
textSm: "15px",
|
|
1687
|
-
textMd: "17px",
|
|
1688
|
-
textLg: "20px",
|
|
1689
|
-
textXl: "24px",
|
|
1690
|
-
weightNormal: "400",
|
|
1691
|
-
weightMedium: "500",
|
|
1692
|
-
weightStrong: "600",
|
|
1693
|
-
leadingTight: "1.2",
|
|
1694
|
-
leadingNormal: "1.55",
|
|
1695
|
-
spaceXs: "4px",
|
|
1696
|
-
spaceSm: "8px",
|
|
1697
|
-
spaceMd: "12px",
|
|
1698
|
-
spaceLg: "20px",
|
|
1699
|
-
spaceXl: "32px",
|
|
1700
|
-
radiusSm: "6px",
|
|
1701
|
-
radiusMd: "8px",
|
|
1702
|
-
radiusLg: "12px",
|
|
1703
|
-
radiusFull: "999px",
|
|
1704
|
-
borderWidth: "1px",
|
|
1705
|
-
shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
|
|
1706
|
-
shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
|
|
1707
|
-
shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
|
|
1708
|
-
durationFast: "120ms",
|
|
1709
|
-
durationNormal: "180ms",
|
|
1710
|
-
durationSlow: "280ms",
|
|
1711
|
-
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
1712
|
-
zOverlay: "50",
|
|
1713
|
-
zModal: "60",
|
|
1714
|
-
zToast: "70",
|
|
1715
|
-
controlHeightSm: "40px",
|
|
1716
|
-
controlHeightMd: "48px",
|
|
1717
|
-
controlHeightLg: "56px",
|
|
1718
|
-
density: "comfortable"
|
|
1719
|
-
},
|
|
1720
|
-
light: {
|
|
1721
|
-
colorBg: "#e4e9ef",
|
|
1722
|
-
colorSurface: "#f3f6f9",
|
|
1723
|
-
colorSurfaceRaised: "#ffffff",
|
|
1724
|
-
colorText: "#26323e",
|
|
1725
|
-
colorMuted: "#5d6d7e",
|
|
1726
|
-
colorPrimary: "#3857e8",
|
|
1727
|
-
colorOnPrimary: "#ffffff",
|
|
1728
|
-
colorDanger: "#dc2626",
|
|
1729
|
-
colorSuccess: "#15803d",
|
|
1730
|
-
colorWarning: "#b45309",
|
|
1731
|
-
colorBorder: "#c7d0da",
|
|
1732
|
-
colorFocus: "#3857e8",
|
|
1733
|
-
chart1: "#3857e8",
|
|
1734
|
-
chart2: "#7088ee",
|
|
1735
|
-
chart3: "#667dd0",
|
|
1736
|
-
chart4: "#94a3b8",
|
|
1737
|
-
chart5: "#b3c0cd",
|
|
1738
|
-
chart6: "#ccd6e0",
|
|
1739
|
-
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
1740
|
-
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
1741
|
-
textXs: "13px",
|
|
1742
|
-
textSm: "15px",
|
|
1743
|
-
textMd: "17px",
|
|
1744
|
-
textLg: "20px",
|
|
1745
|
-
textXl: "24px",
|
|
1746
|
-
weightNormal: "400",
|
|
1747
|
-
weightMedium: "500",
|
|
1748
|
-
weightStrong: "600",
|
|
1749
|
-
leadingTight: "1.2",
|
|
1750
|
-
leadingNormal: "1.55",
|
|
1751
|
-
spaceXs: "4px",
|
|
1752
|
-
spaceSm: "8px",
|
|
1753
|
-
spaceMd: "12px",
|
|
1754
|
-
spaceLg: "20px",
|
|
1755
|
-
spaceXl: "32px",
|
|
1756
|
-
radiusSm: "6px",
|
|
1757
|
-
radiusMd: "8px",
|
|
1758
|
-
radiusLg: "12px",
|
|
1759
|
-
radiusFull: "999px",
|
|
1760
|
-
borderWidth: "1px",
|
|
1761
|
-
shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
|
|
1762
|
-
shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
|
|
1763
|
-
shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
|
|
1764
|
-
durationFast: "120ms",
|
|
1765
|
-
durationNormal: "180ms",
|
|
1766
|
-
durationSlow: "280ms",
|
|
1767
|
-
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
1768
|
-
zOverlay: "50",
|
|
1769
|
-
zModal: "60",
|
|
1770
|
-
zToast: "70",
|
|
1771
|
-
controlHeightSm: "40px",
|
|
1772
|
-
controlHeightMd: "48px",
|
|
1773
|
-
controlHeightLg: "56px",
|
|
1774
|
-
density: "comfortable"
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
1778
|
-
/** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
|
|
1779
|
-
function skinTokenVar(key) {
|
|
1780
|
-
return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
|
|
1781
|
-
}
|
|
1782
|
-
/** Apply the active skin to the document root. */
|
|
1783
|
-
function applySkin(skin, mode) {
|
|
1784
|
-
if (typeof document === "undefined") return;
|
|
1785
|
-
const root = document.documentElement;
|
|
1786
|
-
root.dataset["snapSkin"] = skin.id;
|
|
1787
|
-
root.dataset["snapMode"] = mode;
|
|
1788
|
-
const tokens = skin.tokens[mode];
|
|
1789
|
-
for (const [key, value] of Object.entries(tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
1790
|
-
}
|
|
1791
|
-
/** Mount the `ctx.skins` registry. */
|
|
1792
|
-
const skinsPlugin = {
|
|
1793
|
-
name: "snap-rail ui skins",
|
|
1794
|
-
apply(ctx) {
|
|
1795
|
-
const skins = /* @__PURE__ */ new Map();
|
|
1796
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1797
|
-
const styleTags = /* @__PURE__ */ new Map();
|
|
1798
|
-
let activeId = DEFAULT_SKIN_ID;
|
|
1799
|
-
let mode = "dark";
|
|
1800
|
-
let revision = 0;
|
|
1801
|
-
skins.set(DEFAULT_SKIN_ID, DEFAULT_SKIN);
|
|
1802
|
-
const notify = () => {
|
|
1803
|
-
revision += 1;
|
|
1804
|
-
for (const listener of listeners) listener();
|
|
1805
|
-
ctx.emit("skins/changed");
|
|
1806
|
-
};
|
|
1807
|
-
const ensureStyleTag = (skin) => {
|
|
1808
|
-
if (typeof document === "undefined" || skin.css === void 0) return;
|
|
1809
|
-
if (styleTags.has(skin.id)) return;
|
|
1810
|
-
const tag = document.createElement("style");
|
|
1811
|
-
tag.dataset["snapSkinStyle"] = skin.id;
|
|
1812
|
-
tag.textContent = skin.css;
|
|
1813
|
-
document.head.append(tag);
|
|
1814
|
-
styleTags.set(skin.id, tag);
|
|
1815
|
-
};
|
|
1816
|
-
const refresh = () => {
|
|
1817
|
-
const skin = skins.get(activeId) ?? DEFAULT_SKIN;
|
|
1818
|
-
activeId = skin.id;
|
|
1819
|
-
ensureStyleTag(skin);
|
|
1820
|
-
applySkin(skin, mode);
|
|
1821
|
-
notify();
|
|
1822
|
-
};
|
|
1823
|
-
ctx.provide("skins", {
|
|
1824
|
-
register(caller, skin) {
|
|
1825
|
-
skins.set(skin.id, skin);
|
|
1826
|
-
if (skin.id !== "default") activeId = skin.id;
|
|
1827
|
-
refresh();
|
|
1828
|
-
const remove = () => {
|
|
1829
|
-
if (!skins.delete(skin.id)) return;
|
|
1830
|
-
const tag = styleTags.get(skin.id);
|
|
1831
|
-
if (tag !== void 0) {
|
|
1832
|
-
tag.remove();
|
|
1833
|
-
styleTags.delete(skin.id);
|
|
1834
|
-
}
|
|
1835
|
-
if (activeId === skin.id) activeId = DEFAULT_SKIN_ID;
|
|
1836
|
-
refresh();
|
|
1837
|
-
};
|
|
1838
|
-
caller.effect(() => remove);
|
|
1839
|
-
return remove;
|
|
1840
|
-
},
|
|
1841
|
-
activate(skinId) {
|
|
1842
|
-
if (!skins.has(skinId)) return false;
|
|
1843
|
-
activeId = skinId;
|
|
1844
|
-
refresh();
|
|
1845
|
-
return true;
|
|
1846
|
-
},
|
|
1847
|
-
list: () => [skins.get("default") ?? DEFAULT_SKIN, ...[...skins.values()].filter((skin) => skin.id !== DEFAULT_SKIN_ID)],
|
|
1848
|
-
active: () => skins.get(activeId) ?? DEFAULT_SKIN,
|
|
1849
|
-
setMode(next) {
|
|
1850
|
-
if (mode === next) return;
|
|
1851
|
-
mode = next;
|
|
1852
|
-
refresh();
|
|
1853
|
-
},
|
|
1854
|
-
mode: () => mode,
|
|
1855
|
-
presentation(target) {
|
|
1856
|
-
return (skins.get(activeId) ?? DEFAULT_SKIN).presentations?.[target];
|
|
1857
|
-
},
|
|
1858
|
-
tokens: () => (skins.get(activeId) ?? DEFAULT_SKIN).tokens[mode],
|
|
1859
|
-
subscribe(listener) {
|
|
1860
|
-
listeners.add(listener);
|
|
1861
|
-
return () => {
|
|
1862
|
-
listeners.delete(listener);
|
|
1863
|
-
};
|
|
1864
|
-
},
|
|
1865
|
-
version: () => revision
|
|
2871
|
+
render: () => jsx(SettingsSurface, {
|
|
2872
|
+
service,
|
|
2873
|
+
ctx
|
|
2874
|
+
})
|
|
1866
2875
|
});
|
|
1867
|
-
refresh();
|
|
1868
2876
|
}
|
|
1869
2877
|
};
|
|
1870
|
-
/** The React context carrying the skin service. */
|
|
1871
|
-
const SkinsContext = createContext(null);
|
|
1872
|
-
/** Provide the skin service to a renderer tree. */
|
|
1873
|
-
function SkinsProvider(props) {
|
|
1874
|
-
return jsx(SkinsContext.Provider, {
|
|
1875
|
-
value: props.service,
|
|
1876
|
-
children: props.children
|
|
1877
|
-
});
|
|
1878
|
-
}
|
|
1879
2878
|
//#endregion
|
|
1880
2879
|
//#region lib/types/runtime.js
|
|
2880
|
+
/**
|
|
2881
|
+
* The built-in renderer runtime: it takes over the kernel root, mounts the
|
|
2882
|
+
* core services, the skins, the layout/page plugins, and finally the fallback
|
|
2883
|
+
* layout. There is no framework row and no framework seed: the substrate is
|
|
2884
|
+
* always present, so a fresh install has a usable UI before any plugin is
|
|
2885
|
+
* installed.
|
|
2886
|
+
*
|
|
2887
|
+
* @module @snap-rail/ui/runtime
|
|
2888
|
+
*/
|
|
1881
2889
|
/** The React context carrying the host link/surface into builtin pages. */
|
|
1882
2890
|
const ClientContext = createContext(null);
|
|
1883
2891
|
/** Provide the client services to builtin page components. */
|
|
@@ -1893,6 +2901,14 @@ function useClient() {
|
|
|
1893
2901
|
if (service === null) throw new Error("useClient: no ClientProvider in the tree");
|
|
1894
2902
|
return service;
|
|
1895
2903
|
}
|
|
2904
|
+
/**
|
|
2905
|
+
* Wire an element as a ball face's single drag/click surface. Past the travel
|
|
2906
|
+
* threshold the face only signals `shell.ball.move` `begin`/`end`; the host
|
|
2907
|
+
* anchors the grab from the OS cursor and runs the dock settle, so the face
|
|
2908
|
+
* never streams coordinates. A press-release inside the threshold is the
|
|
2909
|
+
* click. Returns the disposer removing every listener.
|
|
2910
|
+
*/
|
|
2911
|
+
const attachBallDrag = attachBallDrag$1;
|
|
1896
2912
|
/** Re-render on settings open/page changes. */
|
|
1897
2913
|
function useSettingsVersion(ctx) {
|
|
1898
2914
|
return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
|
|
@@ -1950,7 +2966,7 @@ function SettingsFallbackHost(props) {
|
|
|
1950
2966
|
/** The operator-window root. */
|
|
1951
2967
|
function MainRoot(props) {
|
|
1952
2968
|
const layout = useActiveLayout();
|
|
1953
|
-
return
|
|
2969
|
+
return jsx(Fragment, { children: jsxs(TooltipProvider, { children: [
|
|
1954
2970
|
jsx(StageProfiles, {
|
|
1955
2971
|
ctx: props.ctx,
|
|
1956
2972
|
layout
|
|
@@ -1960,32 +2976,81 @@ function MainRoot(props) {
|
|
|
1960
2976
|
children: "没有已加载的布局插件。"
|
|
1961
2977
|
}) : layout.render(),
|
|
1962
2978
|
jsx(OverlayHost, { ctx: props.ctx }),
|
|
1963
|
-
jsx(SettingsFallbackHost, { ctx: props.ctx })
|
|
1964
|
-
|
|
2979
|
+
jsx(SettingsFallbackHost, { ctx: props.ctx }),
|
|
2980
|
+
jsx(Toaster, {})
|
|
2981
|
+
] }) });
|
|
1965
2982
|
}
|
|
1966
|
-
/**
|
|
2983
|
+
/**
|
|
2984
|
+
* The fallback ball face used when no plugin occupies `shell.ball`: a themed
|
|
2985
|
+
* disc that follows the active skin tokens (visible on any colour mode). The
|
|
2986
|
+
* whole ball is one drag/click surface ({@link attachBallDrag}): press-move
|
|
2987
|
+
* drags the window over `shell.ball.move`, a press-release summons the
|
|
2988
|
+
* operator window — the same anatomy the kernel's crash fallback paints.
|
|
2989
|
+
*/
|
|
1967
2990
|
function BallRoot(props) {
|
|
1968
2991
|
useUiVersion(props.ctx.ui);
|
|
1969
2992
|
const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
|
|
1970
|
-
|
|
2993
|
+
const link = props.ctx.client.link;
|
|
2994
|
+
const hasOccupant = occupant !== void 0;
|
|
2995
|
+
const rootRef = useRef(null);
|
|
2996
|
+
useEffect(() => {
|
|
2997
|
+
if (hasOccupant) return void 0;
|
|
2998
|
+
const element = rootRef.current;
|
|
2999
|
+
if (element === null) return void 0;
|
|
3000
|
+
return attachBallDrag(element, {
|
|
3001
|
+
link,
|
|
3002
|
+
onClick: () => {
|
|
3003
|
+
link.call("shell.surface.present", { surface: "main" });
|
|
3004
|
+
}
|
|
3005
|
+
});
|
|
3006
|
+
}, [hasOccupant, link]);
|
|
3007
|
+
if (occupant !== void 0) return jsxs(TooltipProvider, { children: [jsx("div", {
|
|
1971
3008
|
style: {
|
|
1972
3009
|
width: "100%",
|
|
1973
3010
|
height: "100%"
|
|
1974
3011
|
},
|
|
1975
3012
|
children: occupant.render({ surface: "ball" })
|
|
1976
|
-
});
|
|
3013
|
+
}), jsx(Toaster, {})] });
|
|
1977
3014
|
return jsx("div", {
|
|
3015
|
+
ref: rootRef,
|
|
1978
3016
|
"data-snap-part": "ball.root",
|
|
1979
3017
|
style: {
|
|
1980
3018
|
display: "flex",
|
|
1981
3019
|
alignItems: "center",
|
|
1982
3020
|
justifyContent: "center",
|
|
1983
3021
|
width: "100%",
|
|
1984
|
-
height: "100%"
|
|
1985
|
-
color: "var(--snap-color-muted)",
|
|
1986
|
-
fontSize: "var(--snap-text-xs)"
|
|
3022
|
+
height: "100%"
|
|
1987
3023
|
},
|
|
1988
|
-
children: "
|
|
3024
|
+
children: jsx("div", {
|
|
3025
|
+
"data-snap-part": "ball.orb",
|
|
3026
|
+
style: {
|
|
3027
|
+
display: "flex",
|
|
3028
|
+
alignItems: "center",
|
|
3029
|
+
justifyContent: "center",
|
|
3030
|
+
width: "calc(100% - 16px)",
|
|
3031
|
+
height: "calc(100% - 16px)",
|
|
3032
|
+
borderRadius: "50%",
|
|
3033
|
+
background: "var(--snap-color-surface-raised)",
|
|
3034
|
+
border: "var(--snap-border-width) solid var(--snap-color-border)"
|
|
3035
|
+
},
|
|
3036
|
+
children: jsx("button", {
|
|
3037
|
+
type: "button",
|
|
3038
|
+
"data-snap-part": "ball.core",
|
|
3039
|
+
title: "打开主窗口",
|
|
3040
|
+
style: {
|
|
3041
|
+
width: "calc(100% - 16px)",
|
|
3042
|
+
height: "calc(100% - 16px)",
|
|
3043
|
+
borderRadius: "50%",
|
|
3044
|
+
border: "none",
|
|
3045
|
+
background: "var(--snap-color-surface)",
|
|
3046
|
+
color: "var(--snap-color-text)",
|
|
3047
|
+
fontSize: "var(--snap-text-xs)",
|
|
3048
|
+
fontWeight: "var(--snap-weight-medium)",
|
|
3049
|
+
cursor: "default"
|
|
3050
|
+
},
|
|
3051
|
+
children: "snap-rail"
|
|
3052
|
+
})
|
|
3053
|
+
})
|
|
1989
3054
|
});
|
|
1990
3055
|
}
|
|
1991
3056
|
/** The root that mounts the layout (or the ball face) and the global overlays. */
|
|
@@ -2020,12 +3085,9 @@ async function createClientRuntime(handle, options) {
|
|
|
2020
3085
|
await ctx.plugin(skinsPlugin);
|
|
2021
3086
|
await ctx.plugin(settingsPlugin);
|
|
2022
3087
|
const applyThemeRow = (value) => {
|
|
2023
|
-
const
|
|
2024
|
-
const
|
|
2025
|
-
|
|
2026
|
-
const resolved = choice === "system" ? prefersLight ? "light" : "dark" : choice;
|
|
2027
|
-
ctx.skins.setMode(resolved);
|
|
2028
|
-
if (typeof document !== "undefined") document.documentElement.dataset["mode"] = resolved;
|
|
3088
|
+
const row = value;
|
|
3089
|
+
const selection = typeof row?.id === "string" && row.id !== "" ? row.id : row?.mode === "light" ? DEFAULT_LIGHT_ID : DEFAULT_DARK_ID;
|
|
3090
|
+
if (!ctx.skins.activate(selection)) ctx.skins.activate(DEFAULT_DARK_ID);
|
|
2029
3091
|
};
|
|
2030
3092
|
handle.link.call("settings.get", { key: "ui.theme" }).then((result) => {
|
|
2031
3093
|
if (result.ok) applyThemeRow(result.value.value);
|
|
@@ -2061,4 +3123,4 @@ async function createClientRuntime(handle, options) {
|
|
|
2061
3123
|
};
|
|
2062
3124
|
}
|
|
2063
3125
|
//#endregion
|
|
2064
|
-
export { ClientProvider, Slot, createClientRuntime, fallbackPlugin, pagesPlugin, settingsPlugin, skinsPlugin, slotsPlugin, useClient };
|
|
3126
|
+
export { ClientProvider, Slot, attachBallDrag, createClientRuntime, fallbackPlugin, pagesPlugin, settingsPlugin, skinsPlugin, slotsPlugin, useClient };
|