@snap-rail/ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/lib/charts.js +118 -0
- package/lib/contract.js +527 -0
- package/lib/fallback.js +399 -0
- package/lib/index.js +1282 -0
- package/lib/pages.js +68 -0
- package/lib/runtime.js +3003 -0
- package/lib/settings.js +2069 -0
- package/lib/skins.js +258 -0
- package/lib/slots.js +267 -0
- package/lib/types/charts.d.ts +62 -0
- package/lib/types/charts.js +41 -0
- package/lib/types/components/button.d.ts +39 -0
- package/lib/types/components/button.js +27 -0
- package/lib/types/components/controls.d.ts +66 -0
- package/lib/types/components/controls.js +66 -0
- package/lib/types/components/dialog.d.ts +58 -0
- package/lib/types/components/dialog.js +46 -0
- package/lib/types/components/feedback.d.ts +46 -0
- package/lib/types/components/feedback.js +20 -0
- package/lib/types/components/form.d.ts +31 -0
- package/lib/types/components/form.js +13 -0
- package/lib/types/components/index.d.ts +15 -0
- package/lib/types/components/index.js +15 -0
- package/lib/types/components/input.d.ts +40 -0
- package/lib/types/components/input.js +18 -0
- package/lib/types/components/layout.d.ts +103 -0
- package/lib/types/components/layout.js +80 -0
- package/lib/types/components/schema-form.d.ts +44 -0
- package/lib/types/components/schema-form.js +84 -0
- package/lib/types/components/surface.d.ts +49 -0
- package/lib/types/components/surface.js +59 -0
- package/lib/types/contract.d.ts +350 -0
- package/lib/types/contract.js +231 -0
- package/lib/types/fallback.d.ts +14 -0
- package/lib/types/fallback.js +50 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/index.js +19 -0
- package/lib/types/pages.d.ts +40 -0
- package/lib/types/pages.js +69 -0
- package/lib/types/runtime.d.ts +93 -0
- package/lib/types/runtime.js +233 -0
- package/lib/types/settings-pages/appearance.d.ts +15 -0
- package/lib/types/settings-pages/appearance.js +128 -0
- package/lib/types/settings-pages/index.d.ts +3 -0
- package/lib/types/settings-pages/index.js +3 -0
- 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 +21 -0
- package/lib/types/settings-pages/plugins.js +372 -0
- package/lib/types/settings.d.ts +59 -0
- package/lib/types/settings.js +176 -0
- package/lib/types/skins.d.ts +137 -0
- package/lib/types/skins.js +271 -0
- package/lib/types/slots.d.ts +69 -0
- package/lib/types/slots.js +210 -0
- package/lib/types/utils.d.ts +15 -0
- package/lib/types/utils.js +26 -0
- package/package.json +105 -3
- package/src/styles/base.css +329 -0
- package/src/styles/default.css +735 -0
- package/README.md +0 -3
package/lib/settings.js
ADDED
|
@@ -0,0 +1,2069 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Component, createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
4
|
+
import "@radix-ui/react-checkbox";
|
|
5
|
+
import "@radix-ui/react-label";
|
|
6
|
+
import "@radix-ui/react-radio-group";
|
|
7
|
+
import "@radix-ui/react-select";
|
|
8
|
+
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
|
9
|
+
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
10
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
11
|
+
import { rpcErrorText } from "@snap-rail/connection";
|
|
12
|
+
import "@snap-rail/client-kernel";
|
|
13
|
+
import "@snap-rail/station-rpc/contract";
|
|
14
|
+
import "@snap-rail/cordis";
|
|
15
|
+
import "@snap-rail/cordis-plugin-timer";
|
|
16
|
+
import "@snap-rail/shell/contract";
|
|
17
|
+
import "react-dom/client";
|
|
18
|
+
import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
|
|
19
|
+
//#region lib/types/utils.js
|
|
20
|
+
/**
|
|
21
|
+
* Small helpers shared by the headless semantic components: class merging and
|
|
22
|
+
* the stable `data-snap-*` anatomy that skins target.
|
|
23
|
+
*
|
|
24
|
+
* @module @snap-rail/ui/utils
|
|
25
|
+
*/
|
|
26
|
+
/** Join truthy class names. */
|
|
27
|
+
function cn(...values) {
|
|
28
|
+
return values.filter((value) => typeof value === "string" && value.length > 0).join(" ");
|
|
29
|
+
}
|
|
30
|
+
/** The anatomy attributes every semantic component renders. */
|
|
31
|
+
function part(component, name) {
|
|
32
|
+
return {
|
|
33
|
+
"data-snap-component": component,
|
|
34
|
+
"data-snap-part": `${component}.${name}`
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Map a semantic spacing token to a CSS variable. */
|
|
38
|
+
function space(token) {
|
|
39
|
+
return `var(--snap-space-${token})`;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region lib/types/components/button.js
|
|
43
|
+
/**
|
|
44
|
+
* Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
|
|
45
|
+
* `button.root`, `button.label`, `button.icon`, and `button.spinner` parts;
|
|
46
|
+
* intent/emphasis/size are data attributes a skin styles.
|
|
47
|
+
*
|
|
48
|
+
* @module @snap-rail/ui/components/button
|
|
49
|
+
*/
|
|
50
|
+
/** A spinner that inherits the current text colour. */
|
|
51
|
+
function Spinner(props) {
|
|
52
|
+
return jsxs("svg", {
|
|
53
|
+
...part("button", "spinner"),
|
|
54
|
+
className: cn("snap-spinner", props.className),
|
|
55
|
+
viewBox: "0 0 24 24",
|
|
56
|
+
"aria-hidden": "true",
|
|
57
|
+
children: [jsx("circle", {
|
|
58
|
+
cx: "12",
|
|
59
|
+
cy: "12",
|
|
60
|
+
r: "9",
|
|
61
|
+
fill: "none",
|
|
62
|
+
stroke: "currentColor",
|
|
63
|
+
strokeWidth: "3",
|
|
64
|
+
opacity: "0.25"
|
|
65
|
+
}), jsx("path", {
|
|
66
|
+
d: "M21 12a9 9 0 0 0-9-9",
|
|
67
|
+
fill: "none",
|
|
68
|
+
stroke: "currentColor",
|
|
69
|
+
strokeWidth: "3",
|
|
70
|
+
strokeLinecap: "round"
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** A themed button; `asChild` composes the behaviour onto a child element. */
|
|
75
|
+
function Button({ intent = "neutral", emphasis = "solid", size = "md", loading = false, icon, iconPosition = "start", asChild = false, disabled, className, children, type, ...props }) {
|
|
76
|
+
const Component = asChild ? Slot : "button";
|
|
77
|
+
const content = asChild ? children : jsxs(Fragment, { children: [
|
|
78
|
+
icon !== void 0 && iconPosition === "start" && jsx("span", {
|
|
79
|
+
...part("button", "icon"),
|
|
80
|
+
children: icon
|
|
81
|
+
}),
|
|
82
|
+
children !== void 0 && jsx("span", {
|
|
83
|
+
...part("button", "label"),
|
|
84
|
+
children
|
|
85
|
+
}),
|
|
86
|
+
icon !== void 0 && iconPosition === "end" && jsx("span", {
|
|
87
|
+
...part("button", "icon"),
|
|
88
|
+
children: icon
|
|
89
|
+
}),
|
|
90
|
+
loading && jsx(Spinner, {})
|
|
91
|
+
] });
|
|
92
|
+
return jsx(Component, {
|
|
93
|
+
...part("button", "root"),
|
|
94
|
+
...type !== void 0 ? { type } : !asChild ? { type: "button" } : {},
|
|
95
|
+
className: cn("snap-button", className),
|
|
96
|
+
"data-intent": intent,
|
|
97
|
+
"data-emphasis": emphasis,
|
|
98
|
+
"data-size": size,
|
|
99
|
+
"data-loading": loading || void 0,
|
|
100
|
+
"data-disabled": disabled === true || void 0,
|
|
101
|
+
"aria-busy": loading || void 0,
|
|
102
|
+
disabled: !asChild ? disabled === true || loading : void 0,
|
|
103
|
+
...props,
|
|
104
|
+
children: content
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** A square glyph button with a mandatory accessible label. */
|
|
108
|
+
function IconButton({ icon, label, active = false, intent = "neutral", emphasis = "ghost", size = "md", className, ...props }) {
|
|
109
|
+
return jsx("button", {
|
|
110
|
+
...part("icon-button", "root"),
|
|
111
|
+
type: "button",
|
|
112
|
+
className: cn("snap-icon-button", className),
|
|
113
|
+
"data-intent": intent,
|
|
114
|
+
"data-emphasis": emphasis,
|
|
115
|
+
"data-size": size,
|
|
116
|
+
"data-active": active || void 0,
|
|
117
|
+
"aria-label": label,
|
|
118
|
+
"aria-pressed": active || void 0,
|
|
119
|
+
...props,
|
|
120
|
+
children: jsx("span", {
|
|
121
|
+
...part("icon-button", "icon"),
|
|
122
|
+
"aria-hidden": "true",
|
|
123
|
+
children: icon
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region lib/types/components/dialog.js
|
|
129
|
+
/**
|
|
130
|
+
* Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
|
|
131
|
+
* the presentation (modal, sheet, fullscreen) through the `presentation`
|
|
132
|
+
* attribute; the core owns dismissal and focus behaviour.
|
|
133
|
+
*
|
|
134
|
+
* @module @snap-rail/ui/components/dialog
|
|
135
|
+
*/
|
|
136
|
+
/** The dialog root. */
|
|
137
|
+
const Dialog = DialogPrimitive.Root;
|
|
138
|
+
/** The portalled dialog content. */
|
|
139
|
+
function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
|
|
140
|
+
const resolved = presentation === "auto" ? "modal" : presentation;
|
|
141
|
+
return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
|
|
142
|
+
...part("dialog", "overlay"),
|
|
143
|
+
className: "snap-dialog-overlay"
|
|
144
|
+
}), jsxs(DialogPrimitive.Content, {
|
|
145
|
+
...part("dialog", "panel"),
|
|
146
|
+
className: cn("snap-dialog-panel", className),
|
|
147
|
+
"data-presentation": resolved,
|
|
148
|
+
"data-size": size,
|
|
149
|
+
...rest,
|
|
150
|
+
children: [children, showClose && jsx(DialogPrimitive.Close, {
|
|
151
|
+
...part("dialog", "close"),
|
|
152
|
+
className: "snap-dialog-close",
|
|
153
|
+
"aria-label": "关闭",
|
|
154
|
+
children: "×"
|
|
155
|
+
})]
|
|
156
|
+
})] });
|
|
157
|
+
}
|
|
158
|
+
/** The dialog header. */
|
|
159
|
+
function DialogHeader({ children, className }) {
|
|
160
|
+
return jsx("div", {
|
|
161
|
+
...part("dialog", "header"),
|
|
162
|
+
className: cn("snap-dialog-header", className),
|
|
163
|
+
children
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/** The dialog title. */
|
|
167
|
+
function DialogTitle({ children, className }) {
|
|
168
|
+
return jsx(DialogPrimitive.Title, {
|
|
169
|
+
...part("dialog", "title"),
|
|
170
|
+
className: cn("snap-dialog-title", className),
|
|
171
|
+
children
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/** The dialog description. */
|
|
175
|
+
function DialogDescription({ children, className }) {
|
|
176
|
+
return jsx(DialogPrimitive.Description, {
|
|
177
|
+
...part("dialog", "description"),
|
|
178
|
+
className: cn("snap-dialog-description", className),
|
|
179
|
+
children
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** The dialog body. */
|
|
183
|
+
function DialogBody({ children, className }) {
|
|
184
|
+
return jsx("div", {
|
|
185
|
+
...part("dialog", "body"),
|
|
186
|
+
className: cn("snap-dialog-body", className),
|
|
187
|
+
children
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/** The dialog footer. */
|
|
191
|
+
function DialogFooter({ children, className }) {
|
|
192
|
+
return jsx("div", {
|
|
193
|
+
...part("dialog", "footer"),
|
|
194
|
+
className: cn("snap-dialog-footer", className),
|
|
195
|
+
children
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region lib/types/components/controls.js
|
|
200
|
+
/** The tabs root. */
|
|
201
|
+
const Tabs = TabsPrimitive.Root;
|
|
202
|
+
/** The tabs list. */
|
|
203
|
+
function TabsList({ className, children, ...props }) {
|
|
204
|
+
return jsx(TabsPrimitive.List, {
|
|
205
|
+
...part("tabs", "list"),
|
|
206
|
+
className: cn("snap-tabs-list", className),
|
|
207
|
+
...props,
|
|
208
|
+
children
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/** A tab trigger. */
|
|
212
|
+
function TabsTrigger({ className, children, ...props }) {
|
|
213
|
+
return jsx(TabsPrimitive.Trigger, {
|
|
214
|
+
...part("tabs", "trigger"),
|
|
215
|
+
className: cn("snap-tabs-trigger", className),
|
|
216
|
+
...props,
|
|
217
|
+
children
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/** A boolean switch. */
|
|
221
|
+
function Switch({ className, label, ...props }) {
|
|
222
|
+
return jsxs("label", {
|
|
223
|
+
className: "snap-switch-label",
|
|
224
|
+
children: [jsx(SwitchPrimitive.Root, {
|
|
225
|
+
...part("switch", "root"),
|
|
226
|
+
className: cn("snap-switch", className),
|
|
227
|
+
...props,
|
|
228
|
+
children: jsx(SwitchPrimitive.Thumb, {
|
|
229
|
+
...part("switch", "thumb"),
|
|
230
|
+
className: "snap-switch-thumb"
|
|
231
|
+
})
|
|
232
|
+
}), label !== void 0 && jsx("span", {
|
|
233
|
+
...part("switch", "label"),
|
|
234
|
+
children: label
|
|
235
|
+
})]
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region lib/types/components/feedback.js
|
|
240
|
+
/** A compact status/count label. */
|
|
241
|
+
function Badge({ children, intent = "neutral", className }) {
|
|
242
|
+
return jsx("span", {
|
|
243
|
+
...part("badge", "root"),
|
|
244
|
+
className: cn("snap-badge", className),
|
|
245
|
+
"data-intent": intent,
|
|
246
|
+
children
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/** A centered empty/zero-state block. */
|
|
250
|
+
function EmptyState({ title, description, icon, action, className }) {
|
|
251
|
+
return jsxs("div", {
|
|
252
|
+
...part("empty-state", "root"),
|
|
253
|
+
className: cn("snap-empty-state", className),
|
|
254
|
+
children: [
|
|
255
|
+
icon !== void 0 && jsx("div", {
|
|
256
|
+
...part("empty-state", "icon"),
|
|
257
|
+
children: icon
|
|
258
|
+
}),
|
|
259
|
+
jsx("div", {
|
|
260
|
+
...part("empty-state", "title"),
|
|
261
|
+
children: title
|
|
262
|
+
}),
|
|
263
|
+
description !== void 0 && jsx("div", {
|
|
264
|
+
...part("empty-state", "description"),
|
|
265
|
+
children: description
|
|
266
|
+
}),
|
|
267
|
+
action !== void 0 && jsx("div", {
|
|
268
|
+
...part("empty-state", "action"),
|
|
269
|
+
children: action
|
|
270
|
+
})
|
|
271
|
+
]
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region lib/types/components/input.js
|
|
276
|
+
/** A single-line text field with semantic prefix/suffix slots. Layout
|
|
277
|
+
* `style`/`className` dress the wrapper — the visible control; the native
|
|
278
|
+
* field already stretches inside it. */
|
|
279
|
+
function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, style, disabled, ...props }) {
|
|
280
|
+
return jsxs("div", {
|
|
281
|
+
...part(componentName, "root"),
|
|
282
|
+
className: cn("snap-input", className),
|
|
283
|
+
style,
|
|
284
|
+
"data-size": size,
|
|
285
|
+
"data-invalid": invalid || void 0,
|
|
286
|
+
"data-disabled": disabled === true || void 0,
|
|
287
|
+
children: [
|
|
288
|
+
prefix !== void 0 && jsx("span", {
|
|
289
|
+
...part(componentName, "prefix"),
|
|
290
|
+
children: prefix
|
|
291
|
+
}),
|
|
292
|
+
jsx("input", {
|
|
293
|
+
...part(componentName, "field"),
|
|
294
|
+
className: "snap-input-field",
|
|
295
|
+
disabled,
|
|
296
|
+
"aria-invalid": invalid || void 0,
|
|
297
|
+
...props
|
|
298
|
+
}),
|
|
299
|
+
onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
|
|
300
|
+
...part(componentName, "clear"),
|
|
301
|
+
type: "button",
|
|
302
|
+
className: "snap-input-clear",
|
|
303
|
+
"aria-label": "清除",
|
|
304
|
+
onClick: onClear,
|
|
305
|
+
children: "×"
|
|
306
|
+
}),
|
|
307
|
+
suffix !== void 0 && jsx("span", {
|
|
308
|
+
...part(componentName, "suffix"),
|
|
309
|
+
children: suffix
|
|
310
|
+
})
|
|
311
|
+
]
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region lib/types/components/layout.js
|
|
316
|
+
/** A vertical flow. */
|
|
317
|
+
function Stack({ gap = "md", padding, align, className, style, children }) {
|
|
318
|
+
return jsx("div", {
|
|
319
|
+
...part("stack", "root"),
|
|
320
|
+
className: cn("snap-stack", className),
|
|
321
|
+
style: {
|
|
322
|
+
display: "flex",
|
|
323
|
+
flexDirection: "column",
|
|
324
|
+
gap: space(gap),
|
|
325
|
+
...padding !== void 0 ? { padding: space(padding) } : {},
|
|
326
|
+
...align !== void 0 ? { alignItems: align } : {},
|
|
327
|
+
...style
|
|
328
|
+
},
|
|
329
|
+
children
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/** A horizontal flow. */
|
|
333
|
+
function Row({ gap = "sm", padding, align, justify, wrap = false, className, style, children }) {
|
|
334
|
+
return jsx("div", {
|
|
335
|
+
...part("row", "root"),
|
|
336
|
+
className: cn("snap-row", className),
|
|
337
|
+
style: {
|
|
338
|
+
display: "flex",
|
|
339
|
+
flexDirection: "row",
|
|
340
|
+
gap: space(gap),
|
|
341
|
+
...padding !== void 0 ? { padding: space(padding) } : {},
|
|
342
|
+
...align !== void 0 ? { alignItems: align } : {},
|
|
343
|
+
...justify !== void 0 ? { justifyContent: justify } : {},
|
|
344
|
+
...wrap ? { flexWrap: "wrap" } : {},
|
|
345
|
+
...style
|
|
346
|
+
},
|
|
347
|
+
children
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/** A page body with its own header/actions anatomy. */
|
|
351
|
+
function Page({ header, actions, title, titleExtra, description, className, style, children }) {
|
|
352
|
+
return jsxs("div", {
|
|
353
|
+
...part("page", "root"),
|
|
354
|
+
className: cn("snap-page", className),
|
|
355
|
+
style: {
|
|
356
|
+
display: "flex",
|
|
357
|
+
flexDirection: "column",
|
|
358
|
+
minHeight: 0,
|
|
359
|
+
...style
|
|
360
|
+
},
|
|
361
|
+
children: [(header !== void 0 || title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("div", {
|
|
362
|
+
...part("page", "header"),
|
|
363
|
+
style: {
|
|
364
|
+
display: "flex",
|
|
365
|
+
flexDirection: "column",
|
|
366
|
+
gap: space("sm"),
|
|
367
|
+
flexShrink: 0
|
|
368
|
+
},
|
|
369
|
+
children: [
|
|
370
|
+
jsxs("div", {
|
|
371
|
+
style: {
|
|
372
|
+
display: "flex",
|
|
373
|
+
alignItems: "flex-start",
|
|
374
|
+
justifyContent: "space-between",
|
|
375
|
+
gap: space("md")
|
|
376
|
+
},
|
|
377
|
+
children: [jsxs("div", {
|
|
378
|
+
style: {
|
|
379
|
+
display: "flex",
|
|
380
|
+
alignItems: "center",
|
|
381
|
+
gap: space("sm")
|
|
382
|
+
},
|
|
383
|
+
children: [title !== void 0 && jsx("div", {
|
|
384
|
+
...part("page", "title"),
|
|
385
|
+
children: title
|
|
386
|
+
}), titleExtra !== void 0 && jsx("div", {
|
|
387
|
+
...part("page", "title-extra"),
|
|
388
|
+
children: titleExtra
|
|
389
|
+
})]
|
|
390
|
+
}), actions !== void 0 && jsx("div", {
|
|
391
|
+
...part("page", "actions"),
|
|
392
|
+
children: actions
|
|
393
|
+
})]
|
|
394
|
+
}),
|
|
395
|
+
description !== void 0 && jsx("div", {
|
|
396
|
+
...part("page", "description"),
|
|
397
|
+
children: description
|
|
398
|
+
}),
|
|
399
|
+
header
|
|
400
|
+
]
|
|
401
|
+
}), jsx("div", {
|
|
402
|
+
...part("page", "body"),
|
|
403
|
+
style: {
|
|
404
|
+
display: "flex",
|
|
405
|
+
flexDirection: "column",
|
|
406
|
+
flex: 1,
|
|
407
|
+
minHeight: 0
|
|
408
|
+
},
|
|
409
|
+
children
|
|
410
|
+
})]
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
/** A titled content section. */
|
|
414
|
+
function Section({ title, description, actions, className, style, children }) {
|
|
415
|
+
return jsxs("section", {
|
|
416
|
+
...part("section", "root"),
|
|
417
|
+
className: cn("snap-section", className),
|
|
418
|
+
style: {
|
|
419
|
+
display: "flex",
|
|
420
|
+
flexDirection: "column",
|
|
421
|
+
gap: space("sm"),
|
|
422
|
+
...style
|
|
423
|
+
},
|
|
424
|
+
children: [(title !== void 0 || actions !== void 0) && jsxs("div", {
|
|
425
|
+
...part("section", "header"),
|
|
426
|
+
style: {
|
|
427
|
+
display: "flex",
|
|
428
|
+
alignItems: "center",
|
|
429
|
+
justifyContent: "space-between",
|
|
430
|
+
gap: space("md")
|
|
431
|
+
},
|
|
432
|
+
children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
|
|
433
|
+
...part("section", "title"),
|
|
434
|
+
children: title
|
|
435
|
+
}), description !== void 0 && jsx("div", { children: description })] }), actions !== void 0 && jsx("div", {
|
|
436
|
+
...part("section", "actions"),
|
|
437
|
+
children: actions
|
|
438
|
+
})]
|
|
439
|
+
}), jsx("div", {
|
|
440
|
+
...part("section", "body"),
|
|
441
|
+
children
|
|
442
|
+
})]
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region lib/types/components/surface.js
|
|
447
|
+
/** A semantic table. */
|
|
448
|
+
function Table({ className, children, ...props }) {
|
|
449
|
+
return jsx("div", {
|
|
450
|
+
...part("table", "root"),
|
|
451
|
+
className: cn("snap-table", className),
|
|
452
|
+
children: jsx("table", {
|
|
453
|
+
...props,
|
|
454
|
+
children
|
|
455
|
+
})
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
/** The table head. */
|
|
459
|
+
function TableHeader({ className, children, ...props }) {
|
|
460
|
+
return jsx("thead", {
|
|
461
|
+
...part("table", "header"),
|
|
462
|
+
className: cn("snap-table-header", className),
|
|
463
|
+
...props,
|
|
464
|
+
children
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
/** The table body. */
|
|
468
|
+
function TableBody({ className, children, ...props }) {
|
|
469
|
+
return jsx("tbody", {
|
|
470
|
+
...part("table", "body"),
|
|
471
|
+
className: cn("snap-table-body", className),
|
|
472
|
+
...props,
|
|
473
|
+
children
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
/** A table row. */
|
|
477
|
+
function TableRow({ className, children, ...props }) {
|
|
478
|
+
return jsx("tr", {
|
|
479
|
+
...part("table", "row"),
|
|
480
|
+
className: cn("snap-table-row", className),
|
|
481
|
+
...props,
|
|
482
|
+
children
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
/** A table header cell. */
|
|
486
|
+
function TableHead({ className, children, ...props }) {
|
|
487
|
+
return jsx("th", {
|
|
488
|
+
...part("table", "head"),
|
|
489
|
+
className: cn("snap-table-head", className),
|
|
490
|
+
...props,
|
|
491
|
+
children
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
/** A table body cell. */
|
|
495
|
+
function TableCell({ className, children, ...props }) {
|
|
496
|
+
return jsx("td", {
|
|
497
|
+
...part("table", "cell"),
|
|
498
|
+
className: cn("snap-table-cell", className),
|
|
499
|
+
...props,
|
|
500
|
+
children
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region lib/types/contract.js
|
|
505
|
+
/** The stable region slots every layout may provide. */
|
|
506
|
+
const UI_SLOT_IDS = {
|
|
507
|
+
/** The one active layout of the operator window. */
|
|
508
|
+
layout: "shell.layout",
|
|
509
|
+
/** The operator titlebar. */
|
|
510
|
+
titlebar: "shell.titlebar",
|
|
511
|
+
/** Contributed titlebar actions. */
|
|
512
|
+
titlebarActions: "shell.titlebar.actions",
|
|
513
|
+
/** Sidebar extension area. */
|
|
514
|
+
sidebar: "shell.sidebar",
|
|
515
|
+
/** Statusbar extension area. */
|
|
516
|
+
statusbar: "shell.statusbar",
|
|
517
|
+
/** The global overlay stack (dialogs, confirms). */
|
|
518
|
+
overlay: "shell.overlay",
|
|
519
|
+
/** The floating ball surface face. */
|
|
520
|
+
ball: "shell.ball",
|
|
521
|
+
/** The settings trigger. */
|
|
522
|
+
settingsEntry: "settings.entry",
|
|
523
|
+
/** The settings surface itself. */
|
|
524
|
+
settingsSurface: "settings.surface"
|
|
525
|
+
};
|
|
526
|
+
UI_SLOT_IDS.layout, UI_SLOT_IDS.titlebar, UI_SLOT_IDS.titlebarActions, UI_SLOT_IDS.sidebar, UI_SLOT_IDS.statusbar, UI_SLOT_IDS.overlay, UI_SLOT_IDS.ball, UI_SLOT_IDS.settingsEntry, UI_SLOT_IDS.settingsSurface;
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region lib/types/skins.js
|
|
529
|
+
/** The React context carrying the skin service. */
|
|
530
|
+
const SkinsContext = createContext(null);
|
|
531
|
+
/** Read the skin service. */
|
|
532
|
+
function useSkins() {
|
|
533
|
+
const service = useContext(SkinsContext);
|
|
534
|
+
if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
|
|
535
|
+
return service;
|
|
536
|
+
}
|
|
537
|
+
/** Re-render on theme changes and return the active theme id. */
|
|
538
|
+
function useSkinId() {
|
|
539
|
+
const service = useSkins();
|
|
540
|
+
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
541
|
+
return service.active().id;
|
|
542
|
+
}
|
|
543
|
+
createContext(null);
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region lib/types/runtime.js
|
|
546
|
+
/** The React context carrying the host link/surface into builtin pages. */
|
|
547
|
+
const ClientContext = createContext(null);
|
|
548
|
+
/** Read the client services (host link + surface) from a builtin page. */
|
|
549
|
+
function useClient() {
|
|
550
|
+
const service = useContext(ClientContext);
|
|
551
|
+
if (service === null) throw new Error("useClient: no ClientProvider in the tree");
|
|
552
|
+
return service;
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region lib/types/settings-pages/appearance.js
|
|
556
|
+
const THEME_KEY = "ui.theme";
|
|
557
|
+
const WINDOW_KEY = "ui.window";
|
|
558
|
+
const BALL_KEY = "ui.ball";
|
|
559
|
+
const WINDOW_PRESETS = [
|
|
560
|
+
{
|
|
561
|
+
label: "1280 × 800",
|
|
562
|
+
width: 1280,
|
|
563
|
+
height: 800
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
label: "1440 × 900",
|
|
567
|
+
width: 1440,
|
|
568
|
+
height: 900
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
label: "1600 × 900",
|
|
572
|
+
width: 1600,
|
|
573
|
+
height: 900
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
label: "1920 × 1080",
|
|
577
|
+
width: 1920,
|
|
578
|
+
height: 1080
|
|
579
|
+
}
|
|
580
|
+
];
|
|
581
|
+
const BALL_SIZES = [
|
|
582
|
+
96,
|
|
583
|
+
112,
|
|
584
|
+
128,
|
|
585
|
+
160,
|
|
586
|
+
192
|
|
587
|
+
];
|
|
588
|
+
/** Read a settings value through the host link. */
|
|
589
|
+
async function readSetting(link, key) {
|
|
590
|
+
const result = await link.call("settings.get", { key });
|
|
591
|
+
return result.ok ? result.value.value : void 0;
|
|
592
|
+
}
|
|
593
|
+
/** Write a settings value; `null` clears the row. */
|
|
594
|
+
async function writeSetting(link, key, value) {
|
|
595
|
+
await link.call("settings.set", {
|
|
596
|
+
key,
|
|
597
|
+
value
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
/** The appearance/display page. */
|
|
601
|
+
function AppearancePage() {
|
|
602
|
+
const { link } = useClient();
|
|
603
|
+
const skins = useSkins();
|
|
604
|
+
const activeId = useSkinId();
|
|
605
|
+
const [packages, setPackages] = useState([]);
|
|
606
|
+
const [windowPreset, setWindowPreset] = useState(void 0);
|
|
607
|
+
const [ballSize, setBallSize] = useState(128);
|
|
608
|
+
const [ballEnabled, setBallEnabled] = useState(true);
|
|
609
|
+
const [ballCollapse, setBallCollapse] = useState(true);
|
|
610
|
+
const [error, setError] = useState(void 0);
|
|
611
|
+
const [busy, setBusy] = useState(false);
|
|
612
|
+
useEffect(() => {
|
|
613
|
+
Promise.all([
|
|
614
|
+
readSetting(link, WINDOW_KEY),
|
|
615
|
+
readSetting(link, BALL_KEY),
|
|
616
|
+
link.call("plugins.list", {})
|
|
617
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
618
|
+
const windowProfile = windowRow;
|
|
619
|
+
if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
|
|
620
|
+
const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
621
|
+
setWindowPreset(preset?.label);
|
|
622
|
+
}
|
|
623
|
+
const ballProfile = ballRow;
|
|
624
|
+
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
|
|
625
|
+
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
|
|
626
|
+
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
|
|
627
|
+
if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
|
|
628
|
+
name: plugin.packageName,
|
|
629
|
+
title: plugin.title ?? plugin.packageName,
|
|
630
|
+
enabled: plugin.enabled
|
|
631
|
+
})));
|
|
632
|
+
}).catch((cause) => {
|
|
633
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
634
|
+
});
|
|
635
|
+
}, [link]);
|
|
636
|
+
const saveWindow = (width, height, label) => {
|
|
637
|
+
setWindowPreset(label);
|
|
638
|
+
writeSetting(link, WINDOW_KEY, {
|
|
639
|
+
width,
|
|
640
|
+
height,
|
|
641
|
+
minWidth: 960,
|
|
642
|
+
minHeight: 600
|
|
643
|
+
}).catch((cause) => {
|
|
644
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
const resetWindow = () => {
|
|
648
|
+
setWindowPreset(void 0);
|
|
649
|
+
writeSetting(link, WINDOW_KEY, null).catch((cause) => {
|
|
650
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
651
|
+
});
|
|
652
|
+
};
|
|
653
|
+
const saveBall = (patch) => {
|
|
654
|
+
const next = {
|
|
655
|
+
size: patch.size ?? ballSize,
|
|
656
|
+
enabled: patch.enabled ?? ballEnabled,
|
|
657
|
+
collapse: patch.collapse ?? ballCollapse
|
|
658
|
+
};
|
|
659
|
+
if (patch.size !== void 0) setBallSize(patch.size);
|
|
660
|
+
if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
|
|
661
|
+
if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
|
|
662
|
+
writeSetting(link, BALL_KEY, next).catch((cause) => {
|
|
663
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
664
|
+
});
|
|
665
|
+
};
|
|
666
|
+
const tabs = [...skins.list().map((row) => ({
|
|
667
|
+
id: row.id,
|
|
668
|
+
title: row.title
|
|
669
|
+
})), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
|
|
670
|
+
id: pkg.name,
|
|
671
|
+
title: pkg.title,
|
|
672
|
+
enable: pkg.name
|
|
673
|
+
}))];
|
|
674
|
+
const selectTheme = (tab) => {
|
|
675
|
+
if (busy) return;
|
|
676
|
+
if (tab.enable === void 0) {
|
|
677
|
+
writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
|
|
678
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
679
|
+
});
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
setBusy(true);
|
|
683
|
+
link.call("plugins.set-enabled", {
|
|
684
|
+
name: tab.enable,
|
|
685
|
+
enabled: true
|
|
686
|
+
}).then((result) => {
|
|
687
|
+
if (!result.ok) {
|
|
688
|
+
setError(rpcErrorText(result.error));
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
|
|
692
|
+
...pkg,
|
|
693
|
+
enabled: true
|
|
694
|
+
} : pkg));
|
|
695
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
696
|
+
}).catch((cause) => {
|
|
697
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
698
|
+
}).finally(() => {
|
|
699
|
+
setBusy(false);
|
|
700
|
+
});
|
|
701
|
+
};
|
|
702
|
+
return jsx(Page, {
|
|
703
|
+
title: "外观与显示",
|
|
704
|
+
description: "主题、主窗口尺寸和悬浮球外观。",
|
|
705
|
+
children: jsxs(Stack, {
|
|
706
|
+
gap: "lg",
|
|
707
|
+
children: [
|
|
708
|
+
error !== void 0 && jsx("div", {
|
|
709
|
+
role: "alert",
|
|
710
|
+
style: { color: "var(--snap-color-danger)" },
|
|
711
|
+
children: error
|
|
712
|
+
}),
|
|
713
|
+
jsx(Section, {
|
|
714
|
+
title: "主题",
|
|
715
|
+
children: jsx(Tabs, {
|
|
716
|
+
value: activeId,
|
|
717
|
+
onValueChange: (value) => {
|
|
718
|
+
const tab = tabs.find((item) => item.id === value);
|
|
719
|
+
if (tab !== void 0) selectTheme(tab);
|
|
720
|
+
},
|
|
721
|
+
children: jsx(TabsList, {
|
|
722
|
+
"aria-label": "主题",
|
|
723
|
+
children: tabs.map((tab) => jsx(TabsTrigger, {
|
|
724
|
+
value: tab.id,
|
|
725
|
+
disabled: busy,
|
|
726
|
+
children: tab.title
|
|
727
|
+
}, tab.id))
|
|
728
|
+
})
|
|
729
|
+
})
|
|
730
|
+
}),
|
|
731
|
+
jsx(Section, {
|
|
732
|
+
title: "主窗口",
|
|
733
|
+
children: jsxs(Stack, {
|
|
734
|
+
gap: "sm",
|
|
735
|
+
children: [jsxs(Row, {
|
|
736
|
+
gap: "sm",
|
|
737
|
+
wrap: true,
|
|
738
|
+
children: [WINDOW_PRESETS.map((preset) => jsx(Button, {
|
|
739
|
+
size: "sm",
|
|
740
|
+
intent: windowPreset === preset.label ? "primary" : "neutral",
|
|
741
|
+
emphasis: windowPreset === preset.label ? "solid" : "outline",
|
|
742
|
+
onClick: () => saveWindow(preset.width, preset.height, preset.label),
|
|
743
|
+
children: preset.label
|
|
744
|
+
}, preset.label)), jsx(Button, {
|
|
745
|
+
size: "sm",
|
|
746
|
+
emphasis: "ghost",
|
|
747
|
+
onClick: resetWindow,
|
|
748
|
+
children: "跟随布局"
|
|
749
|
+
})]
|
|
750
|
+
}), jsxs("span", {
|
|
751
|
+
style: {
|
|
752
|
+
color: "var(--snap-color-muted)",
|
|
753
|
+
fontSize: "var(--snap-text-sm)"
|
|
754
|
+
},
|
|
755
|
+
children: ["当前:", windowPreset ?? "跟随布局推荐 / 默认 1280 × 800"]
|
|
756
|
+
})]
|
|
757
|
+
})
|
|
758
|
+
}),
|
|
759
|
+
jsx(Section, {
|
|
760
|
+
title: "悬浮球",
|
|
761
|
+
description: "球面尺寸与停泊行为。",
|
|
762
|
+
children: jsxs(Stack, {
|
|
763
|
+
gap: "md",
|
|
764
|
+
children: [jsx(Row, {
|
|
765
|
+
gap: "sm",
|
|
766
|
+
wrap: true,
|
|
767
|
+
align: "center",
|
|
768
|
+
children: BALL_SIZES.map((size) => jsxs(Button, {
|
|
769
|
+
size: "sm",
|
|
770
|
+
intent: ballSize === size ? "primary" : "neutral",
|
|
771
|
+
emphasis: ballSize === size ? "solid" : "outline",
|
|
772
|
+
onClick: () => saveBall({ size }),
|
|
773
|
+
children: [size, "px"]
|
|
774
|
+
}, size))
|
|
775
|
+
}), jsxs(Row, {
|
|
776
|
+
gap: "lg",
|
|
777
|
+
wrap: true,
|
|
778
|
+
align: "center",
|
|
779
|
+
children: [jsx(Switch, {
|
|
780
|
+
label: "启用悬浮球",
|
|
781
|
+
checked: ballEnabled,
|
|
782
|
+
onCheckedChange: (enabled) => saveBall({ enabled })
|
|
783
|
+
}), jsx(Switch, {
|
|
784
|
+
label: "允许贴边收起",
|
|
785
|
+
checked: ballCollapse,
|
|
786
|
+
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
787
|
+
})]
|
|
788
|
+
})]
|
|
789
|
+
})
|
|
790
|
+
})
|
|
791
|
+
]
|
|
792
|
+
})
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region lib/types/settings-pages/plugin-feed.js
|
|
797
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
798
|
+
function PluginFeedDialog(props) {
|
|
799
|
+
const { open } = props;
|
|
800
|
+
const link = props.ctx.client.link;
|
|
801
|
+
const [urls, setUrls] = useState([]);
|
|
802
|
+
const [draft, setDraft] = useState("");
|
|
803
|
+
const [error, setError] = useState(void 0);
|
|
804
|
+
useEffect(() => {
|
|
805
|
+
if (!open) return;
|
|
806
|
+
link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
|
|
807
|
+
if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
|
|
808
|
+
}).catch(() => void 0);
|
|
809
|
+
}, [open, link]);
|
|
810
|
+
const save = () => {
|
|
811
|
+
for (const url of urls) try {
|
|
812
|
+
const parsed = new URL(url);
|
|
813
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
814
|
+
} catch {
|
|
815
|
+
setError("插件源地址需要以 http(s) 开头");
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
setError(void 0);
|
|
819
|
+
link.call("settings.set", {
|
|
820
|
+
key: PLUGINS_FEED_URLS_KEY,
|
|
821
|
+
value: urls
|
|
822
|
+
}).then((result) => {
|
|
823
|
+
if (!result.ok) {
|
|
824
|
+
setError(rpcErrorText(result.error));
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
props.onOpenChange(false);
|
|
828
|
+
}).catch((cause) => setError(String(cause)));
|
|
829
|
+
};
|
|
830
|
+
const append = () => {
|
|
831
|
+
const value = draft.trim();
|
|
832
|
+
if (value === "") return;
|
|
833
|
+
try {
|
|
834
|
+
const parsed = new URL(value);
|
|
835
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
836
|
+
} catch {
|
|
837
|
+
setError("请填写 http(s) 开头的插件源地址");
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
setError(void 0);
|
|
841
|
+
setDraft("");
|
|
842
|
+
setUrls((current) => current.includes(value) ? current : [...current, value]);
|
|
843
|
+
};
|
|
844
|
+
return jsx(Dialog, {
|
|
845
|
+
open,
|
|
846
|
+
onOpenChange: props.onOpenChange,
|
|
847
|
+
children: jsxs(DialogContent, {
|
|
848
|
+
presentation: "modal",
|
|
849
|
+
"aria-describedby": void 0,
|
|
850
|
+
children: [
|
|
851
|
+
jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
|
|
852
|
+
jsx(DialogBody, { children: jsxs(Stack, {
|
|
853
|
+
gap: "sm",
|
|
854
|
+
children: [
|
|
855
|
+
urls.length === 0 && jsx("div", {
|
|
856
|
+
style: {
|
|
857
|
+
fontSize: "var(--snap-text-xs)",
|
|
858
|
+
color: "var(--snap-color-muted)"
|
|
859
|
+
},
|
|
860
|
+
children: "尚未添加自定义源(当前使用出厂默认源)。"
|
|
861
|
+
}),
|
|
862
|
+
urls.map((url, index) => jsxs("div", {
|
|
863
|
+
style: {
|
|
864
|
+
display: "flex",
|
|
865
|
+
gap: "var(--snap-space-sm)",
|
|
866
|
+
alignItems: "center"
|
|
867
|
+
},
|
|
868
|
+
children: [jsx("span", {
|
|
869
|
+
style: {
|
|
870
|
+
flex: 1,
|
|
871
|
+
minWidth: 0,
|
|
872
|
+
overflow: "hidden",
|
|
873
|
+
textOverflow: "ellipsis",
|
|
874
|
+
whiteSpace: "nowrap",
|
|
875
|
+
fontSize: "var(--snap-text-xs)"
|
|
876
|
+
},
|
|
877
|
+
children: url
|
|
878
|
+
}), jsx(Button, {
|
|
879
|
+
intent: "neutral",
|
|
880
|
+
emphasis: "ghost",
|
|
881
|
+
size: "sm",
|
|
882
|
+
"aria-label": `移除 ${url}`,
|
|
883
|
+
onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
|
|
884
|
+
children: "✕"
|
|
885
|
+
})]
|
|
886
|
+
}, url)),
|
|
887
|
+
jsxs("div", {
|
|
888
|
+
style: {
|
|
889
|
+
display: "flex",
|
|
890
|
+
gap: "var(--snap-space-sm)",
|
|
891
|
+
width: "100%"
|
|
892
|
+
},
|
|
893
|
+
children: [jsx(Input, {
|
|
894
|
+
value: draft,
|
|
895
|
+
placeholder: "https://…",
|
|
896
|
+
style: {
|
|
897
|
+
flex: 1,
|
|
898
|
+
minWidth: 0
|
|
899
|
+
},
|
|
900
|
+
onChange: (event) => setDraft(event.target.value),
|
|
901
|
+
onKeyDown: (event) => {
|
|
902
|
+
if (event.key === "Enter") append();
|
|
903
|
+
}
|
|
904
|
+
}), jsx(Button, {
|
|
905
|
+
intent: "neutral",
|
|
906
|
+
emphasis: "outline",
|
|
907
|
+
onClick: append,
|
|
908
|
+
children: "添加源"
|
|
909
|
+
})]
|
|
910
|
+
}),
|
|
911
|
+
error !== void 0 && jsx("div", {
|
|
912
|
+
role: "alert",
|
|
913
|
+
style: {
|
|
914
|
+
color: "var(--snap-color-danger)",
|
|
915
|
+
fontSize: "var(--snap-text-sm)"
|
|
916
|
+
},
|
|
917
|
+
children: error
|
|
918
|
+
})
|
|
919
|
+
]
|
|
920
|
+
}) }),
|
|
921
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
922
|
+
intent: "neutral",
|
|
923
|
+
emphasis: "outline",
|
|
924
|
+
onClick: () => props.onOpenChange(false),
|
|
925
|
+
children: "取消"
|
|
926
|
+
}), jsx(Button, {
|
|
927
|
+
intent: "primary",
|
|
928
|
+
"data-plugins-feed-save": true,
|
|
929
|
+
onClick: save,
|
|
930
|
+
children: "保存"
|
|
931
|
+
})] })
|
|
932
|
+
]
|
|
933
|
+
})
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
//#endregion
|
|
937
|
+
//#region lib/types/settings-pages/plugins.js
|
|
938
|
+
/** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
|
|
939
|
+
* Electron or in tests. Inlined rather than imported from the app-internal
|
|
940
|
+
* kernel package: it never ships in the installer, and the packaged-app gate
|
|
941
|
+
* refuses any shipped `@snap-rail/ui` lib that requires it. */
|
|
942
|
+
function droppedZipPath(file) {
|
|
943
|
+
const zipPathOf = globalThis.snapRail?.zipPathOf;
|
|
944
|
+
if (typeof zipPathOf !== "function") return null;
|
|
945
|
+
return zipPathOf(file);
|
|
946
|
+
}
|
|
947
|
+
/** Human labels for the package kinds. */
|
|
948
|
+
const KIND_LABELS = {
|
|
949
|
+
skin: "界面风格",
|
|
950
|
+
driver: "通讯驱动",
|
|
951
|
+
suite: "业务套件",
|
|
952
|
+
plugin: "插件"
|
|
953
|
+
};
|
|
954
|
+
const PROFILE_LABELS = {
|
|
955
|
+
native: "皮肤原生",
|
|
956
|
+
integrated: "图表桥接",
|
|
957
|
+
custom: "自定义界面"
|
|
958
|
+
};
|
|
959
|
+
/** Search rows shown before the tail is folded into a counter. */
|
|
960
|
+
const SEARCH_ROW_CAP = 20;
|
|
961
|
+
/** The plus glyph for the page's install entry. */
|
|
962
|
+
function PlusIcon() {
|
|
963
|
+
return jsx("svg", {
|
|
964
|
+
viewBox: "0 0 24 24",
|
|
965
|
+
width: "18",
|
|
966
|
+
height: "18",
|
|
967
|
+
fill: "none",
|
|
968
|
+
stroke: "currentColor",
|
|
969
|
+
strokeWidth: "2.4",
|
|
970
|
+
strokeLinecap: "round",
|
|
971
|
+
"aria-hidden": "true",
|
|
972
|
+
children: jsx("path", { d: "M12 5v14M5 12h14" })
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
/** Collapse entry rows into package rows (one master switch per package). */
|
|
976
|
+
function packageRows(plugins) {
|
|
977
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
978
|
+
for (const plugin of plugins) {
|
|
979
|
+
if (plugin.source === "builtin") continue;
|
|
980
|
+
const existing = byPackage.get(plugin.packageName);
|
|
981
|
+
if (existing !== void 0) {
|
|
982
|
+
existing.enabled = existing.enabled || plugin.enabled;
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
byPackage.set(plugin.packageName, {
|
|
986
|
+
packageName: plugin.packageName,
|
|
987
|
+
title: plugin.title ?? plugin.packageName,
|
|
988
|
+
category: plugin.category ?? "其他",
|
|
989
|
+
kind: plugin.kind ?? "plugin",
|
|
990
|
+
...plugin.version !== void 0 ? { version: plugin.version } : {},
|
|
991
|
+
enabled: plugin.enabled,
|
|
992
|
+
source: plugin.source,
|
|
993
|
+
builtinDefault: plugin.source === "builtin-default",
|
|
994
|
+
clientOnly: plugin.clientOnly === true,
|
|
995
|
+
...plugin.uiProfile !== void 0 ? { uiProfile: plugin.uiProfile } : {}
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
999
|
+
}
|
|
1000
|
+
/** The preview's signature line (one row in the confirm card). */
|
|
1001
|
+
function signatureText(signature, viaUrl) {
|
|
1002
|
+
if (signature.state === "verified") return {
|
|
1003
|
+
text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
|
|
1004
|
+
warning: false
|
|
1005
|
+
};
|
|
1006
|
+
const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
|
|
1007
|
+
return {
|
|
1008
|
+
text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
|
|
1009
|
+
warning: true
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
/** Does the input name an http(s) address? */
|
|
1013
|
+
const isHttpUrl = (text) => /^https?:\/\//i.test(text);
|
|
1014
|
+
/** Does the input look like a filesystem path (drive letter, UNC, posix
|
|
1015
|
+
* root, or a .zip name with a separator in it)? */
|
|
1016
|
+
const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
|
|
1017
|
+
/** The plugin management page. */
|
|
1018
|
+
function PluginsPage({ ctx }) {
|
|
1019
|
+
const [rows, setRows] = useState([]);
|
|
1020
|
+
const [error, setError] = useState(void 0);
|
|
1021
|
+
const [busy, setBusy] = useState(void 0);
|
|
1022
|
+
const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
|
|
1023
|
+
const [restartNeeded, setRestartNeeded] = useState(false);
|
|
1024
|
+
const [installOpen, setInstallOpen] = useState(false);
|
|
1025
|
+
const [phase, setPhase] = useState({ kind: "idle" });
|
|
1026
|
+
const [message, setMessage] = useState(void 0);
|
|
1027
|
+
const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
|
|
1028
|
+
const [updatingName, setUpdatingName] = useState(void 0);
|
|
1029
|
+
const [keyChange, setKeyChange] = useState(void 0);
|
|
1030
|
+
const [query, setQuery] = useState("");
|
|
1031
|
+
const [searchResults, setSearchResults] = useState(void 0);
|
|
1032
|
+
const [searching, setSearching] = useState(false);
|
|
1033
|
+
const [dragging, setDragging] = useState(false);
|
|
1034
|
+
const link = ctx.client.link;
|
|
1035
|
+
const load = () => {
|
|
1036
|
+
setError(void 0);
|
|
1037
|
+
link.call("plugins.list", {}).then((result) => {
|
|
1038
|
+
if (!result.ok) {
|
|
1039
|
+
setError(rpcErrorText(result.error));
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
setRows(packageRows(result.value.plugins));
|
|
1043
|
+
}).catch((cause) => {
|
|
1044
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1045
|
+
});
|
|
1046
|
+
link.call("plugins.updates-check", {}).then((result) => {
|
|
1047
|
+
if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
|
|
1048
|
+
}).catch(() => void 0);
|
|
1049
|
+
};
|
|
1050
|
+
useEffect(() => {
|
|
1051
|
+
load();
|
|
1052
|
+
}, [link]);
|
|
1053
|
+
const openInstall = () => {
|
|
1054
|
+
setQuery("");
|
|
1055
|
+
setSearchResults(void 0);
|
|
1056
|
+
setMessage(void 0);
|
|
1057
|
+
setDragging(false);
|
|
1058
|
+
setInstallOpen(true);
|
|
1059
|
+
};
|
|
1060
|
+
const closeInstall = () => {
|
|
1061
|
+
setInstallOpen(false);
|
|
1062
|
+
setQuery("");
|
|
1063
|
+
setSearchResults(void 0);
|
|
1064
|
+
setMessage(void 0);
|
|
1065
|
+
setDragging(false);
|
|
1066
|
+
};
|
|
1067
|
+
const toggle = (row, enabled) => {
|
|
1068
|
+
setBusy(row.packageName);
|
|
1069
|
+
link.call("plugins.set-enabled", {
|
|
1070
|
+
name: row.packageName,
|
|
1071
|
+
enabled
|
|
1072
|
+
}).then((result) => {
|
|
1073
|
+
if (!result.ok) {
|
|
1074
|
+
setError(rpcErrorText(result.error));
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
setRows((current) => current.map((item) => item.packageName === row.packageName ? {
|
|
1078
|
+
...item,
|
|
1079
|
+
enabled
|
|
1080
|
+
} : item));
|
|
1081
|
+
setTouched((current) => new Set(current).add(row.packageName));
|
|
1082
|
+
}).catch((cause) => {
|
|
1083
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1084
|
+
}).finally(() => {
|
|
1085
|
+
setBusy(void 0);
|
|
1086
|
+
});
|
|
1087
|
+
};
|
|
1088
|
+
const uninstall = (row) => {
|
|
1089
|
+
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
|
|
1090
|
+
setBusy(row.packageName);
|
|
1091
|
+
link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
|
|
1092
|
+
if (!result.ok) {
|
|
1093
|
+
setError(rpcErrorText(result.error));
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
setTouched((current) => new Set(current).add(row.packageName));
|
|
1097
|
+
setRestartNeeded(true);
|
|
1098
|
+
load();
|
|
1099
|
+
}).catch((cause) => {
|
|
1100
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1101
|
+
}).finally(() => {
|
|
1102
|
+
setBusy(void 0);
|
|
1103
|
+
});
|
|
1104
|
+
};
|
|
1105
|
+
const inspectPath = (zipPath) => {
|
|
1106
|
+
setMessage(void 0);
|
|
1107
|
+
link.call("plugins.inspect", { zipPath }).then((result) => {
|
|
1108
|
+
if (!result.ok) {
|
|
1109
|
+
setPhase({
|
|
1110
|
+
kind: "error",
|
|
1111
|
+
message: `读取插件包失败:${rpcErrorText(result.error)}`
|
|
1112
|
+
});
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
setPhase({
|
|
1116
|
+
kind: "confirm",
|
|
1117
|
+
zipPath,
|
|
1118
|
+
archive: result.value.archive,
|
|
1119
|
+
viaUrl: false,
|
|
1120
|
+
risk: false
|
|
1121
|
+
});
|
|
1122
|
+
}).catch((cause) => setPhase({
|
|
1123
|
+
kind: "error",
|
|
1124
|
+
message: String(cause)
|
|
1125
|
+
}));
|
|
1126
|
+
};
|
|
1127
|
+
const inspectFromUrl = (url) => {
|
|
1128
|
+
setMessage(void 0);
|
|
1129
|
+
link.call("plugins.inspect-from-url", { url }).then((result) => {
|
|
1130
|
+
if (!result.ok) {
|
|
1131
|
+
setPhase({
|
|
1132
|
+
kind: "error",
|
|
1133
|
+
message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
|
|
1134
|
+
});
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
setPhase({
|
|
1138
|
+
kind: "confirm",
|
|
1139
|
+
zipPath: result.value.zipPath,
|
|
1140
|
+
archive: result.value.archive,
|
|
1141
|
+
viaUrl: true,
|
|
1142
|
+
risk: false
|
|
1143
|
+
});
|
|
1144
|
+
}).catch((cause) => setPhase({
|
|
1145
|
+
kind: "error",
|
|
1146
|
+
message: String(cause)
|
|
1147
|
+
}));
|
|
1148
|
+
};
|
|
1149
|
+
const runInstall = (zipPath, archive) => {
|
|
1150
|
+
setPhase({ kind: "installing" });
|
|
1151
|
+
(archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
|
|
1152
|
+
if (!result.ok) {
|
|
1153
|
+
setPhase({
|
|
1154
|
+
kind: "error",
|
|
1155
|
+
message: `安装失败:${rpcErrorText(result.error)}`
|
|
1156
|
+
});
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
setPhase({ kind: "idle" });
|
|
1160
|
+
closeInstall();
|
|
1161
|
+
setRestartNeeded(true);
|
|
1162
|
+
load();
|
|
1163
|
+
}).catch((cause) => setPhase({
|
|
1164
|
+
kind: "error",
|
|
1165
|
+
message: String(cause)
|
|
1166
|
+
}));
|
|
1167
|
+
};
|
|
1168
|
+
/** The update pill's click: a plain update installs directly; a key
|
|
1169
|
+
* change confirmation intercepts first. */
|
|
1170
|
+
const requestUpdate = (update) => {
|
|
1171
|
+
if (update.keyChanged === true) {
|
|
1172
|
+
setKeyChange(update);
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
updateNow(update.name);
|
|
1176
|
+
};
|
|
1177
|
+
/** The update itself: the feed's entry, no preview. */
|
|
1178
|
+
const updateNow = (name) => {
|
|
1179
|
+
setKeyChange(void 0);
|
|
1180
|
+
setUpdatingName(name);
|
|
1181
|
+
setMessage(void 0);
|
|
1182
|
+
link.call("plugins.remote-install", { name }).then((result) => {
|
|
1183
|
+
setUpdatingName(void 0);
|
|
1184
|
+
if (!result.ok) {
|
|
1185
|
+
setMessage({
|
|
1186
|
+
kind: "error",
|
|
1187
|
+
text: rpcErrorText(result.error)
|
|
1188
|
+
});
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
setRestartNeeded(true);
|
|
1192
|
+
load();
|
|
1193
|
+
}).catch(() => setUpdatingName(void 0));
|
|
1194
|
+
};
|
|
1195
|
+
/** The tri-form input: address/path → inspect, anything else → feed search. */
|
|
1196
|
+
const submitQuery = () => {
|
|
1197
|
+
const text = query.trim();
|
|
1198
|
+
if (text === "") return;
|
|
1199
|
+
setMessage(void 0);
|
|
1200
|
+
if (isHttpUrl(text)) {
|
|
1201
|
+
inspectFromUrl(text);
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
if (looksLikePath(text)) {
|
|
1205
|
+
inspectPath(text);
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
runSearch(text);
|
|
1209
|
+
};
|
|
1210
|
+
const runSearch = (text) => {
|
|
1211
|
+
setSearching(true);
|
|
1212
|
+
setSearchResults(void 0);
|
|
1213
|
+
link.call("plugins.remote-list", {}).then((result) => {
|
|
1214
|
+
setSearching(false);
|
|
1215
|
+
if (!result.ok) {
|
|
1216
|
+
setMessage({
|
|
1217
|
+
kind: "error",
|
|
1218
|
+
text: `搜索失败:${rpcErrorText(result.error)}`
|
|
1219
|
+
});
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
const needle = text.toLowerCase();
|
|
1223
|
+
setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
|
|
1224
|
+
}).catch((cause) => {
|
|
1225
|
+
setSearching(false);
|
|
1226
|
+
setMessage({
|
|
1227
|
+
kind: "error",
|
|
1228
|
+
text: String(cause)
|
|
1229
|
+
});
|
|
1230
|
+
});
|
|
1231
|
+
};
|
|
1232
|
+
/** A search-result entry that is not installed yet: preview first. The
|
|
1233
|
+
* entry's own coordinates decide where the zip comes from — a federation
|
|
1234
|
+
* row downloads from the author's release, a same-directory row from its
|
|
1235
|
+
* feed base. */
|
|
1236
|
+
const previewRemote = (item) => {
|
|
1237
|
+
if (item.url !== void 0) {
|
|
1238
|
+
inspectFromUrl(item.url);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
if (item.feedUrl === void 0 || item.file === void 0) return;
|
|
1242
|
+
const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
|
|
1243
|
+
inspectFromUrl(`${base}${item.file}`);
|
|
1244
|
+
};
|
|
1245
|
+
const onDrop = (event) => {
|
|
1246
|
+
event.preventDefault();
|
|
1247
|
+
setDragging(false);
|
|
1248
|
+
const file = event.dataTransfer.files[0];
|
|
1249
|
+
if (file === void 0) return;
|
|
1250
|
+
if (!file.name.toLowerCase().endsWith(".zip")) {
|
|
1251
|
+
setMessage({
|
|
1252
|
+
kind: "error",
|
|
1253
|
+
text: "只支持 .zip 插件包或组合包"
|
|
1254
|
+
});
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
const zipPath = droppedZipPath(file);
|
|
1258
|
+
if (zipPath === null) {
|
|
1259
|
+
setMessage({
|
|
1260
|
+
kind: "error",
|
|
1261
|
+
text: "当前环境不支持拖拽安装(缺少路径桥)"
|
|
1262
|
+
});
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
inspectPath(zipPath);
|
|
1266
|
+
};
|
|
1267
|
+
const restart = () => {
|
|
1268
|
+
link.call("window.relaunch", {});
|
|
1269
|
+
};
|
|
1270
|
+
const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
|
|
1271
|
+
const spans = /* @__PURE__ */ new Map();
|
|
1272
|
+
for (let index = 0; index < rows.length;) {
|
|
1273
|
+
const category = rows[index].category;
|
|
1274
|
+
let end = index + 1;
|
|
1275
|
+
while (end < rows.length && rows[end].category === category) end += 1;
|
|
1276
|
+
spans.set(index, end - index);
|
|
1277
|
+
index = end;
|
|
1278
|
+
}
|
|
1279
|
+
return jsxs(Page, {
|
|
1280
|
+
title: "插件管理",
|
|
1281
|
+
titleExtra: jsx(IconButton, {
|
|
1282
|
+
icon: jsx(PlusIcon, {}),
|
|
1283
|
+
label: "安装插件",
|
|
1284
|
+
onClick: openInstall
|
|
1285
|
+
}),
|
|
1286
|
+
actions: restartNeeded ? jsx(Button, {
|
|
1287
|
+
intent: "primary",
|
|
1288
|
+
onClick: restart,
|
|
1289
|
+
children: "重启生效"
|
|
1290
|
+
}) : void 0,
|
|
1291
|
+
children: [
|
|
1292
|
+
jsxs(Stack, {
|
|
1293
|
+
gap: "lg",
|
|
1294
|
+
children: [error !== void 0 && jsx("div", {
|
|
1295
|
+
role: "alert",
|
|
1296
|
+
style: { color: "var(--snap-color-danger)" },
|
|
1297
|
+
children: error
|
|
1298
|
+
}), rows.length === 0 ? jsx(EmptyState, {
|
|
1299
|
+
title: "还没有安装插件",
|
|
1300
|
+
action: jsx(Button, {
|
|
1301
|
+
intent: "primary",
|
|
1302
|
+
onClick: openInstall,
|
|
1303
|
+
children: "安装插件"
|
|
1304
|
+
})
|
|
1305
|
+
}) : jsxs(Table, {
|
|
1306
|
+
"data-plugins-table": true,
|
|
1307
|
+
children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
|
|
1308
|
+
jsx(TableHead, {
|
|
1309
|
+
style: { width: "6em" },
|
|
1310
|
+
children: "分类"
|
|
1311
|
+
}),
|
|
1312
|
+
jsx(TableHead, { children: "名称" }),
|
|
1313
|
+
jsx(TableHead, { children: "类型" }),
|
|
1314
|
+
jsx(TableHead, { children: "版本" }),
|
|
1315
|
+
jsx(TableHead, { children: "状态" }),
|
|
1316
|
+
jsx(TableHead, { children: "操作" })
|
|
1317
|
+
] }) }), jsx(TableBody, { children: rows.map((row, index) => {
|
|
1318
|
+
const update = updates.get(row.packageName);
|
|
1319
|
+
const span = spans.get(index);
|
|
1320
|
+
return jsxs(TableRow, { children: [
|
|
1321
|
+
span !== void 0 && jsx(TableCell, {
|
|
1322
|
+
rowSpan: span,
|
|
1323
|
+
style: {
|
|
1324
|
+
verticalAlign: "middle",
|
|
1325
|
+
color: "var(--snap-color-muted)",
|
|
1326
|
+
fontWeight: 600
|
|
1327
|
+
},
|
|
1328
|
+
children: row.category
|
|
1329
|
+
}),
|
|
1330
|
+
jsx(TableCell, { children: jsxs("div", {
|
|
1331
|
+
style: {
|
|
1332
|
+
display: "flex",
|
|
1333
|
+
flexDirection: "column"
|
|
1334
|
+
},
|
|
1335
|
+
children: [jsxs("span", {
|
|
1336
|
+
style: {
|
|
1337
|
+
display: "flex",
|
|
1338
|
+
alignItems: "center",
|
|
1339
|
+
gap: "var(--snap-space-sm)"
|
|
1340
|
+
},
|
|
1341
|
+
children: [row.title, row.builtinDefault && jsx(Badge, {
|
|
1342
|
+
intent: "neutral",
|
|
1343
|
+
children: "内置默认"
|
|
1344
|
+
})]
|
|
1345
|
+
}), jsx("span", {
|
|
1346
|
+
style: {
|
|
1347
|
+
color: "var(--snap-color-muted)",
|
|
1348
|
+
fontSize: "var(--snap-text-xs)"
|
|
1349
|
+
},
|
|
1350
|
+
children: row.packageName
|
|
1351
|
+
})]
|
|
1352
|
+
}) }),
|
|
1353
|
+
jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
|
|
1354
|
+
intent: "neutral",
|
|
1355
|
+
children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
|
|
1356
|
+
})] }),
|
|
1357
|
+
jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
|
|
1358
|
+
intent: "primary",
|
|
1359
|
+
emphasis: "ghost",
|
|
1360
|
+
size: "sm",
|
|
1361
|
+
title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
|
|
1362
|
+
disabled: updatingName === row.packageName,
|
|
1363
|
+
onClick: () => requestUpdate(update),
|
|
1364
|
+
children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
|
|
1365
|
+
}) : row.version ?? "—" }),
|
|
1366
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
|
|
1367
|
+
checked: true,
|
|
1368
|
+
disabled: true,
|
|
1369
|
+
"aria-label": `启用 ${row.title}`
|
|
1370
|
+
}) : jsxs("div", {
|
|
1371
|
+
style: {
|
|
1372
|
+
display: "flex",
|
|
1373
|
+
alignItems: "center",
|
|
1374
|
+
gap: "var(--snap-space-sm)"
|
|
1375
|
+
},
|
|
1376
|
+
children: [jsx(Switch, {
|
|
1377
|
+
checked: row.enabled,
|
|
1378
|
+
disabled: busy === row.packageName,
|
|
1379
|
+
onCheckedChange: (next) => toggle(row, next),
|
|
1380
|
+
"aria-label": `启用 ${row.title}`
|
|
1381
|
+
}), touched.has(row.packageName) && jsx(Badge, {
|
|
1382
|
+
intent: "warning",
|
|
1383
|
+
children: "待重启"
|
|
1384
|
+
})]
|
|
1385
|
+
}) }),
|
|
1386
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
|
|
1387
|
+
style: { color: "var(--snap-color-muted)" },
|
|
1388
|
+
children: "内置默认不可卸载"
|
|
1389
|
+
}) : jsx(Button, {
|
|
1390
|
+
intent: "danger",
|
|
1391
|
+
emphasis: "ghost",
|
|
1392
|
+
size: "sm",
|
|
1393
|
+
disabled: busy === row.packageName,
|
|
1394
|
+
onClick: () => uninstall(row),
|
|
1395
|
+
children: "卸载"
|
|
1396
|
+
}) })
|
|
1397
|
+
] }, row.packageName);
|
|
1398
|
+
}) })]
|
|
1399
|
+
})]
|
|
1400
|
+
}),
|
|
1401
|
+
jsx(Dialog, {
|
|
1402
|
+
open: installOpen,
|
|
1403
|
+
onOpenChange: (next) => {
|
|
1404
|
+
if (!next) closeInstall();
|
|
1405
|
+
},
|
|
1406
|
+
children: jsxs(DialogContent, {
|
|
1407
|
+
presentation: "modal",
|
|
1408
|
+
size: "lg",
|
|
1409
|
+
"data-plugins-dropzone": true,
|
|
1410
|
+
"aria-describedby": void 0,
|
|
1411
|
+
onDragOver: (event) => {
|
|
1412
|
+
event.preventDefault();
|
|
1413
|
+
setDragging(true);
|
|
1414
|
+
},
|
|
1415
|
+
onDragLeave: (event) => {
|
|
1416
|
+
if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
|
|
1417
|
+
},
|
|
1418
|
+
onDrop,
|
|
1419
|
+
children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
|
|
1420
|
+
gap: "sm",
|
|
1421
|
+
children: [
|
|
1422
|
+
jsx("div", {
|
|
1423
|
+
"data-plugins-drop-hint": true,
|
|
1424
|
+
style: {
|
|
1425
|
+
height: "calc(var(--snap-control-height-md) * 3)",
|
|
1426
|
+
display: "flex",
|
|
1427
|
+
alignItems: "center",
|
|
1428
|
+
justifyContent: "center",
|
|
1429
|
+
border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
|
|
1430
|
+
borderRadius: "var(--snap-radius-md)",
|
|
1431
|
+
background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
|
|
1432
|
+
color: "var(--snap-color-muted)",
|
|
1433
|
+
fontSize: "var(--snap-text-sm)"
|
|
1434
|
+
},
|
|
1435
|
+
children: dragging ? "释放以安装" : "拖入 .zip 安装"
|
|
1436
|
+
}),
|
|
1437
|
+
jsxs("div", {
|
|
1438
|
+
style: {
|
|
1439
|
+
display: "flex",
|
|
1440
|
+
gap: "var(--snap-space-sm)"
|
|
1441
|
+
},
|
|
1442
|
+
children: [jsx(Input, {
|
|
1443
|
+
value: query,
|
|
1444
|
+
placeholder: "本地路径 / https://… / 插件名",
|
|
1445
|
+
style: {
|
|
1446
|
+
flex: 1,
|
|
1447
|
+
minWidth: 0
|
|
1448
|
+
},
|
|
1449
|
+
onChange: (event) => setQuery(event.target.value),
|
|
1450
|
+
onKeyDown: (event) => {
|
|
1451
|
+
if (event.key === "Enter") submitQuery();
|
|
1452
|
+
}
|
|
1453
|
+
}), jsx(Button, {
|
|
1454
|
+
intent: "neutral",
|
|
1455
|
+
emphasis: "outline",
|
|
1456
|
+
disabled: searching,
|
|
1457
|
+
onClick: submitQuery,
|
|
1458
|
+
children: searching ? "搜索中…" : "搜索"
|
|
1459
|
+
})]
|
|
1460
|
+
}),
|
|
1461
|
+
message !== void 0 && jsx("div", {
|
|
1462
|
+
role: message.kind === "error" ? "alert" : "status",
|
|
1463
|
+
style: {
|
|
1464
|
+
fontSize: "var(--snap-text-xs)",
|
|
1465
|
+
color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
|
|
1466
|
+
},
|
|
1467
|
+
children: message.text
|
|
1468
|
+
}),
|
|
1469
|
+
visibleResults !== void 0 && jsxs(Stack, {
|
|
1470
|
+
gap: "sm",
|
|
1471
|
+
children: [
|
|
1472
|
+
jsxs("div", {
|
|
1473
|
+
style: {
|
|
1474
|
+
display: "flex",
|
|
1475
|
+
justifyContent: "space-between",
|
|
1476
|
+
alignItems: "center"
|
|
1477
|
+
},
|
|
1478
|
+
children: [jsxs("span", {
|
|
1479
|
+
style: {
|
|
1480
|
+
fontSize: "var(--snap-text-sm)",
|
|
1481
|
+
color: "var(--snap-color-muted)"
|
|
1482
|
+
},
|
|
1483
|
+
children: [
|
|
1484
|
+
"搜索“",
|
|
1485
|
+
query.trim(),
|
|
1486
|
+
"”(",
|
|
1487
|
+
searchResults?.length ?? 0,
|
|
1488
|
+
")"
|
|
1489
|
+
]
|
|
1490
|
+
}), jsx(Button, {
|
|
1491
|
+
intent: "neutral",
|
|
1492
|
+
emphasis: "ghost",
|
|
1493
|
+
size: "sm",
|
|
1494
|
+
onClick: () => setSearchResults(void 0),
|
|
1495
|
+
children: "✕"
|
|
1496
|
+
})]
|
|
1497
|
+
}),
|
|
1498
|
+
visibleResults.length === 0 && jsx("div", {
|
|
1499
|
+
style: {
|
|
1500
|
+
padding: "12px 0",
|
|
1501
|
+
textAlign: "center",
|
|
1502
|
+
color: "var(--snap-color-muted)",
|
|
1503
|
+
fontSize: "var(--snap-text-sm)"
|
|
1504
|
+
},
|
|
1505
|
+
children: "没有匹配的插件。"
|
|
1506
|
+
}),
|
|
1507
|
+
visibleResults.map((item) => {
|
|
1508
|
+
const installed = item.installed !== void 0;
|
|
1509
|
+
return jsxs("div", {
|
|
1510
|
+
style: {
|
|
1511
|
+
display: "flex",
|
|
1512
|
+
gap: "var(--snap-space-md)",
|
|
1513
|
+
alignItems: "center",
|
|
1514
|
+
justifyContent: "space-between",
|
|
1515
|
+
borderBottom: "1px solid var(--snap-color-border)",
|
|
1516
|
+
paddingBottom: "var(--snap-space-sm)"
|
|
1517
|
+
},
|
|
1518
|
+
children: [jsxs("div", {
|
|
1519
|
+
style: { minWidth: 0 },
|
|
1520
|
+
children: [jsxs("div", {
|
|
1521
|
+
style: {
|
|
1522
|
+
display: "flex",
|
|
1523
|
+
gap: "var(--snap-space-sm)",
|
|
1524
|
+
alignItems: "center"
|
|
1525
|
+
},
|
|
1526
|
+
children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
|
|
1527
|
+
intent: "neutral",
|
|
1528
|
+
children: item.source
|
|
1529
|
+
})]
|
|
1530
|
+
}), jsxs("div", {
|
|
1531
|
+
style: {
|
|
1532
|
+
fontSize: "var(--snap-text-xs)",
|
|
1533
|
+
color: "var(--snap-color-muted)"
|
|
1534
|
+
},
|
|
1535
|
+
children: [
|
|
1536
|
+
item.name,
|
|
1537
|
+
" · ",
|
|
1538
|
+
item.version
|
|
1539
|
+
]
|
|
1540
|
+
})]
|
|
1541
|
+
}), item.action === "install" ? jsx(Button, {
|
|
1542
|
+
intent: "primary",
|
|
1543
|
+
emphasis: "outline",
|
|
1544
|
+
size: "sm",
|
|
1545
|
+
onClick: () => previewRemote(item),
|
|
1546
|
+
children: "安装"
|
|
1547
|
+
}) : item.action === "update" && installed ? jsx(Button, {
|
|
1548
|
+
intent: "primary",
|
|
1549
|
+
emphasis: "ghost",
|
|
1550
|
+
size: "sm",
|
|
1551
|
+
title: `当前 ${item.installed?.version} → ${item.version}`,
|
|
1552
|
+
disabled: updatingName === item.name,
|
|
1553
|
+
onClick: () => requestUpdate({
|
|
1554
|
+
name: item.name,
|
|
1555
|
+
installedVersion: item.installed?.version ?? "",
|
|
1556
|
+
feedVersion: item.version
|
|
1557
|
+
}),
|
|
1558
|
+
children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
|
|
1559
|
+
}) : jsx("span", {
|
|
1560
|
+
style: {
|
|
1561
|
+
fontSize: "var(--snap-text-xs)",
|
|
1562
|
+
color: "var(--snap-color-muted)"
|
|
1563
|
+
},
|
|
1564
|
+
children: item.action === "current" ? "已是最新" : "本地更新"
|
|
1565
|
+
})]
|
|
1566
|
+
}, item.name);
|
|
1567
|
+
}),
|
|
1568
|
+
(searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
|
|
1569
|
+
style: {
|
|
1570
|
+
fontSize: "var(--snap-text-xs)",
|
|
1571
|
+
color: "var(--snap-color-muted)"
|
|
1572
|
+
},
|
|
1573
|
+
children: [
|
|
1574
|
+
"已显示前 ",
|
|
1575
|
+
SEARCH_ROW_CAP,
|
|
1576
|
+
" 条,共 ",
|
|
1577
|
+
searchResults?.length,
|
|
1578
|
+
" 条。"
|
|
1579
|
+
]
|
|
1580
|
+
})
|
|
1581
|
+
]
|
|
1582
|
+
})
|
|
1583
|
+
]
|
|
1584
|
+
}) })]
|
|
1585
|
+
})
|
|
1586
|
+
}),
|
|
1587
|
+
jsx(Dialog, {
|
|
1588
|
+
open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
|
|
1589
|
+
onOpenChange: (next) => {
|
|
1590
|
+
if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
|
|
1591
|
+
},
|
|
1592
|
+
children: jsxs(DialogContent, {
|
|
1593
|
+
presentation: "modal",
|
|
1594
|
+
"aria-describedby": void 0,
|
|
1595
|
+
children: [
|
|
1596
|
+
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}` })] }),
|
|
1597
|
+
jsxs(DialogBody, { children: [
|
|
1598
|
+
phase.kind === "error" && jsx("div", {
|
|
1599
|
+
style: {
|
|
1600
|
+
color: "var(--snap-color-danger)",
|
|
1601
|
+
whiteSpace: "pre-wrap",
|
|
1602
|
+
fontSize: "var(--snap-text-sm)"
|
|
1603
|
+
},
|
|
1604
|
+
children: phase.message
|
|
1605
|
+
}),
|
|
1606
|
+
phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
|
|
1607
|
+
gap: "sm",
|
|
1608
|
+
children: [
|
|
1609
|
+
phase.archive.combo.description !== void 0 && jsx("div", {
|
|
1610
|
+
style: {
|
|
1611
|
+
color: "var(--snap-color-muted)",
|
|
1612
|
+
fontSize: "var(--snap-text-sm)"
|
|
1613
|
+
},
|
|
1614
|
+
children: phase.archive.combo.description
|
|
1615
|
+
}),
|
|
1616
|
+
jsxs("div", {
|
|
1617
|
+
style: {
|
|
1618
|
+
display: "grid",
|
|
1619
|
+
gap: "var(--snap-space-xs)",
|
|
1620
|
+
fontSize: "var(--snap-text-sm)"
|
|
1621
|
+
},
|
|
1622
|
+
children: [jsxs("div", { children: [
|
|
1623
|
+
"插件(",
|
|
1624
|
+
phase.archive.combo.plugins.length,
|
|
1625
|
+
")"
|
|
1626
|
+
] }), phase.archive.combo.plugins.map((plugin) => {
|
|
1627
|
+
const line = signatureText(plugin.signature, phase.viaUrl);
|
|
1628
|
+
const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
|
|
1629
|
+
return jsxs("div", {
|
|
1630
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
1631
|
+
children: [
|
|
1632
|
+
plugin.title ?? plugin.name,
|
|
1633
|
+
" ",
|
|
1634
|
+
plugin.version,
|
|
1635
|
+
" · ",
|
|
1636
|
+
action,
|
|
1637
|
+
line.warning ? " · ⚠ 未验证" : ""
|
|
1638
|
+
]
|
|
1639
|
+
}, plugin.name);
|
|
1640
|
+
})]
|
|
1641
|
+
}),
|
|
1642
|
+
phase.archive.combo.missing.length > 0 && jsxs("div", {
|
|
1643
|
+
style: {
|
|
1644
|
+
color: "var(--snap-color-danger)",
|
|
1645
|
+
fontSize: "var(--snap-text-sm)"
|
|
1646
|
+
},
|
|
1647
|
+
children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
|
|
1648
|
+
})
|
|
1649
|
+
]
|
|
1650
|
+
}),
|
|
1651
|
+
phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
|
|
1652
|
+
gap: "sm",
|
|
1653
|
+
children: [
|
|
1654
|
+
phase.risk ? jsx("div", {
|
|
1655
|
+
"data-plugins-risk": true,
|
|
1656
|
+
style: {
|
|
1657
|
+
color: "var(--snap-color-warning)",
|
|
1658
|
+
fontWeight: 600
|
|
1659
|
+
},
|
|
1660
|
+
children: "⚠ 此插件未经发布者验证"
|
|
1661
|
+
}) : void 0,
|
|
1662
|
+
!phase.risk && jsxs(Stack, {
|
|
1663
|
+
gap: "sm",
|
|
1664
|
+
children: [
|
|
1665
|
+
phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
|
|
1666
|
+
jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
|
|
1667
|
+
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] })
|
|
1668
|
+
]
|
|
1669
|
+
}),
|
|
1670
|
+
(() => {
|
|
1671
|
+
const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
|
|
1672
|
+
return jsxs("div", {
|
|
1673
|
+
"data-plugins-signature": phase.archive.plugin.signature.state,
|
|
1674
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
1675
|
+
children: ["签名:", line.text]
|
|
1676
|
+
});
|
|
1677
|
+
})(),
|
|
1678
|
+
!phase.risk && jsxs(Stack, {
|
|
1679
|
+
gap: "sm",
|
|
1680
|
+
children: [
|
|
1681
|
+
jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
|
|
1682
|
+
phase.archive.plugin.missing.length > 0 && jsxs("div", {
|
|
1683
|
+
style: {
|
|
1684
|
+
color: "var(--snap-color-danger)",
|
|
1685
|
+
fontSize: "var(--snap-text-sm)"
|
|
1686
|
+
},
|
|
1687
|
+
children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
|
|
1688
|
+
}),
|
|
1689
|
+
phase.archive.plugin.action === "blocked" && jsxs("div", {
|
|
1690
|
+
style: {
|
|
1691
|
+
color: "var(--snap-color-danger)",
|
|
1692
|
+
fontSize: "var(--snap-text-sm)"
|
|
1693
|
+
},
|
|
1694
|
+
children: [
|
|
1695
|
+
"已安装 v",
|
|
1696
|
+
phase.archive.plugin.installed?.version,
|
|
1697
|
+
",安装包 v",
|
|
1698
|
+
phase.archive.plugin.version,
|
|
1699
|
+
" 不高于已装版本,无法覆盖。"
|
|
1700
|
+
]
|
|
1701
|
+
})
|
|
1702
|
+
]
|
|
1703
|
+
}),
|
|
1704
|
+
phase.risk && jsx("div", {
|
|
1705
|
+
style: {
|
|
1706
|
+
color: "var(--snap-color-muted)",
|
|
1707
|
+
fontSize: "var(--snap-text-sm)"
|
|
1708
|
+
},
|
|
1709
|
+
children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
|
|
1710
|
+
})
|
|
1711
|
+
]
|
|
1712
|
+
})
|
|
1713
|
+
] }),
|
|
1714
|
+
jsxs(DialogFooter, { children: [
|
|
1715
|
+
phase.kind === "error" && jsx(Button, {
|
|
1716
|
+
intent: "neutral",
|
|
1717
|
+
emphasis: "outline",
|
|
1718
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
1719
|
+
children: "返回"
|
|
1720
|
+
}),
|
|
1721
|
+
phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
|
|
1722
|
+
intent: "neutral",
|
|
1723
|
+
emphasis: "outline",
|
|
1724
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
1725
|
+
children: "取消"
|
|
1726
|
+
}), phase.risk ? jsx(Button, {
|
|
1727
|
+
intent: "primary",
|
|
1728
|
+
"data-plugins-risk-confirm": true,
|
|
1729
|
+
onClick: () => runInstall(phase.zipPath, phase.archive),
|
|
1730
|
+
children: "我知晓风险,仍要安装"
|
|
1731
|
+
}) : jsx(Button, {
|
|
1732
|
+
intent: "primary",
|
|
1733
|
+
"data-plugins-install-confirm": true,
|
|
1734
|
+
disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
|
|
1735
|
+
onClick: () => {
|
|
1736
|
+
if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
|
|
1737
|
+
setPhase({
|
|
1738
|
+
...phase,
|
|
1739
|
+
risk: true
|
|
1740
|
+
});
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
runInstall(phase.zipPath, phase.archive);
|
|
1744
|
+
},
|
|
1745
|
+
children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
|
|
1746
|
+
})] }),
|
|
1747
|
+
phase.kind === "installing" && jsx("span", {
|
|
1748
|
+
style: { color: "var(--snap-color-muted)" },
|
|
1749
|
+
children: "正在安装…"
|
|
1750
|
+
})
|
|
1751
|
+
] })
|
|
1752
|
+
]
|
|
1753
|
+
})
|
|
1754
|
+
}),
|
|
1755
|
+
jsx(Dialog, {
|
|
1756
|
+
open: keyChange !== void 0,
|
|
1757
|
+
onOpenChange: (next) => {
|
|
1758
|
+
if (!next) setKeyChange(void 0);
|
|
1759
|
+
},
|
|
1760
|
+
children: jsxs(DialogContent, {
|
|
1761
|
+
presentation: "modal",
|
|
1762
|
+
children: [
|
|
1763
|
+
jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
|
|
1764
|
+
jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
|
|
1765
|
+
style: { fontSize: "var(--snap-text-sm)" },
|
|
1766
|
+
children: [
|
|
1767
|
+
"已安装 v",
|
|
1768
|
+
keyChange.installedVersion,
|
|
1769
|
+
" → 源上 v",
|
|
1770
|
+
keyChange.feedVersion,
|
|
1771
|
+
"。"
|
|
1772
|
+
]
|
|
1773
|
+
}) }),
|
|
1774
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
1775
|
+
intent: "neutral",
|
|
1776
|
+
emphasis: "outline",
|
|
1777
|
+
onClick: () => setKeyChange(void 0),
|
|
1778
|
+
children: "取消"
|
|
1779
|
+
}), jsx(Button, {
|
|
1780
|
+
intent: "primary",
|
|
1781
|
+
"data-plugins-keychange-confirm": true,
|
|
1782
|
+
onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
|
|
1783
|
+
children: "仍要更新"
|
|
1784
|
+
})] })
|
|
1785
|
+
]
|
|
1786
|
+
})
|
|
1787
|
+
})
|
|
1788
|
+
]
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
//#endregion
|
|
1792
|
+
//#region lib/types/settings.js
|
|
1793
|
+
/** Sort pages by order, then registration time. */
|
|
1794
|
+
function orderedPages(pages) {
|
|
1795
|
+
return [...pages].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
|
|
1796
|
+
}
|
|
1797
|
+
/** A page-level boundary: one broken settings page must not take down the shell. */
|
|
1798
|
+
var SettingsPageBoundary = class extends Component {
|
|
1799
|
+
state = { failed: false };
|
|
1800
|
+
static getDerivedStateFromError() {
|
|
1801
|
+
return { failed: true };
|
|
1802
|
+
}
|
|
1803
|
+
componentDidCatch(error) {
|
|
1804
|
+
console.error(`[snap-rail ui] settings page ${this.props.page} failed`, error);
|
|
1805
|
+
}
|
|
1806
|
+
render() {
|
|
1807
|
+
return this.state.failed ? jsx(EmptyState, {
|
|
1808
|
+
title: "设置页加载失败",
|
|
1809
|
+
description: "该页面抛出了异常,其他设置页仍可使用。"
|
|
1810
|
+
}) : this.props.children;
|
|
1811
|
+
}
|
|
1812
|
+
};
|
|
1813
|
+
/** The gear glyph used by the default trigger. */
|
|
1814
|
+
function GearIcon() {
|
|
1815
|
+
return jsxs("svg", {
|
|
1816
|
+
viewBox: "0 0 24 24",
|
|
1817
|
+
width: "18",
|
|
1818
|
+
height: "18",
|
|
1819
|
+
fill: "none",
|
|
1820
|
+
stroke: "currentColor",
|
|
1821
|
+
strokeWidth: "1.8",
|
|
1822
|
+
"aria-hidden": "true",
|
|
1823
|
+
children: [jsx("circle", {
|
|
1824
|
+
cx: "12",
|
|
1825
|
+
cy: "12",
|
|
1826
|
+
r: "3"
|
|
1827
|
+
}), 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" })]
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
/** The close glyph used by the surface's dismiss control. */
|
|
1831
|
+
function CloseIcon() {
|
|
1832
|
+
return jsx("svg", {
|
|
1833
|
+
viewBox: "0 0 24 24",
|
|
1834
|
+
width: "18",
|
|
1835
|
+
height: "18",
|
|
1836
|
+
fill: "none",
|
|
1837
|
+
stroke: "currentColor",
|
|
1838
|
+
strokeWidth: "1.8",
|
|
1839
|
+
"aria-hidden": "true",
|
|
1840
|
+
children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
/** The default settings trigger; the layout decides placement/presentation. */
|
|
1844
|
+
function SettingsEntry(props) {
|
|
1845
|
+
if (props.presentation === "label") return jsx(Button, {
|
|
1846
|
+
intent: "neutral",
|
|
1847
|
+
emphasis: "ghost",
|
|
1848
|
+
icon: jsx(GearIcon, {}),
|
|
1849
|
+
onClick: props.open,
|
|
1850
|
+
children: "设置"
|
|
1851
|
+
});
|
|
1852
|
+
return jsx(IconButton, {
|
|
1853
|
+
icon: jsx(GearIcon, {}),
|
|
1854
|
+
label: "设置",
|
|
1855
|
+
active: props.isOpen,
|
|
1856
|
+
onClick: props.open
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
/** The default settings surface. */
|
|
1860
|
+
function SettingsSurface(props) {
|
|
1861
|
+
const { service, ctx } = props;
|
|
1862
|
+
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
1863
|
+
const open = service.isOpen();
|
|
1864
|
+
const pages = service.listPages();
|
|
1865
|
+
const activeId = service.activePage();
|
|
1866
|
+
const active = pages.find((page) => page.id === activeId);
|
|
1867
|
+
const [feedOpen, setFeedOpen] = useState(false);
|
|
1868
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1869
|
+
for (const page of pages) {
|
|
1870
|
+
const group = page.group ?? "其他";
|
|
1871
|
+
const bucket = groups.get(group);
|
|
1872
|
+
if (bucket === void 0) groups.set(group, [page]);
|
|
1873
|
+
else bucket.push(page);
|
|
1874
|
+
}
|
|
1875
|
+
return jsxs(Fragment, { children: [jsx(Dialog, {
|
|
1876
|
+
open,
|
|
1877
|
+
onOpenChange: (next) => {
|
|
1878
|
+
if (!next) service.close();
|
|
1879
|
+
},
|
|
1880
|
+
children: jsx(DialogContent, {
|
|
1881
|
+
presentation: "fullscreen",
|
|
1882
|
+
showClose: false,
|
|
1883
|
+
children: jsxs("div", {
|
|
1884
|
+
...part("settings", "root"),
|
|
1885
|
+
className: "snap-settings",
|
|
1886
|
+
children: [jsxs("header", {
|
|
1887
|
+
...part("settings", "header"),
|
|
1888
|
+
className: "snap-settings-header",
|
|
1889
|
+
children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
|
|
1890
|
+
style: {
|
|
1891
|
+
display: "flex",
|
|
1892
|
+
alignItems: "center",
|
|
1893
|
+
gap: 4
|
|
1894
|
+
},
|
|
1895
|
+
children: [jsx(IconButton, {
|
|
1896
|
+
icon: jsx(GearIcon, {}),
|
|
1897
|
+
label: "配置插件源",
|
|
1898
|
+
onClick: () => setFeedOpen(true)
|
|
1899
|
+
}), jsx(IconButton, {
|
|
1900
|
+
icon: jsx(CloseIcon, {}),
|
|
1901
|
+
label: "关闭",
|
|
1902
|
+
onClick: () => service.close()
|
|
1903
|
+
})]
|
|
1904
|
+
})]
|
|
1905
|
+
}), jsxs("div", {
|
|
1906
|
+
...part("settings", "body"),
|
|
1907
|
+
className: "snap-settings-body",
|
|
1908
|
+
children: [jsx("nav", {
|
|
1909
|
+
...part("settings", "nav"),
|
|
1910
|
+
className: "snap-settings-nav",
|
|
1911
|
+
"aria-label": "设置页",
|
|
1912
|
+
children: [...groups.entries()].map(([group, entries]) => jsxs("div", {
|
|
1913
|
+
...part("settings", "group"),
|
|
1914
|
+
className: "snap-settings-group",
|
|
1915
|
+
children: [jsx("div", {
|
|
1916
|
+
...part("settings", "group-title"),
|
|
1917
|
+
className: "snap-settings-group-title",
|
|
1918
|
+
children: group
|
|
1919
|
+
}), entries.map((page) => jsxs("button", {
|
|
1920
|
+
type: "button",
|
|
1921
|
+
...part("settings", "nav-item"),
|
|
1922
|
+
className: cn("snap-settings-nav-item", page.id === activeId && "is-active"),
|
|
1923
|
+
"data-active": page.id === activeId || void 0,
|
|
1924
|
+
"aria-current": page.id === activeId ? "page" : void 0,
|
|
1925
|
+
onClick: () => service.open(page.id),
|
|
1926
|
+
children: [page.icon !== void 0 && jsx("span", {
|
|
1927
|
+
...part("settings", "nav-icon"),
|
|
1928
|
+
children: page.icon
|
|
1929
|
+
}), jsx("span", { children: page.title })]
|
|
1930
|
+
}, page.id))]
|
|
1931
|
+
}, group))
|
|
1932
|
+
}), jsx("main", {
|
|
1933
|
+
...part("settings", "content"),
|
|
1934
|
+
className: "snap-settings-content",
|
|
1935
|
+
"data-active-page": activeId,
|
|
1936
|
+
children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
|
|
1937
|
+
page: active.id,
|
|
1938
|
+
children: active.render()
|
|
1939
|
+
})
|
|
1940
|
+
})]
|
|
1941
|
+
})]
|
|
1942
|
+
})
|
|
1943
|
+
})
|
|
1944
|
+
}), jsx(PluginFeedDialog, {
|
|
1945
|
+
ctx,
|
|
1946
|
+
open: feedOpen,
|
|
1947
|
+
onOpenChange: setFeedOpen
|
|
1948
|
+
})] });
|
|
1949
|
+
}
|
|
1950
|
+
/** Mount the settings registry and its default slot contributions. */
|
|
1951
|
+
const settingsPlugin = {
|
|
1952
|
+
name: "snap-rail settings",
|
|
1953
|
+
inject: ["ui"],
|
|
1954
|
+
apply(ctx) {
|
|
1955
|
+
const pages = /* @__PURE__ */ new Map();
|
|
1956
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1957
|
+
let open = false;
|
|
1958
|
+
let requestedId;
|
|
1959
|
+
let revision = 0;
|
|
1960
|
+
let seq = 0;
|
|
1961
|
+
const notify = (kind) => {
|
|
1962
|
+
revision += 1;
|
|
1963
|
+
for (const listener of listeners) listener();
|
|
1964
|
+
ctx.emit(kind === "pages" ? "settings/pages-changed" : "settings/open-changed");
|
|
1965
|
+
};
|
|
1966
|
+
const firstId = () => orderedPages(pages.values())[0]?.id;
|
|
1967
|
+
const activeId = () => {
|
|
1968
|
+
if (!open) return void 0;
|
|
1969
|
+
if (requestedId !== void 0 && pages.has(requestedId)) return requestedId;
|
|
1970
|
+
return firstId();
|
|
1971
|
+
};
|
|
1972
|
+
const service = {
|
|
1973
|
+
registerPage(caller, page) {
|
|
1974
|
+
pages.set(page.id, {
|
|
1975
|
+
page,
|
|
1976
|
+
seq: seq++
|
|
1977
|
+
});
|
|
1978
|
+
notify("pages");
|
|
1979
|
+
const remove = () => {
|
|
1980
|
+
if (pages.delete(page.id)) notify("pages");
|
|
1981
|
+
};
|
|
1982
|
+
caller.effect(() => remove);
|
|
1983
|
+
return remove;
|
|
1984
|
+
},
|
|
1985
|
+
listPages: () => orderedPages(pages.values()),
|
|
1986
|
+
open(pageId) {
|
|
1987
|
+
if (pageId !== void 0) requestedId = pageId;
|
|
1988
|
+
if (open && pageId === void 0) return;
|
|
1989
|
+
open = true;
|
|
1990
|
+
notify("open");
|
|
1991
|
+
},
|
|
1992
|
+
close() {
|
|
1993
|
+
if (!open) return;
|
|
1994
|
+
open = false;
|
|
1995
|
+
notify("open");
|
|
1996
|
+
},
|
|
1997
|
+
toggle() {
|
|
1998
|
+
if (open) service.close();
|
|
1999
|
+
else service.open();
|
|
2000
|
+
},
|
|
2001
|
+
isOpen: () => open,
|
|
2002
|
+
activePage: activeId,
|
|
2003
|
+
subscribe(listener) {
|
|
2004
|
+
listeners.add(listener);
|
|
2005
|
+
return () => {
|
|
2006
|
+
listeners.delete(listener);
|
|
2007
|
+
};
|
|
2008
|
+
},
|
|
2009
|
+
version: () => revision
|
|
2010
|
+
};
|
|
2011
|
+
ctx.provide("settings", service);
|
|
2012
|
+
ctx.settings.registerPage(ctx, {
|
|
2013
|
+
id: "plugins",
|
|
2014
|
+
title: "插件管理",
|
|
2015
|
+
group: "系统",
|
|
2016
|
+
order: 0,
|
|
2017
|
+
keywords: [
|
|
2018
|
+
"安装",
|
|
2019
|
+
"启用",
|
|
2020
|
+
"卸载",
|
|
2021
|
+
"驱动",
|
|
2022
|
+
"皮肤"
|
|
2023
|
+
],
|
|
2024
|
+
render: () => jsx(PluginsPage, { ctx })
|
|
2025
|
+
});
|
|
2026
|
+
ctx.settings.registerPage(ctx, {
|
|
2027
|
+
id: "appearance",
|
|
2028
|
+
title: "外观与显示",
|
|
2029
|
+
group: "系统",
|
|
2030
|
+
order: 1,
|
|
2031
|
+
keywords: [
|
|
2032
|
+
"主题",
|
|
2033
|
+
"皮肤",
|
|
2034
|
+
"窗口",
|
|
2035
|
+
"悬浮球",
|
|
2036
|
+
"尺寸"
|
|
2037
|
+
],
|
|
2038
|
+
render: () => jsx(AppearancePage, {})
|
|
2039
|
+
});
|
|
2040
|
+
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsEntry, {
|
|
2041
|
+
id: "settings.default-entry",
|
|
2042
|
+
order: 0,
|
|
2043
|
+
render: (context) => jsx(SettingsEntry, {
|
|
2044
|
+
presentation: context.presentation,
|
|
2045
|
+
open: context.open,
|
|
2046
|
+
isOpen: context.isOpen
|
|
2047
|
+
})
|
|
2048
|
+
});
|
|
2049
|
+
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
|
|
2050
|
+
id: "settings.default-surface",
|
|
2051
|
+
order: 0,
|
|
2052
|
+
render: () => jsx(SettingsSurface, {
|
|
2053
|
+
service,
|
|
2054
|
+
ctx
|
|
2055
|
+
})
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
};
|
|
2059
|
+
/** The settings page info the slot context exposes. */
|
|
2060
|
+
function settingsPageInfo(page) {
|
|
2061
|
+
return {
|
|
2062
|
+
id: page.id,
|
|
2063
|
+
title: page.title,
|
|
2064
|
+
...page.group !== void 0 ? { group: page.group } : {},
|
|
2065
|
+
order: page.order
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
//#endregion
|
|
2069
|
+
export { SettingsEntry, SettingsSurface, settingsPlugin as default, settingsPageInfo };
|