@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/runtime.js
ADDED
|
@@ -0,0 +1,3003 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { attachBallDrag as attachBallDrag$1 } from "@snap-rail/client-kernel";
|
|
3
|
+
import { rpcErrorText, subscribeFrame } from "@snap-rail/connection";
|
|
4
|
+
import { settingsChangedSchema } from "@snap-rail/station-rpc/contract";
|
|
5
|
+
import { Context } from "@snap-rail/cordis";
|
|
6
|
+
import { TimerService } from "@snap-rail/cordis-plugin-timer";
|
|
7
|
+
import { shellContract } from "@snap-rail/shell/contract";
|
|
8
|
+
import { Component, createContext, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
9
|
+
import { createRoot } from "react-dom/client";
|
|
10
|
+
import { Slot as Slot$1 } from "@radix-ui/react-slot";
|
|
11
|
+
import "@radix-ui/react-checkbox";
|
|
12
|
+
import "@radix-ui/react-label";
|
|
13
|
+
import "@radix-ui/react-radio-group";
|
|
14
|
+
import "@radix-ui/react-select";
|
|
15
|
+
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
|
16
|
+
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
17
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
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$1 : "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
|
+
/** The operator-window shell frame. */
|
|
351
|
+
function AppShell({ header, sidebar, footer, className, style, children }) {
|
|
352
|
+
return jsxs("div", {
|
|
353
|
+
...part("app-shell", "root"),
|
|
354
|
+
className: cn("snap-app-shell", className),
|
|
355
|
+
style: {
|
|
356
|
+
display: "flex",
|
|
357
|
+
flexDirection: "column",
|
|
358
|
+
height: "100%",
|
|
359
|
+
minHeight: 0,
|
|
360
|
+
...style
|
|
361
|
+
},
|
|
362
|
+
children: [
|
|
363
|
+
header !== void 0 && jsx("div", {
|
|
364
|
+
...part("app-shell", "header"),
|
|
365
|
+
style: { flexShrink: 0 },
|
|
366
|
+
children: header
|
|
367
|
+
}),
|
|
368
|
+
jsxs("div", {
|
|
369
|
+
style: {
|
|
370
|
+
display: "flex",
|
|
371
|
+
flex: 1,
|
|
372
|
+
minHeight: 0
|
|
373
|
+
},
|
|
374
|
+
children: [sidebar !== void 0 && jsx("div", {
|
|
375
|
+
...part("app-shell", "sidebar"),
|
|
376
|
+
style: {
|
|
377
|
+
flexShrink: 0,
|
|
378
|
+
minHeight: 0
|
|
379
|
+
},
|
|
380
|
+
children: sidebar
|
|
381
|
+
}), jsx("div", {
|
|
382
|
+
...part("app-shell", "main"),
|
|
383
|
+
style: {
|
|
384
|
+
flex: 1,
|
|
385
|
+
minWidth: 0,
|
|
386
|
+
minHeight: 0,
|
|
387
|
+
overflow: "auto"
|
|
388
|
+
},
|
|
389
|
+
children
|
|
390
|
+
})]
|
|
391
|
+
}),
|
|
392
|
+
footer !== void 0 && jsx("div", {
|
|
393
|
+
...part("app-shell", "footer"),
|
|
394
|
+
style: { flexShrink: 0 },
|
|
395
|
+
children: footer
|
|
396
|
+
})
|
|
397
|
+
]
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/** A page body with its own header/actions anatomy. */
|
|
401
|
+
function Page({ header, actions, title, titleExtra, description, className, style, children }) {
|
|
402
|
+
return jsxs("div", {
|
|
403
|
+
...part("page", "root"),
|
|
404
|
+
className: cn("snap-page", className),
|
|
405
|
+
style: {
|
|
406
|
+
display: "flex",
|
|
407
|
+
flexDirection: "column",
|
|
408
|
+
minHeight: 0,
|
|
409
|
+
...style
|
|
410
|
+
},
|
|
411
|
+
children: [(header !== void 0 || title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("div", {
|
|
412
|
+
...part("page", "header"),
|
|
413
|
+
style: {
|
|
414
|
+
display: "flex",
|
|
415
|
+
flexDirection: "column",
|
|
416
|
+
gap: space("sm"),
|
|
417
|
+
flexShrink: 0
|
|
418
|
+
},
|
|
419
|
+
children: [
|
|
420
|
+
jsxs("div", {
|
|
421
|
+
style: {
|
|
422
|
+
display: "flex",
|
|
423
|
+
alignItems: "flex-start",
|
|
424
|
+
justifyContent: "space-between",
|
|
425
|
+
gap: space("md")
|
|
426
|
+
},
|
|
427
|
+
children: [jsxs("div", {
|
|
428
|
+
style: {
|
|
429
|
+
display: "flex",
|
|
430
|
+
alignItems: "center",
|
|
431
|
+
gap: space("sm")
|
|
432
|
+
},
|
|
433
|
+
children: [title !== void 0 && jsx("div", {
|
|
434
|
+
...part("page", "title"),
|
|
435
|
+
children: title
|
|
436
|
+
}), titleExtra !== void 0 && jsx("div", {
|
|
437
|
+
...part("page", "title-extra"),
|
|
438
|
+
children: titleExtra
|
|
439
|
+
})]
|
|
440
|
+
}), actions !== void 0 && jsx("div", {
|
|
441
|
+
...part("page", "actions"),
|
|
442
|
+
children: actions
|
|
443
|
+
})]
|
|
444
|
+
}),
|
|
445
|
+
description !== void 0 && jsx("div", {
|
|
446
|
+
...part("page", "description"),
|
|
447
|
+
children: description
|
|
448
|
+
}),
|
|
449
|
+
header
|
|
450
|
+
]
|
|
451
|
+
}), jsx("div", {
|
|
452
|
+
...part("page", "body"),
|
|
453
|
+
style: {
|
|
454
|
+
display: "flex",
|
|
455
|
+
flexDirection: "column",
|
|
456
|
+
flex: 1,
|
|
457
|
+
minHeight: 0
|
|
458
|
+
},
|
|
459
|
+
children
|
|
460
|
+
})]
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/** A titled content section. */
|
|
464
|
+
function Section({ title, description, actions, className, style, children }) {
|
|
465
|
+
return jsxs("section", {
|
|
466
|
+
...part("section", "root"),
|
|
467
|
+
className: cn("snap-section", className),
|
|
468
|
+
style: {
|
|
469
|
+
display: "flex",
|
|
470
|
+
flexDirection: "column",
|
|
471
|
+
gap: space("sm"),
|
|
472
|
+
...style
|
|
473
|
+
},
|
|
474
|
+
children: [(title !== void 0 || actions !== void 0) && jsxs("div", {
|
|
475
|
+
...part("section", "header"),
|
|
476
|
+
style: {
|
|
477
|
+
display: "flex",
|
|
478
|
+
alignItems: "center",
|
|
479
|
+
justifyContent: "space-between",
|
|
480
|
+
gap: space("md")
|
|
481
|
+
},
|
|
482
|
+
children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
|
|
483
|
+
...part("section", "title"),
|
|
484
|
+
children: title
|
|
485
|
+
}), description !== void 0 && jsx("div", { children: description })] }), actions !== void 0 && jsx("div", {
|
|
486
|
+
...part("section", "actions"),
|
|
487
|
+
children: actions
|
|
488
|
+
})]
|
|
489
|
+
}), jsx("div", {
|
|
490
|
+
...part("section", "body"),
|
|
491
|
+
children
|
|
492
|
+
})]
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region lib/types/components/surface.js
|
|
497
|
+
/** A semantic table. */
|
|
498
|
+
function Table({ className, children, ...props }) {
|
|
499
|
+
return jsx("div", {
|
|
500
|
+
...part("table", "root"),
|
|
501
|
+
className: cn("snap-table", className),
|
|
502
|
+
children: jsx("table", {
|
|
503
|
+
...props,
|
|
504
|
+
children
|
|
505
|
+
})
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
/** The table head. */
|
|
509
|
+
function TableHeader({ className, children, ...props }) {
|
|
510
|
+
return jsx("thead", {
|
|
511
|
+
...part("table", "header"),
|
|
512
|
+
className: cn("snap-table-header", className),
|
|
513
|
+
...props,
|
|
514
|
+
children
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
/** The table body. */
|
|
518
|
+
function TableBody({ className, children, ...props }) {
|
|
519
|
+
return jsx("tbody", {
|
|
520
|
+
...part("table", "body"),
|
|
521
|
+
className: cn("snap-table-body", className),
|
|
522
|
+
...props,
|
|
523
|
+
children
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
/** A table row. */
|
|
527
|
+
function TableRow({ className, children, ...props }) {
|
|
528
|
+
return jsx("tr", {
|
|
529
|
+
...part("table", "row"),
|
|
530
|
+
className: cn("snap-table-row", className),
|
|
531
|
+
...props,
|
|
532
|
+
children
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
/** A table header cell. */
|
|
536
|
+
function TableHead({ className, children, ...props }) {
|
|
537
|
+
return jsx("th", {
|
|
538
|
+
...part("table", "head"),
|
|
539
|
+
className: cn("snap-table-head", className),
|
|
540
|
+
...props,
|
|
541
|
+
children
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
/** A table body cell. */
|
|
545
|
+
function TableCell({ className, children, ...props }) {
|
|
546
|
+
return jsx("td", {
|
|
547
|
+
...part("table", "cell"),
|
|
548
|
+
className: cn("snap-table-cell", className),
|
|
549
|
+
...props,
|
|
550
|
+
children
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region lib/types/contract.js
|
|
555
|
+
/** The stable region slots every layout may provide. */
|
|
556
|
+
const UI_SLOT_IDS = {
|
|
557
|
+
/** The one active layout of the operator window. */
|
|
558
|
+
layout: "shell.layout",
|
|
559
|
+
/** The operator titlebar. */
|
|
560
|
+
titlebar: "shell.titlebar",
|
|
561
|
+
/** Contributed titlebar actions. */
|
|
562
|
+
titlebarActions: "shell.titlebar.actions",
|
|
563
|
+
/** Sidebar extension area. */
|
|
564
|
+
sidebar: "shell.sidebar",
|
|
565
|
+
/** Statusbar extension area. */
|
|
566
|
+
statusbar: "shell.statusbar",
|
|
567
|
+
/** The global overlay stack (dialogs, confirms). */
|
|
568
|
+
overlay: "shell.overlay",
|
|
569
|
+
/** The floating ball surface face. */
|
|
570
|
+
ball: "shell.ball",
|
|
571
|
+
/** The settings trigger. */
|
|
572
|
+
settingsEntry: "settings.entry",
|
|
573
|
+
/** The settings surface itself. */
|
|
574
|
+
settingsSurface: "settings.surface"
|
|
575
|
+
};
|
|
576
|
+
/** A named custom slot is owned by a publisher package. */
|
|
577
|
+
const CUSTOM_SLOT_PATTERN = /^custom:[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*$/;
|
|
578
|
+
/** Check a region-slot id at runtime. */
|
|
579
|
+
function isValidSlotId(value) {
|
|
580
|
+
return Object.values(UI_SLOT_IDS).includes(value) || CUSTOM_SLOT_PATTERN.test(value);
|
|
581
|
+
}
|
|
582
|
+
/** The occupancy mode of every built-in slot. */
|
|
583
|
+
const UI_SLOT_MODES = {
|
|
584
|
+
[UI_SLOT_IDS.layout]: "one",
|
|
585
|
+
[UI_SLOT_IDS.titlebar]: "one",
|
|
586
|
+
[UI_SLOT_IDS.titlebarActions]: "many",
|
|
587
|
+
[UI_SLOT_IDS.sidebar]: "many",
|
|
588
|
+
[UI_SLOT_IDS.statusbar]: "many",
|
|
589
|
+
[UI_SLOT_IDS.overlay]: "many",
|
|
590
|
+
[UI_SLOT_IDS.ball]: "one",
|
|
591
|
+
[UI_SLOT_IDS.settingsEntry]: "one",
|
|
592
|
+
[UI_SLOT_IDS.settingsSurface]: "one"
|
|
593
|
+
};
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region lib/types/pages.js
|
|
596
|
+
/**
|
|
597
|
+
* The main-page registry: business views contribute a page, a layout renders
|
|
598
|
+
* the active one. This is deliberately separate from settings pages and from
|
|
599
|
+
* the chrome slots; gating/workflows can wrap it later without changing the
|
|
600
|
+
* page authoring surface.
|
|
601
|
+
*
|
|
602
|
+
* @module @snap-rail/ui/pages
|
|
603
|
+
*/
|
|
604
|
+
/** Mount the page registry. */
|
|
605
|
+
const pagesPlugin = {
|
|
606
|
+
name: "snap-rail ui pages",
|
|
607
|
+
apply(ctx) {
|
|
608
|
+
const pages = /* @__PURE__ */ new Map();
|
|
609
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
610
|
+
let revision = 0;
|
|
611
|
+
let seq = 0;
|
|
612
|
+
let activeId;
|
|
613
|
+
const ordered = () => [...pages.values()].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
|
|
614
|
+
const notify = () => {
|
|
615
|
+
revision += 1;
|
|
616
|
+
for (const listener of listeners) listener();
|
|
617
|
+
ctx.emit("pages/changed");
|
|
618
|
+
};
|
|
619
|
+
const service = {
|
|
620
|
+
registerPage(caller, page) {
|
|
621
|
+
pages.set(page.id, {
|
|
622
|
+
page,
|
|
623
|
+
seq: seq++
|
|
624
|
+
});
|
|
625
|
+
activeId ??= page.id;
|
|
626
|
+
notify();
|
|
627
|
+
const remove = () => {
|
|
628
|
+
if (!pages.delete(page.id)) return;
|
|
629
|
+
if (activeId === page.id) activeId = ordered()[0]?.id;
|
|
630
|
+
notify();
|
|
631
|
+
};
|
|
632
|
+
caller.effect(() => remove);
|
|
633
|
+
return remove;
|
|
634
|
+
},
|
|
635
|
+
list: ordered,
|
|
636
|
+
active() {
|
|
637
|
+
if (activeId === void 0) return void 0;
|
|
638
|
+
return pages.get(activeId)?.page ?? ordered()[0];
|
|
639
|
+
},
|
|
640
|
+
setActive(id) {
|
|
641
|
+
if (!pages.has(id) || activeId === id) return;
|
|
642
|
+
activeId = id;
|
|
643
|
+
notify();
|
|
644
|
+
},
|
|
645
|
+
subscribe(listener) {
|
|
646
|
+
listeners.add(listener);
|
|
647
|
+
return () => {
|
|
648
|
+
listeners.delete(listener);
|
|
649
|
+
};
|
|
650
|
+
},
|
|
651
|
+
version: () => revision
|
|
652
|
+
};
|
|
653
|
+
ctx.provide("pages", service);
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
/** Re-render a layout when the page registry or active page changes. */
|
|
657
|
+
function usePagesVersion(ctx) {
|
|
658
|
+
return useSyncExternalStore(ctx.pages.subscribe, ctx.pages.version, ctx.pages.version);
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region lib/types/slots.js
|
|
662
|
+
const MAX_DIAGNOSTICS = 100;
|
|
663
|
+
/** The default definition of a built-in slot. */
|
|
664
|
+
function builtinDefinition(slot) {
|
|
665
|
+
return {
|
|
666
|
+
id: slot,
|
|
667
|
+
mode: UI_SLOT_MODES[slot] ?? "many"
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
/** Mount the `ctx.ui` registry. */
|
|
671
|
+
const slotsPlugin = {
|
|
672
|
+
name: "snap-rail ui slots",
|
|
673
|
+
apply(ctx) {
|
|
674
|
+
const entries = /* @__PURE__ */ new Map();
|
|
675
|
+
const layouts = /* @__PURE__ */ new Map();
|
|
676
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
677
|
+
const diagnostics = [];
|
|
678
|
+
let revision = 0;
|
|
679
|
+
let layoutSeq = 0;
|
|
680
|
+
for (const slot of Object.values(UI_SLOT_IDS)) entries.set(slot, {
|
|
681
|
+
def: builtinDefinition(slot),
|
|
682
|
+
contributions: /* @__PURE__ */ new Map(),
|
|
683
|
+
nextSeq: 0
|
|
684
|
+
});
|
|
685
|
+
const notify = (slot) => {
|
|
686
|
+
revision += 1;
|
|
687
|
+
for (const listener of listeners) listener();
|
|
688
|
+
ctx.emit("ui/changed");
|
|
689
|
+
if (slot !== void 0) ctx.emit("ui/slot-changed", slot);
|
|
690
|
+
};
|
|
691
|
+
const diagnose = (diagnostic) => {
|
|
692
|
+
diagnostics.push({
|
|
693
|
+
...diagnostic,
|
|
694
|
+
time: Date.now()
|
|
695
|
+
});
|
|
696
|
+
if (diagnostics.length > MAX_DIAGNOSTICS) diagnostics.shift();
|
|
697
|
+
};
|
|
698
|
+
const activeLayoutOf = () => {
|
|
699
|
+
return [...layouts.values()].sort((a, b) => {
|
|
700
|
+
const pa = a.layout.precedence ?? 0;
|
|
701
|
+
return (b.layout.precedence ?? 0) - pa || a.layout.order - b.layout.order || b.seq - a.seq;
|
|
702
|
+
})[0]?.layout;
|
|
703
|
+
};
|
|
704
|
+
const ensureEntry = (slot) => {
|
|
705
|
+
const existing = entries.get(slot);
|
|
706
|
+
if (existing !== void 0) return existing;
|
|
707
|
+
const entry = {
|
|
708
|
+
def: {
|
|
709
|
+
id: slot,
|
|
710
|
+
mode: "many"
|
|
711
|
+
},
|
|
712
|
+
contributions: /* @__PURE__ */ new Map(),
|
|
713
|
+
nextSeq: 0
|
|
714
|
+
};
|
|
715
|
+
entries.set(slot, entry);
|
|
716
|
+
return entry;
|
|
717
|
+
};
|
|
718
|
+
ctx.provide("ui", {
|
|
719
|
+
defineSlot(caller, def) {
|
|
720
|
+
if (!isValidSlotId(def.id)) {
|
|
721
|
+
diagnose({
|
|
722
|
+
kind: "unknown-slot",
|
|
723
|
+
slot: def.id,
|
|
724
|
+
message: `插槽 id 不合法:${def.id}`
|
|
725
|
+
});
|
|
726
|
+
return () => {};
|
|
727
|
+
}
|
|
728
|
+
if (Object.values(UI_SLOT_IDS).includes(def.id)) {
|
|
729
|
+
diagnose({
|
|
730
|
+
kind: "duplicate-id",
|
|
731
|
+
slot: def.id,
|
|
732
|
+
message: `内置插槽不能被重新定义:${def.id}`
|
|
733
|
+
});
|
|
734
|
+
return () => {};
|
|
735
|
+
}
|
|
736
|
+
const entry = ensureEntry(def.id);
|
|
737
|
+
entry.def = def;
|
|
738
|
+
notify(def.id);
|
|
739
|
+
const remove = () => {
|
|
740
|
+
if (entries.delete(def.id)) notify(def.id);
|
|
741
|
+
};
|
|
742
|
+
caller.effect(() => remove);
|
|
743
|
+
return remove;
|
|
744
|
+
},
|
|
745
|
+
registerLayout(caller, layout) {
|
|
746
|
+
for (const slot of layout.provides) if (!isValidSlotId(slot)) diagnose({
|
|
747
|
+
kind: "unknown-slot",
|
|
748
|
+
id: layout.id,
|
|
749
|
+
slot,
|
|
750
|
+
message: `布局 ${layout.id} 声明了非法插槽:${slot}`
|
|
751
|
+
});
|
|
752
|
+
else if (!entries.has(slot)) diagnose({
|
|
753
|
+
kind: "unknown-slot",
|
|
754
|
+
id: layout.id,
|
|
755
|
+
slot,
|
|
756
|
+
message: `布局 ${layout.id} 声明了未定义的插槽:${slot}`
|
|
757
|
+
});
|
|
758
|
+
layouts.set(layout.id, {
|
|
759
|
+
layout,
|
|
760
|
+
seq: layoutSeq++
|
|
761
|
+
});
|
|
762
|
+
notify();
|
|
763
|
+
const remove = () => {
|
|
764
|
+
if (layouts.delete(layout.id)) notify();
|
|
765
|
+
};
|
|
766
|
+
caller.effect(() => remove);
|
|
767
|
+
return remove;
|
|
768
|
+
},
|
|
769
|
+
contribute(caller, slot, contribution) {
|
|
770
|
+
if (!isValidSlotId(slot)) {
|
|
771
|
+
diagnose({
|
|
772
|
+
kind: "unknown-slot",
|
|
773
|
+
id: contribution.id,
|
|
774
|
+
slot,
|
|
775
|
+
message: `贡献 ${contribution.id} 指向非法插槽:${slot}`
|
|
776
|
+
});
|
|
777
|
+
return () => {};
|
|
778
|
+
}
|
|
779
|
+
const entry = entries.get(slot);
|
|
780
|
+
if (entry === void 0) diagnose({
|
|
781
|
+
kind: "unknown-slot",
|
|
782
|
+
id: contribution.id,
|
|
783
|
+
slot,
|
|
784
|
+
message: `贡献 ${contribution.id} 指向未定义的插槽:${slot}`
|
|
785
|
+
});
|
|
786
|
+
const target = entry ?? ensureEntry(slot);
|
|
787
|
+
target.contributions.set(contribution.id, {
|
|
788
|
+
contribution,
|
|
789
|
+
seq: target.nextSeq++
|
|
790
|
+
});
|
|
791
|
+
notify(slot);
|
|
792
|
+
const remove = () => {
|
|
793
|
+
if (target.contributions.delete(contribution.id)) notify(slot);
|
|
794
|
+
};
|
|
795
|
+
caller.effect(() => remove);
|
|
796
|
+
return remove;
|
|
797
|
+
},
|
|
798
|
+
list(slot) {
|
|
799
|
+
const entry = entries.get(slot);
|
|
800
|
+
if (entry === void 0) return [];
|
|
801
|
+
const ranked = [...entry.contributions.values()].sort((a, b) => a.contribution.order - b.contribution.order || a.seq - b.seq);
|
|
802
|
+
if (entry.def.mode !== "one" || ranked.length === 0) return ranked.map((item) => item.contribution);
|
|
803
|
+
return [ranked.reduce((best, item) => {
|
|
804
|
+
const delta = (item.contribution.precedence ?? 0) - (best.contribution.precedence ?? 0);
|
|
805
|
+
return delta > 0 || delta === 0 && item.seq > best.seq ? item : best;
|
|
806
|
+
}).contribution];
|
|
807
|
+
},
|
|
808
|
+
definition: (slot) => entries.get(slot)?.def,
|
|
809
|
+
activeLayout: activeLayoutOf,
|
|
810
|
+
hasProvider(slot) {
|
|
811
|
+
const active = activeLayoutOf();
|
|
812
|
+
return active !== void 0 && active.provides.includes(slot);
|
|
813
|
+
},
|
|
814
|
+
diagnostics: () => diagnostics,
|
|
815
|
+
subscribe(listener) {
|
|
816
|
+
listeners.add(listener);
|
|
817
|
+
return () => {
|
|
818
|
+
listeners.delete(listener);
|
|
819
|
+
};
|
|
820
|
+
},
|
|
821
|
+
version: () => revision
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
/** The React context carrying the active UI service. */
|
|
826
|
+
const UiContext = createContext(null);
|
|
827
|
+
/** Provide the UI service to a slot tree. */
|
|
828
|
+
function UiProvider(props) {
|
|
829
|
+
return jsx(UiContext.Provider, {
|
|
830
|
+
value: props.service,
|
|
831
|
+
children: props.children
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
/** Read the UI service; throws when a slot tree is mounted outside the runtime. */
|
|
835
|
+
function useUi() {
|
|
836
|
+
const service = useContext(UiContext);
|
|
837
|
+
if (service === null) throw new Error("useUi: no UiProvider in the tree");
|
|
838
|
+
return service;
|
|
839
|
+
}
|
|
840
|
+
/** Re-render on every registry change. */
|
|
841
|
+
function useUiVersion(service) {
|
|
842
|
+
return useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
843
|
+
}
|
|
844
|
+
/** Keep one broken contribution from taking down the whole shell. */
|
|
845
|
+
var SlotBoundary = class extends Component {
|
|
846
|
+
state = { failed: false };
|
|
847
|
+
static getDerivedStateFromError() {
|
|
848
|
+
return { failed: true };
|
|
849
|
+
}
|
|
850
|
+
componentDidCatch(error) {
|
|
851
|
+
this.props.onError(error);
|
|
852
|
+
}
|
|
853
|
+
render() {
|
|
854
|
+
return this.state.failed ? null : this.props.children;
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
/** A region-slot outlet rendered by a layout. */
|
|
858
|
+
function Slot(props) {
|
|
859
|
+
const service = useUi();
|
|
860
|
+
useUiVersion(service);
|
|
861
|
+
const provided = service.hasProvider(props.name);
|
|
862
|
+
const entry = service.list(props.name);
|
|
863
|
+
const def = service.definition(props.name);
|
|
864
|
+
const context = props.context ?? {};
|
|
865
|
+
if (!provided) return null;
|
|
866
|
+
if (entry.length === 0) {
|
|
867
|
+
const fallback = def?.fallback;
|
|
868
|
+
return fallback?.(context) ?? null;
|
|
869
|
+
}
|
|
870
|
+
return jsx(Fragment, { children: entry.map((item) => jsx(SlotBoundary, {
|
|
871
|
+
onError: (error) => {
|
|
872
|
+
console.error(`[snap-rail ui] slot ${props.name} contribution ${item.id} failed`, error);
|
|
873
|
+
},
|
|
874
|
+
children: item.render(context)
|
|
875
|
+
}, item.id)) });
|
|
876
|
+
}
|
|
877
|
+
/** Re-render when the active layout changes. */
|
|
878
|
+
function useActiveLayout() {
|
|
879
|
+
const service = useUi();
|
|
880
|
+
useUiVersion(service);
|
|
881
|
+
return service.activeLayout();
|
|
882
|
+
}
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region lib/types/fallback.js
|
|
885
|
+
/** A compact glyph for the window controls. */
|
|
886
|
+
function Glyph(props) {
|
|
887
|
+
return jsx("span", {
|
|
888
|
+
"aria-hidden": "true",
|
|
889
|
+
style: { lineHeight: 1 },
|
|
890
|
+
children: props.children
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
/** The fallback body. */
|
|
894
|
+
function FallbackShell(props) {
|
|
895
|
+
useUiVersion(props.ctx.ui);
|
|
896
|
+
usePagesVersion(props.ctx);
|
|
897
|
+
const active = props.ctx.pages.active();
|
|
898
|
+
const control = (action) => {
|
|
899
|
+
props.ctx.client.link.call("window.control", { action }).catch(() => {});
|
|
900
|
+
};
|
|
901
|
+
const header = jsxs("div", {
|
|
902
|
+
className: "snap-fallback-titlebar",
|
|
903
|
+
style: {
|
|
904
|
+
display: "flex",
|
|
905
|
+
alignItems: "center",
|
|
906
|
+
justifyContent: "space-between",
|
|
907
|
+
minHeight: 48,
|
|
908
|
+
paddingLeft: 16
|
|
909
|
+
},
|
|
910
|
+
children: [jsxs("span", {
|
|
911
|
+
style: {
|
|
912
|
+
color: "var(--snap-color-muted)",
|
|
913
|
+
fontSize: "var(--snap-text-sm)"
|
|
914
|
+
},
|
|
915
|
+
children: ["snap-rail", active !== void 0 ? ` · ${active.title}` : ""]
|
|
916
|
+
}), jsxs("div", {
|
|
917
|
+
style: {
|
|
918
|
+
display: "flex",
|
|
919
|
+
alignItems: "center",
|
|
920
|
+
gap: 4
|
|
921
|
+
},
|
|
922
|
+
children: [
|
|
923
|
+
jsx(Slot, {
|
|
924
|
+
name: UI_SLOT_IDS.settingsEntry,
|
|
925
|
+
context: {
|
|
926
|
+
presentation: "icon",
|
|
927
|
+
open: () => props.ctx.settings.open(),
|
|
928
|
+
isOpen: props.ctx.settings.isOpen()
|
|
929
|
+
}
|
|
930
|
+
}),
|
|
931
|
+
jsx(IconButton, {
|
|
932
|
+
icon: jsx(Glyph, { children: "—" }),
|
|
933
|
+
label: "最小化",
|
|
934
|
+
onClick: () => control("minimize")
|
|
935
|
+
}),
|
|
936
|
+
jsx(IconButton, {
|
|
937
|
+
icon: jsx(Glyph, { children: "□" }),
|
|
938
|
+
label: "最大化切换",
|
|
939
|
+
onClick: () => control("toggle-maximize")
|
|
940
|
+
}),
|
|
941
|
+
jsx(IconButton, {
|
|
942
|
+
icon: jsx(Glyph, { children: "×" }),
|
|
943
|
+
label: "关闭",
|
|
944
|
+
onClick: () => control("close")
|
|
945
|
+
})
|
|
946
|
+
]
|
|
947
|
+
})]
|
|
948
|
+
});
|
|
949
|
+
return jsx(AppShell, {
|
|
950
|
+
header,
|
|
951
|
+
children: active !== void 0 ? active.render() : jsx("div", {
|
|
952
|
+
style: {
|
|
953
|
+
display: "flex",
|
|
954
|
+
minHeight: "100%",
|
|
955
|
+
alignItems: "center",
|
|
956
|
+
justifyContent: "center",
|
|
957
|
+
padding: 24
|
|
958
|
+
},
|
|
959
|
+
children: jsx(EmptyState, {
|
|
960
|
+
title: "尚未激活业务套件",
|
|
961
|
+
action: jsx(Button, {
|
|
962
|
+
intent: "primary",
|
|
963
|
+
onClick: () => props.ctx.settings.open("plugins"),
|
|
964
|
+
children: "打开设置"
|
|
965
|
+
})
|
|
966
|
+
})
|
|
967
|
+
})
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
/** The fallback layout occupant. */
|
|
971
|
+
const fallbackPlugin = {
|
|
972
|
+
name: "snap-rail fallback layout",
|
|
973
|
+
inject: [
|
|
974
|
+
"ui",
|
|
975
|
+
"settings",
|
|
976
|
+
"pages",
|
|
977
|
+
"client"
|
|
978
|
+
],
|
|
979
|
+
apply(ctx) {
|
|
980
|
+
ctx.ui.registerLayout(ctx, {
|
|
981
|
+
id: "fallback",
|
|
982
|
+
order: 200,
|
|
983
|
+
precedence: 0,
|
|
984
|
+
provides: [
|
|
985
|
+
UI_SLOT_IDS.titlebar,
|
|
986
|
+
UI_SLOT_IDS.titlebarActions,
|
|
987
|
+
UI_SLOT_IDS.sidebar,
|
|
988
|
+
UI_SLOT_IDS.statusbar,
|
|
989
|
+
UI_SLOT_IDS.settingsEntry
|
|
990
|
+
],
|
|
991
|
+
window: {
|
|
992
|
+
width: 1280,
|
|
993
|
+
height: 800,
|
|
994
|
+
minWidth: 960,
|
|
995
|
+
minHeight: 600
|
|
996
|
+
},
|
|
997
|
+
ball: { size: 128 },
|
|
998
|
+
render: () => jsx(FallbackShell, { ctx })
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
//#endregion
|
|
1003
|
+
//#region lib/types/skins.js
|
|
1004
|
+
/** The factory day theme id (cobalt palette, light surfaces). */
|
|
1005
|
+
const DEFAULT_LIGHT_ID = "default-light";
|
|
1006
|
+
/** The factory night theme id (cobalt palette, dark surfaces). */
|
|
1007
|
+
const DEFAULT_DARK_ID = "default-dark";
|
|
1008
|
+
/** The contributor label for the factory themes. */
|
|
1009
|
+
const FACTORY_CALLER = "@snap-rail/ui";
|
|
1010
|
+
const COBALT_DARK_TOKENS = {
|
|
1011
|
+
colorBg: "#0b0f14",
|
|
1012
|
+
colorSurface: "#11161d",
|
|
1013
|
+
colorSurfaceRaised: "#161b22",
|
|
1014
|
+
colorText: "#ced8e3",
|
|
1015
|
+
colorMuted: "#8b949e",
|
|
1016
|
+
colorPrimary: "#4a6cff",
|
|
1017
|
+
colorOnPrimary: "#ffffff",
|
|
1018
|
+
colorDanger: "#f85149",
|
|
1019
|
+
colorSuccess: "#3fb950",
|
|
1020
|
+
colorWarning: "#d29922",
|
|
1021
|
+
colorBorder: "#1f2933",
|
|
1022
|
+
colorFocus: "#4a6cff",
|
|
1023
|
+
chart1: "#4a6cff",
|
|
1024
|
+
chart2: "#3147a1",
|
|
1025
|
+
chart3: "#667fcd",
|
|
1026
|
+
chart4: "#7d8fa5",
|
|
1027
|
+
chart5: "#55677c",
|
|
1028
|
+
chart6: "#33414f",
|
|
1029
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
1030
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
1031
|
+
textXs: "13px",
|
|
1032
|
+
textSm: "15px",
|
|
1033
|
+
textMd: "17px",
|
|
1034
|
+
textLg: "20px",
|
|
1035
|
+
textXl: "24px",
|
|
1036
|
+
weightNormal: "400",
|
|
1037
|
+
weightMedium: "500",
|
|
1038
|
+
weightStrong: "600",
|
|
1039
|
+
leadingTight: "1.2",
|
|
1040
|
+
leadingNormal: "1.55",
|
|
1041
|
+
spaceXs: "4px",
|
|
1042
|
+
spaceSm: "8px",
|
|
1043
|
+
spaceMd: "12px",
|
|
1044
|
+
spaceLg: "20px",
|
|
1045
|
+
spaceXl: "32px",
|
|
1046
|
+
radiusSm: "6px",
|
|
1047
|
+
radiusMd: "8px",
|
|
1048
|
+
radiusLg: "12px",
|
|
1049
|
+
radiusFull: "999px",
|
|
1050
|
+
borderWidth: "1px",
|
|
1051
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
|
|
1052
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
|
|
1053
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
|
|
1054
|
+
durationFast: "120ms",
|
|
1055
|
+
durationNormal: "180ms",
|
|
1056
|
+
durationSlow: "280ms",
|
|
1057
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
1058
|
+
zOverlay: "50",
|
|
1059
|
+
zModal: "60",
|
|
1060
|
+
zToast: "70",
|
|
1061
|
+
controlHeightSm: "40px",
|
|
1062
|
+
controlHeightMd: "48px",
|
|
1063
|
+
controlHeightLg: "56px",
|
|
1064
|
+
density: "comfortable"
|
|
1065
|
+
};
|
|
1066
|
+
/** The factory day theme. Always registered; never the first paint though — the night theme is. */
|
|
1067
|
+
const DEFAULT_LIGHT = {
|
|
1068
|
+
id: DEFAULT_LIGHT_ID,
|
|
1069
|
+
title: "钴蓝·白天",
|
|
1070
|
+
tokens: {
|
|
1071
|
+
colorBg: "#e4e9ef",
|
|
1072
|
+
colorSurface: "#f3f6f9",
|
|
1073
|
+
colorSurfaceRaised: "#ffffff",
|
|
1074
|
+
colorText: "#26323e",
|
|
1075
|
+
colorMuted: "#5d6d7e",
|
|
1076
|
+
colorPrimary: "#3857e8",
|
|
1077
|
+
colorOnPrimary: "#ffffff",
|
|
1078
|
+
colorDanger: "#dc2626",
|
|
1079
|
+
colorSuccess: "#15803d",
|
|
1080
|
+
colorWarning: "#b45309",
|
|
1081
|
+
colorBorder: "#c7d0da",
|
|
1082
|
+
colorFocus: "#3857e8",
|
|
1083
|
+
chart1: "#3857e8",
|
|
1084
|
+
chart2: "#7088ee",
|
|
1085
|
+
chart3: "#667dd0",
|
|
1086
|
+
chart4: "#94a3b8",
|
|
1087
|
+
chart5: "#b3c0cd",
|
|
1088
|
+
chart6: "#ccd6e0",
|
|
1089
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
1090
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
1091
|
+
textXs: "13px",
|
|
1092
|
+
textSm: "15px",
|
|
1093
|
+
textMd: "17px",
|
|
1094
|
+
textLg: "20px",
|
|
1095
|
+
textXl: "24px",
|
|
1096
|
+
weightNormal: "400",
|
|
1097
|
+
weightMedium: "500",
|
|
1098
|
+
weightStrong: "600",
|
|
1099
|
+
leadingTight: "1.2",
|
|
1100
|
+
leadingNormal: "1.55",
|
|
1101
|
+
spaceXs: "4px",
|
|
1102
|
+
spaceSm: "8px",
|
|
1103
|
+
spaceMd: "12px",
|
|
1104
|
+
spaceLg: "20px",
|
|
1105
|
+
spaceXl: "32px",
|
|
1106
|
+
radiusSm: "6px",
|
|
1107
|
+
radiusMd: "8px",
|
|
1108
|
+
radiusLg: "12px",
|
|
1109
|
+
radiusFull: "999px",
|
|
1110
|
+
borderWidth: "1px",
|
|
1111
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
|
|
1112
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
|
|
1113
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
|
|
1114
|
+
durationFast: "120ms",
|
|
1115
|
+
durationNormal: "180ms",
|
|
1116
|
+
durationSlow: "280ms",
|
|
1117
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
1118
|
+
zOverlay: "50",
|
|
1119
|
+
zModal: "60",
|
|
1120
|
+
zToast: "70",
|
|
1121
|
+
controlHeightSm: "40px",
|
|
1122
|
+
controlHeightMd: "48px",
|
|
1123
|
+
controlHeightLg: "56px",
|
|
1124
|
+
density: "comfortable"
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
/** The factory night theme and the registry's fallback. */
|
|
1128
|
+
const DEFAULT_DARK = {
|
|
1129
|
+
id: DEFAULT_DARK_ID,
|
|
1130
|
+
title: "钴蓝·黑夜",
|
|
1131
|
+
tokens: COBALT_DARK_TOKENS
|
|
1132
|
+
};
|
|
1133
|
+
/** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
|
|
1134
|
+
function skinTokenVar(key) {
|
|
1135
|
+
return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
|
|
1136
|
+
}
|
|
1137
|
+
/** Apply the active theme to the document root. */
|
|
1138
|
+
function applySkin(skin) {
|
|
1139
|
+
if (typeof document === "undefined") return;
|
|
1140
|
+
const root = document.documentElement;
|
|
1141
|
+
root.dataset["snapSkin"] = skin.id;
|
|
1142
|
+
for (const [key, value] of Object.entries(skin.tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
1143
|
+
}
|
|
1144
|
+
/** Mount the `ctx.skins` registry. */
|
|
1145
|
+
const skinsPlugin = {
|
|
1146
|
+
name: "snap-rail ui skins",
|
|
1147
|
+
apply(ctx) {
|
|
1148
|
+
const skins = /* @__PURE__ */ new Map();
|
|
1149
|
+
const callers = /* @__PURE__ */ new Map();
|
|
1150
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1151
|
+
const styleTags = /* @__PURE__ */ new Map();
|
|
1152
|
+
let activeId = DEFAULT_DARK_ID;
|
|
1153
|
+
let revision = 0;
|
|
1154
|
+
skins.set(DEFAULT_LIGHT_ID, DEFAULT_LIGHT);
|
|
1155
|
+
callers.set(DEFAULT_LIGHT_ID, FACTORY_CALLER);
|
|
1156
|
+
skins.set(DEFAULT_DARK_ID, DEFAULT_DARK);
|
|
1157
|
+
callers.set(DEFAULT_DARK_ID, FACTORY_CALLER);
|
|
1158
|
+
const notify = () => {
|
|
1159
|
+
revision += 1;
|
|
1160
|
+
for (const listener of listeners) listener();
|
|
1161
|
+
ctx.emit("skins/changed");
|
|
1162
|
+
};
|
|
1163
|
+
const ensureStyleTag = (skin) => {
|
|
1164
|
+
if (typeof document === "undefined" || skin.css === void 0) return;
|
|
1165
|
+
if (styleTags.has(skin.id)) return;
|
|
1166
|
+
const tag = document.createElement("style");
|
|
1167
|
+
tag.dataset["snapSkinStyle"] = skin.id;
|
|
1168
|
+
tag.textContent = skin.css;
|
|
1169
|
+
document.head.append(tag);
|
|
1170
|
+
styleTags.set(skin.id, tag);
|
|
1171
|
+
};
|
|
1172
|
+
const refresh = () => {
|
|
1173
|
+
const skin = skins.get(activeId) ?? DEFAULT_DARK;
|
|
1174
|
+
activeId = skin.id;
|
|
1175
|
+
ensureStyleTag(skin);
|
|
1176
|
+
applySkin(skin);
|
|
1177
|
+
notify();
|
|
1178
|
+
};
|
|
1179
|
+
ctx.provide("skins", {
|
|
1180
|
+
register(caller, skin) {
|
|
1181
|
+
skins.set(skin.id, skin);
|
|
1182
|
+
callers.set(skin.id, caller.fiber.name);
|
|
1183
|
+
refresh();
|
|
1184
|
+
const remove = () => {
|
|
1185
|
+
if (!skins.delete(skin.id)) return;
|
|
1186
|
+
callers.delete(skin.id);
|
|
1187
|
+
const tag = styleTags.get(skin.id);
|
|
1188
|
+
if (tag !== void 0) {
|
|
1189
|
+
tag.remove();
|
|
1190
|
+
styleTags.delete(skin.id);
|
|
1191
|
+
}
|
|
1192
|
+
if (activeId === skin.id) activeId = DEFAULT_DARK_ID;
|
|
1193
|
+
refresh();
|
|
1194
|
+
};
|
|
1195
|
+
caller.effect(() => remove);
|
|
1196
|
+
return remove;
|
|
1197
|
+
},
|
|
1198
|
+
activate(selection) {
|
|
1199
|
+
let next = skins.has(selection) ? selection : void 0;
|
|
1200
|
+
if (next === void 0) {
|
|
1201
|
+
for (const [id, owner] of callers) if (id !== selection && owner === selection && skins.has(id)) {
|
|
1202
|
+
next = id;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (next === void 0) return false;
|
|
1207
|
+
if (next === activeId) return true;
|
|
1208
|
+
activeId = next;
|
|
1209
|
+
refresh();
|
|
1210
|
+
return true;
|
|
1211
|
+
},
|
|
1212
|
+
list: () => [...skins.values()].map((skin) => ({
|
|
1213
|
+
id: skin.id,
|
|
1214
|
+
title: skin.title,
|
|
1215
|
+
caller: callers.get(skin.id) ?? FACTORY_CALLER
|
|
1216
|
+
})),
|
|
1217
|
+
active: () => skins.get(activeId) ?? DEFAULT_DARK,
|
|
1218
|
+
tokens: () => (skins.get(activeId) ?? DEFAULT_DARK).tokens,
|
|
1219
|
+
subscribe(listener) {
|
|
1220
|
+
listeners.add(listener);
|
|
1221
|
+
return () => {
|
|
1222
|
+
listeners.delete(listener);
|
|
1223
|
+
};
|
|
1224
|
+
},
|
|
1225
|
+
version: () => revision
|
|
1226
|
+
});
|
|
1227
|
+
refresh();
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
/** The React context carrying the skin service. */
|
|
1231
|
+
const SkinsContext = createContext(null);
|
|
1232
|
+
/** Provide the skin service to a renderer tree. */
|
|
1233
|
+
function SkinsProvider(props) {
|
|
1234
|
+
return jsx(SkinsContext.Provider, {
|
|
1235
|
+
value: props.service,
|
|
1236
|
+
children: props.children
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
/** Read the skin service. */
|
|
1240
|
+
function useSkins() {
|
|
1241
|
+
const service = useContext(SkinsContext);
|
|
1242
|
+
if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
|
|
1243
|
+
return service;
|
|
1244
|
+
}
|
|
1245
|
+
/** Re-render on theme changes and return the active theme id. */
|
|
1246
|
+
function useSkinId() {
|
|
1247
|
+
const service = useSkins();
|
|
1248
|
+
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
1249
|
+
return service.active().id;
|
|
1250
|
+
}
|
|
1251
|
+
//#endregion
|
|
1252
|
+
//#region lib/types/settings-pages/appearance.js
|
|
1253
|
+
const THEME_KEY = "ui.theme";
|
|
1254
|
+
const WINDOW_KEY = "ui.window";
|
|
1255
|
+
const BALL_KEY = "ui.ball";
|
|
1256
|
+
const WINDOW_PRESETS = [
|
|
1257
|
+
{
|
|
1258
|
+
label: "1280 × 800",
|
|
1259
|
+
width: 1280,
|
|
1260
|
+
height: 800
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
label: "1440 × 900",
|
|
1264
|
+
width: 1440,
|
|
1265
|
+
height: 900
|
|
1266
|
+
},
|
|
1267
|
+
{
|
|
1268
|
+
label: "1600 × 900",
|
|
1269
|
+
width: 1600,
|
|
1270
|
+
height: 900
|
|
1271
|
+
},
|
|
1272
|
+
{
|
|
1273
|
+
label: "1920 × 1080",
|
|
1274
|
+
width: 1920,
|
|
1275
|
+
height: 1080
|
|
1276
|
+
}
|
|
1277
|
+
];
|
|
1278
|
+
const BALL_SIZES = [
|
|
1279
|
+
96,
|
|
1280
|
+
112,
|
|
1281
|
+
128,
|
|
1282
|
+
160,
|
|
1283
|
+
192
|
|
1284
|
+
];
|
|
1285
|
+
/** Read a settings value through the host link. */
|
|
1286
|
+
async function readSetting(link, key) {
|
|
1287
|
+
const result = await link.call("settings.get", { key });
|
|
1288
|
+
return result.ok ? result.value.value : void 0;
|
|
1289
|
+
}
|
|
1290
|
+
/** Write a settings value; `null` clears the row. */
|
|
1291
|
+
async function writeSetting(link, key, value) {
|
|
1292
|
+
await link.call("settings.set", {
|
|
1293
|
+
key,
|
|
1294
|
+
value
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
/** The appearance/display page. */
|
|
1298
|
+
function AppearancePage() {
|
|
1299
|
+
const { link } = useClient();
|
|
1300
|
+
const skins = useSkins();
|
|
1301
|
+
const activeId = useSkinId();
|
|
1302
|
+
const [packages, setPackages] = useState([]);
|
|
1303
|
+
const [windowPreset, setWindowPreset] = useState(void 0);
|
|
1304
|
+
const [ballSize, setBallSize] = useState(128);
|
|
1305
|
+
const [ballEnabled, setBallEnabled] = useState(true);
|
|
1306
|
+
const [ballCollapse, setBallCollapse] = useState(true);
|
|
1307
|
+
const [error, setError] = useState(void 0);
|
|
1308
|
+
const [busy, setBusy] = useState(false);
|
|
1309
|
+
useEffect(() => {
|
|
1310
|
+
Promise.all([
|
|
1311
|
+
readSetting(link, WINDOW_KEY),
|
|
1312
|
+
readSetting(link, BALL_KEY),
|
|
1313
|
+
link.call("plugins.list", {})
|
|
1314
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
1315
|
+
const windowProfile = windowRow;
|
|
1316
|
+
if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
|
|
1317
|
+
const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
1318
|
+
setWindowPreset(preset?.label);
|
|
1319
|
+
}
|
|
1320
|
+
const ballProfile = ballRow;
|
|
1321
|
+
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
|
|
1322
|
+
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
|
|
1323
|
+
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
|
|
1324
|
+
if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
|
|
1325
|
+
name: plugin.packageName,
|
|
1326
|
+
title: plugin.title ?? plugin.packageName,
|
|
1327
|
+
enabled: plugin.enabled
|
|
1328
|
+
})));
|
|
1329
|
+
}).catch((cause) => {
|
|
1330
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1331
|
+
});
|
|
1332
|
+
}, [link]);
|
|
1333
|
+
const saveWindow = (width, height, label) => {
|
|
1334
|
+
setWindowPreset(label);
|
|
1335
|
+
writeSetting(link, WINDOW_KEY, {
|
|
1336
|
+
width,
|
|
1337
|
+
height,
|
|
1338
|
+
minWidth: 960,
|
|
1339
|
+
minHeight: 600
|
|
1340
|
+
}).catch((cause) => {
|
|
1341
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1342
|
+
});
|
|
1343
|
+
};
|
|
1344
|
+
const resetWindow = () => {
|
|
1345
|
+
setWindowPreset(void 0);
|
|
1346
|
+
writeSetting(link, WINDOW_KEY, null).catch((cause) => {
|
|
1347
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1348
|
+
});
|
|
1349
|
+
};
|
|
1350
|
+
const saveBall = (patch) => {
|
|
1351
|
+
const next = {
|
|
1352
|
+
size: patch.size ?? ballSize,
|
|
1353
|
+
enabled: patch.enabled ?? ballEnabled,
|
|
1354
|
+
collapse: patch.collapse ?? ballCollapse
|
|
1355
|
+
};
|
|
1356
|
+
if (patch.size !== void 0) setBallSize(patch.size);
|
|
1357
|
+
if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
|
|
1358
|
+
if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
|
|
1359
|
+
writeSetting(link, BALL_KEY, next).catch((cause) => {
|
|
1360
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1361
|
+
});
|
|
1362
|
+
};
|
|
1363
|
+
const tabs = [...skins.list().map((row) => ({
|
|
1364
|
+
id: row.id,
|
|
1365
|
+
title: row.title
|
|
1366
|
+
})), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
|
|
1367
|
+
id: pkg.name,
|
|
1368
|
+
title: pkg.title,
|
|
1369
|
+
enable: pkg.name
|
|
1370
|
+
}))];
|
|
1371
|
+
const selectTheme = (tab) => {
|
|
1372
|
+
if (busy) return;
|
|
1373
|
+
if (tab.enable === void 0) {
|
|
1374
|
+
writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
|
|
1375
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1376
|
+
});
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
setBusy(true);
|
|
1380
|
+
link.call("plugins.set-enabled", {
|
|
1381
|
+
name: tab.enable,
|
|
1382
|
+
enabled: true
|
|
1383
|
+
}).then((result) => {
|
|
1384
|
+
if (!result.ok) {
|
|
1385
|
+
setError(rpcErrorText(result.error));
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
|
|
1389
|
+
...pkg,
|
|
1390
|
+
enabled: true
|
|
1391
|
+
} : pkg));
|
|
1392
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
1393
|
+
}).catch((cause) => {
|
|
1394
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1395
|
+
}).finally(() => {
|
|
1396
|
+
setBusy(false);
|
|
1397
|
+
});
|
|
1398
|
+
};
|
|
1399
|
+
return jsx(Page, {
|
|
1400
|
+
title: "外观与显示",
|
|
1401
|
+
description: "主题、主窗口尺寸和悬浮球外观。",
|
|
1402
|
+
children: jsxs(Stack, {
|
|
1403
|
+
gap: "lg",
|
|
1404
|
+
children: [
|
|
1405
|
+
error !== void 0 && jsx("div", {
|
|
1406
|
+
role: "alert",
|
|
1407
|
+
style: { color: "var(--snap-color-danger)" },
|
|
1408
|
+
children: error
|
|
1409
|
+
}),
|
|
1410
|
+
jsx(Section, {
|
|
1411
|
+
title: "主题",
|
|
1412
|
+
children: jsx(Tabs, {
|
|
1413
|
+
value: activeId,
|
|
1414
|
+
onValueChange: (value) => {
|
|
1415
|
+
const tab = tabs.find((item) => item.id === value);
|
|
1416
|
+
if (tab !== void 0) selectTheme(tab);
|
|
1417
|
+
},
|
|
1418
|
+
children: jsx(TabsList, {
|
|
1419
|
+
"aria-label": "主题",
|
|
1420
|
+
children: tabs.map((tab) => jsx(TabsTrigger, {
|
|
1421
|
+
value: tab.id,
|
|
1422
|
+
disabled: busy,
|
|
1423
|
+
children: tab.title
|
|
1424
|
+
}, tab.id))
|
|
1425
|
+
})
|
|
1426
|
+
})
|
|
1427
|
+
}),
|
|
1428
|
+
jsx(Section, {
|
|
1429
|
+
title: "主窗口",
|
|
1430
|
+
children: jsxs(Stack, {
|
|
1431
|
+
gap: "sm",
|
|
1432
|
+
children: [jsxs(Row, {
|
|
1433
|
+
gap: "sm",
|
|
1434
|
+
wrap: true,
|
|
1435
|
+
children: [WINDOW_PRESETS.map((preset) => jsx(Button, {
|
|
1436
|
+
size: "sm",
|
|
1437
|
+
intent: windowPreset === preset.label ? "primary" : "neutral",
|
|
1438
|
+
emphasis: windowPreset === preset.label ? "solid" : "outline",
|
|
1439
|
+
onClick: () => saveWindow(preset.width, preset.height, preset.label),
|
|
1440
|
+
children: preset.label
|
|
1441
|
+
}, preset.label)), jsx(Button, {
|
|
1442
|
+
size: "sm",
|
|
1443
|
+
emphasis: "ghost",
|
|
1444
|
+
onClick: resetWindow,
|
|
1445
|
+
children: "跟随布局"
|
|
1446
|
+
})]
|
|
1447
|
+
}), jsxs("span", {
|
|
1448
|
+
style: {
|
|
1449
|
+
color: "var(--snap-color-muted)",
|
|
1450
|
+
fontSize: "var(--snap-text-sm)"
|
|
1451
|
+
},
|
|
1452
|
+
children: ["当前:", windowPreset ?? "跟随布局推荐 / 默认 1280 × 800"]
|
|
1453
|
+
})]
|
|
1454
|
+
})
|
|
1455
|
+
}),
|
|
1456
|
+
jsx(Section, {
|
|
1457
|
+
title: "悬浮球",
|
|
1458
|
+
description: "球面尺寸与停泊行为。",
|
|
1459
|
+
children: jsxs(Stack, {
|
|
1460
|
+
gap: "md",
|
|
1461
|
+
children: [jsx(Row, {
|
|
1462
|
+
gap: "sm",
|
|
1463
|
+
wrap: true,
|
|
1464
|
+
align: "center",
|
|
1465
|
+
children: BALL_SIZES.map((size) => jsxs(Button, {
|
|
1466
|
+
size: "sm",
|
|
1467
|
+
intent: ballSize === size ? "primary" : "neutral",
|
|
1468
|
+
emphasis: ballSize === size ? "solid" : "outline",
|
|
1469
|
+
onClick: () => saveBall({ size }),
|
|
1470
|
+
children: [size, "px"]
|
|
1471
|
+
}, size))
|
|
1472
|
+
}), jsxs(Row, {
|
|
1473
|
+
gap: "lg",
|
|
1474
|
+
wrap: true,
|
|
1475
|
+
align: "center",
|
|
1476
|
+
children: [jsx(Switch, {
|
|
1477
|
+
label: "启用悬浮球",
|
|
1478
|
+
checked: ballEnabled,
|
|
1479
|
+
onCheckedChange: (enabled) => saveBall({ enabled })
|
|
1480
|
+
}), jsx(Switch, {
|
|
1481
|
+
label: "允许贴边收起",
|
|
1482
|
+
checked: ballCollapse,
|
|
1483
|
+
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
1484
|
+
})]
|
|
1485
|
+
})]
|
|
1486
|
+
})
|
|
1487
|
+
})
|
|
1488
|
+
]
|
|
1489
|
+
})
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
//#endregion
|
|
1493
|
+
//#region lib/types/settings-pages/plugin-feed.js
|
|
1494
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
1495
|
+
function PluginFeedDialog(props) {
|
|
1496
|
+
const { open } = props;
|
|
1497
|
+
const link = props.ctx.client.link;
|
|
1498
|
+
const [urls, setUrls] = useState([]);
|
|
1499
|
+
const [draft, setDraft] = useState("");
|
|
1500
|
+
const [error, setError] = useState(void 0);
|
|
1501
|
+
useEffect(() => {
|
|
1502
|
+
if (!open) return;
|
|
1503
|
+
link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
|
|
1504
|
+
if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
|
|
1505
|
+
}).catch(() => void 0);
|
|
1506
|
+
}, [open, link]);
|
|
1507
|
+
const save = () => {
|
|
1508
|
+
for (const url of urls) try {
|
|
1509
|
+
const parsed = new URL(url);
|
|
1510
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
1511
|
+
} catch {
|
|
1512
|
+
setError("插件源地址需要以 http(s) 开头");
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
setError(void 0);
|
|
1516
|
+
link.call("settings.set", {
|
|
1517
|
+
key: PLUGINS_FEED_URLS_KEY,
|
|
1518
|
+
value: urls
|
|
1519
|
+
}).then((result) => {
|
|
1520
|
+
if (!result.ok) {
|
|
1521
|
+
setError(rpcErrorText(result.error));
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
props.onOpenChange(false);
|
|
1525
|
+
}).catch((cause) => setError(String(cause)));
|
|
1526
|
+
};
|
|
1527
|
+
const append = () => {
|
|
1528
|
+
const value = draft.trim();
|
|
1529
|
+
if (value === "") return;
|
|
1530
|
+
try {
|
|
1531
|
+
const parsed = new URL(value);
|
|
1532
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
1533
|
+
} catch {
|
|
1534
|
+
setError("请填写 http(s) 开头的插件源地址");
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
setError(void 0);
|
|
1538
|
+
setDraft("");
|
|
1539
|
+
setUrls((current) => current.includes(value) ? current : [...current, value]);
|
|
1540
|
+
};
|
|
1541
|
+
return jsx(Dialog, {
|
|
1542
|
+
open,
|
|
1543
|
+
onOpenChange: props.onOpenChange,
|
|
1544
|
+
children: jsxs(DialogContent, {
|
|
1545
|
+
presentation: "modal",
|
|
1546
|
+
"aria-describedby": void 0,
|
|
1547
|
+
children: [
|
|
1548
|
+
jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
|
|
1549
|
+
jsx(DialogBody, { children: jsxs(Stack, {
|
|
1550
|
+
gap: "sm",
|
|
1551
|
+
children: [
|
|
1552
|
+
urls.length === 0 && jsx("div", {
|
|
1553
|
+
style: {
|
|
1554
|
+
fontSize: "var(--snap-text-xs)",
|
|
1555
|
+
color: "var(--snap-color-muted)"
|
|
1556
|
+
},
|
|
1557
|
+
children: "尚未添加自定义源(当前使用出厂默认源)。"
|
|
1558
|
+
}),
|
|
1559
|
+
urls.map((url, index) => jsxs("div", {
|
|
1560
|
+
style: {
|
|
1561
|
+
display: "flex",
|
|
1562
|
+
gap: "var(--snap-space-sm)",
|
|
1563
|
+
alignItems: "center"
|
|
1564
|
+
},
|
|
1565
|
+
children: [jsx("span", {
|
|
1566
|
+
style: {
|
|
1567
|
+
flex: 1,
|
|
1568
|
+
minWidth: 0,
|
|
1569
|
+
overflow: "hidden",
|
|
1570
|
+
textOverflow: "ellipsis",
|
|
1571
|
+
whiteSpace: "nowrap",
|
|
1572
|
+
fontSize: "var(--snap-text-xs)"
|
|
1573
|
+
},
|
|
1574
|
+
children: url
|
|
1575
|
+
}), jsx(Button, {
|
|
1576
|
+
intent: "neutral",
|
|
1577
|
+
emphasis: "ghost",
|
|
1578
|
+
size: "sm",
|
|
1579
|
+
"aria-label": `移除 ${url}`,
|
|
1580
|
+
onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
|
|
1581
|
+
children: "✕"
|
|
1582
|
+
})]
|
|
1583
|
+
}, url)),
|
|
1584
|
+
jsxs("div", {
|
|
1585
|
+
style: {
|
|
1586
|
+
display: "flex",
|
|
1587
|
+
gap: "var(--snap-space-sm)",
|
|
1588
|
+
width: "100%"
|
|
1589
|
+
},
|
|
1590
|
+
children: [jsx(Input, {
|
|
1591
|
+
value: draft,
|
|
1592
|
+
placeholder: "https://…",
|
|
1593
|
+
style: {
|
|
1594
|
+
flex: 1,
|
|
1595
|
+
minWidth: 0
|
|
1596
|
+
},
|
|
1597
|
+
onChange: (event) => setDraft(event.target.value),
|
|
1598
|
+
onKeyDown: (event) => {
|
|
1599
|
+
if (event.key === "Enter") append();
|
|
1600
|
+
}
|
|
1601
|
+
}), jsx(Button, {
|
|
1602
|
+
intent: "neutral",
|
|
1603
|
+
emphasis: "outline",
|
|
1604
|
+
onClick: append,
|
|
1605
|
+
children: "添加源"
|
|
1606
|
+
})]
|
|
1607
|
+
}),
|
|
1608
|
+
error !== void 0 && jsx("div", {
|
|
1609
|
+
role: "alert",
|
|
1610
|
+
style: {
|
|
1611
|
+
color: "var(--snap-color-danger)",
|
|
1612
|
+
fontSize: "var(--snap-text-sm)"
|
|
1613
|
+
},
|
|
1614
|
+
children: error
|
|
1615
|
+
})
|
|
1616
|
+
]
|
|
1617
|
+
}) }),
|
|
1618
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
1619
|
+
intent: "neutral",
|
|
1620
|
+
emphasis: "outline",
|
|
1621
|
+
onClick: () => props.onOpenChange(false),
|
|
1622
|
+
children: "取消"
|
|
1623
|
+
}), jsx(Button, {
|
|
1624
|
+
intent: "primary",
|
|
1625
|
+
"data-plugins-feed-save": true,
|
|
1626
|
+
onClick: save,
|
|
1627
|
+
children: "保存"
|
|
1628
|
+
})] })
|
|
1629
|
+
]
|
|
1630
|
+
})
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
//#endregion
|
|
1634
|
+
//#region lib/types/settings-pages/plugins.js
|
|
1635
|
+
/** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
|
|
1636
|
+
* Electron or in tests. Inlined rather than imported from the app-internal
|
|
1637
|
+
* kernel package: it never ships in the installer, and the packaged-app gate
|
|
1638
|
+
* refuses any shipped `@snap-rail/ui` lib that requires it. */
|
|
1639
|
+
function droppedZipPath(file) {
|
|
1640
|
+
const zipPathOf = globalThis.snapRail?.zipPathOf;
|
|
1641
|
+
if (typeof zipPathOf !== "function") return null;
|
|
1642
|
+
return zipPathOf(file);
|
|
1643
|
+
}
|
|
1644
|
+
/** Human labels for the package kinds. */
|
|
1645
|
+
const KIND_LABELS = {
|
|
1646
|
+
skin: "界面风格",
|
|
1647
|
+
driver: "通讯驱动",
|
|
1648
|
+
suite: "业务套件",
|
|
1649
|
+
plugin: "插件"
|
|
1650
|
+
};
|
|
1651
|
+
const PROFILE_LABELS = {
|
|
1652
|
+
native: "皮肤原生",
|
|
1653
|
+
integrated: "图表桥接",
|
|
1654
|
+
custom: "自定义界面"
|
|
1655
|
+
};
|
|
1656
|
+
/** Search rows shown before the tail is folded into a counter. */
|
|
1657
|
+
const SEARCH_ROW_CAP = 20;
|
|
1658
|
+
/** The plus glyph for the page's install entry. */
|
|
1659
|
+
function PlusIcon() {
|
|
1660
|
+
return jsx("svg", {
|
|
1661
|
+
viewBox: "0 0 24 24",
|
|
1662
|
+
width: "18",
|
|
1663
|
+
height: "18",
|
|
1664
|
+
fill: "none",
|
|
1665
|
+
stroke: "currentColor",
|
|
1666
|
+
strokeWidth: "2.4",
|
|
1667
|
+
strokeLinecap: "round",
|
|
1668
|
+
"aria-hidden": "true",
|
|
1669
|
+
children: jsx("path", { d: "M12 5v14M5 12h14" })
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
/** Collapse entry rows into package rows (one master switch per package). */
|
|
1673
|
+
function packageRows(plugins) {
|
|
1674
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
1675
|
+
for (const plugin of plugins) {
|
|
1676
|
+
if (plugin.source === "builtin") continue;
|
|
1677
|
+
const existing = byPackage.get(plugin.packageName);
|
|
1678
|
+
if (existing !== void 0) {
|
|
1679
|
+
existing.enabled = existing.enabled || plugin.enabled;
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
byPackage.set(plugin.packageName, {
|
|
1683
|
+
packageName: plugin.packageName,
|
|
1684
|
+
title: plugin.title ?? plugin.packageName,
|
|
1685
|
+
category: plugin.category ?? "其他",
|
|
1686
|
+
kind: plugin.kind ?? "plugin",
|
|
1687
|
+
...plugin.version !== void 0 ? { version: plugin.version } : {},
|
|
1688
|
+
enabled: plugin.enabled,
|
|
1689
|
+
source: plugin.source,
|
|
1690
|
+
builtinDefault: plugin.source === "builtin-default",
|
|
1691
|
+
clientOnly: plugin.clientOnly === true,
|
|
1692
|
+
...plugin.uiProfile !== void 0 ? { uiProfile: plugin.uiProfile } : {}
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
1696
|
+
}
|
|
1697
|
+
/** The preview's signature line (one row in the confirm card). */
|
|
1698
|
+
function signatureText(signature, viaUrl) {
|
|
1699
|
+
if (signature.state === "verified") return {
|
|
1700
|
+
text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
|
|
1701
|
+
warning: false
|
|
1702
|
+
};
|
|
1703
|
+
const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
|
|
1704
|
+
return {
|
|
1705
|
+
text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
|
|
1706
|
+
warning: true
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
/** Does the input name an http(s) address? */
|
|
1710
|
+
const isHttpUrl = (text) => /^https?:\/\//i.test(text);
|
|
1711
|
+
/** Does the input look like a filesystem path (drive letter, UNC, posix
|
|
1712
|
+
* root, or a .zip name with a separator in it)? */
|
|
1713
|
+
const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
|
|
1714
|
+
/** The plugin management page. */
|
|
1715
|
+
function PluginsPage({ ctx }) {
|
|
1716
|
+
const [rows, setRows] = useState([]);
|
|
1717
|
+
const [error, setError] = useState(void 0);
|
|
1718
|
+
const [busy, setBusy] = useState(void 0);
|
|
1719
|
+
const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
|
|
1720
|
+
const [restartNeeded, setRestartNeeded] = useState(false);
|
|
1721
|
+
const [installOpen, setInstallOpen] = useState(false);
|
|
1722
|
+
const [phase, setPhase] = useState({ kind: "idle" });
|
|
1723
|
+
const [message, setMessage] = useState(void 0);
|
|
1724
|
+
const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
|
|
1725
|
+
const [updatingName, setUpdatingName] = useState(void 0);
|
|
1726
|
+
const [keyChange, setKeyChange] = useState(void 0);
|
|
1727
|
+
const [query, setQuery] = useState("");
|
|
1728
|
+
const [searchResults, setSearchResults] = useState(void 0);
|
|
1729
|
+
const [searching, setSearching] = useState(false);
|
|
1730
|
+
const [dragging, setDragging] = useState(false);
|
|
1731
|
+
const link = ctx.client.link;
|
|
1732
|
+
const load = () => {
|
|
1733
|
+
setError(void 0);
|
|
1734
|
+
link.call("plugins.list", {}).then((result) => {
|
|
1735
|
+
if (!result.ok) {
|
|
1736
|
+
setError(rpcErrorText(result.error));
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
setRows(packageRows(result.value.plugins));
|
|
1740
|
+
}).catch((cause) => {
|
|
1741
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1742
|
+
});
|
|
1743
|
+
link.call("plugins.updates-check", {}).then((result) => {
|
|
1744
|
+
if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
|
|
1745
|
+
}).catch(() => void 0);
|
|
1746
|
+
};
|
|
1747
|
+
useEffect(() => {
|
|
1748
|
+
load();
|
|
1749
|
+
}, [link]);
|
|
1750
|
+
const openInstall = () => {
|
|
1751
|
+
setQuery("");
|
|
1752
|
+
setSearchResults(void 0);
|
|
1753
|
+
setMessage(void 0);
|
|
1754
|
+
setDragging(false);
|
|
1755
|
+
setInstallOpen(true);
|
|
1756
|
+
};
|
|
1757
|
+
const closeInstall = () => {
|
|
1758
|
+
setInstallOpen(false);
|
|
1759
|
+
setQuery("");
|
|
1760
|
+
setSearchResults(void 0);
|
|
1761
|
+
setMessage(void 0);
|
|
1762
|
+
setDragging(false);
|
|
1763
|
+
};
|
|
1764
|
+
const toggle = (row, enabled) => {
|
|
1765
|
+
setBusy(row.packageName);
|
|
1766
|
+
link.call("plugins.set-enabled", {
|
|
1767
|
+
name: row.packageName,
|
|
1768
|
+
enabled
|
|
1769
|
+
}).then((result) => {
|
|
1770
|
+
if (!result.ok) {
|
|
1771
|
+
setError(rpcErrorText(result.error));
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
setRows((current) => current.map((item) => item.packageName === row.packageName ? {
|
|
1775
|
+
...item,
|
|
1776
|
+
enabled
|
|
1777
|
+
} : item));
|
|
1778
|
+
setTouched((current) => new Set(current).add(row.packageName));
|
|
1779
|
+
}).catch((cause) => {
|
|
1780
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1781
|
+
}).finally(() => {
|
|
1782
|
+
setBusy(void 0);
|
|
1783
|
+
});
|
|
1784
|
+
};
|
|
1785
|
+
const uninstall = (row) => {
|
|
1786
|
+
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
|
|
1787
|
+
setBusy(row.packageName);
|
|
1788
|
+
link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
|
|
1789
|
+
if (!result.ok) {
|
|
1790
|
+
setError(rpcErrorText(result.error));
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
setTouched((current) => new Set(current).add(row.packageName));
|
|
1794
|
+
setRestartNeeded(true);
|
|
1795
|
+
load();
|
|
1796
|
+
}).catch((cause) => {
|
|
1797
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1798
|
+
}).finally(() => {
|
|
1799
|
+
setBusy(void 0);
|
|
1800
|
+
});
|
|
1801
|
+
};
|
|
1802
|
+
const inspectPath = (zipPath) => {
|
|
1803
|
+
setMessage(void 0);
|
|
1804
|
+
link.call("plugins.inspect", { zipPath }).then((result) => {
|
|
1805
|
+
if (!result.ok) {
|
|
1806
|
+
setPhase({
|
|
1807
|
+
kind: "error",
|
|
1808
|
+
message: `读取插件包失败:${rpcErrorText(result.error)}`
|
|
1809
|
+
});
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
setPhase({
|
|
1813
|
+
kind: "confirm",
|
|
1814
|
+
zipPath,
|
|
1815
|
+
archive: result.value.archive,
|
|
1816
|
+
viaUrl: false,
|
|
1817
|
+
risk: false
|
|
1818
|
+
});
|
|
1819
|
+
}).catch((cause) => setPhase({
|
|
1820
|
+
kind: "error",
|
|
1821
|
+
message: String(cause)
|
|
1822
|
+
}));
|
|
1823
|
+
};
|
|
1824
|
+
const inspectFromUrl = (url) => {
|
|
1825
|
+
setMessage(void 0);
|
|
1826
|
+
link.call("plugins.inspect-from-url", { url }).then((result) => {
|
|
1827
|
+
if (!result.ok) {
|
|
1828
|
+
setPhase({
|
|
1829
|
+
kind: "error",
|
|
1830
|
+
message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
|
|
1831
|
+
});
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
setPhase({
|
|
1835
|
+
kind: "confirm",
|
|
1836
|
+
zipPath: result.value.zipPath,
|
|
1837
|
+
archive: result.value.archive,
|
|
1838
|
+
viaUrl: true,
|
|
1839
|
+
risk: false
|
|
1840
|
+
});
|
|
1841
|
+
}).catch((cause) => setPhase({
|
|
1842
|
+
kind: "error",
|
|
1843
|
+
message: String(cause)
|
|
1844
|
+
}));
|
|
1845
|
+
};
|
|
1846
|
+
const runInstall = (zipPath, archive) => {
|
|
1847
|
+
setPhase({ kind: "installing" });
|
|
1848
|
+
(archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
|
|
1849
|
+
if (!result.ok) {
|
|
1850
|
+
setPhase({
|
|
1851
|
+
kind: "error",
|
|
1852
|
+
message: `安装失败:${rpcErrorText(result.error)}`
|
|
1853
|
+
});
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1856
|
+
setPhase({ kind: "idle" });
|
|
1857
|
+
closeInstall();
|
|
1858
|
+
setRestartNeeded(true);
|
|
1859
|
+
load();
|
|
1860
|
+
}).catch((cause) => setPhase({
|
|
1861
|
+
kind: "error",
|
|
1862
|
+
message: String(cause)
|
|
1863
|
+
}));
|
|
1864
|
+
};
|
|
1865
|
+
/** The update pill's click: a plain update installs directly; a key
|
|
1866
|
+
* change confirmation intercepts first. */
|
|
1867
|
+
const requestUpdate = (update) => {
|
|
1868
|
+
if (update.keyChanged === true) {
|
|
1869
|
+
setKeyChange(update);
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1872
|
+
updateNow(update.name);
|
|
1873
|
+
};
|
|
1874
|
+
/** The update itself: the feed's entry, no preview. */
|
|
1875
|
+
const updateNow = (name) => {
|
|
1876
|
+
setKeyChange(void 0);
|
|
1877
|
+
setUpdatingName(name);
|
|
1878
|
+
setMessage(void 0);
|
|
1879
|
+
link.call("plugins.remote-install", { name }).then((result) => {
|
|
1880
|
+
setUpdatingName(void 0);
|
|
1881
|
+
if (!result.ok) {
|
|
1882
|
+
setMessage({
|
|
1883
|
+
kind: "error",
|
|
1884
|
+
text: rpcErrorText(result.error)
|
|
1885
|
+
});
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
setRestartNeeded(true);
|
|
1889
|
+
load();
|
|
1890
|
+
}).catch(() => setUpdatingName(void 0));
|
|
1891
|
+
};
|
|
1892
|
+
/** The tri-form input: address/path → inspect, anything else → feed search. */
|
|
1893
|
+
const submitQuery = () => {
|
|
1894
|
+
const text = query.trim();
|
|
1895
|
+
if (text === "") return;
|
|
1896
|
+
setMessage(void 0);
|
|
1897
|
+
if (isHttpUrl(text)) {
|
|
1898
|
+
inspectFromUrl(text);
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
if (looksLikePath(text)) {
|
|
1902
|
+
inspectPath(text);
|
|
1903
|
+
return;
|
|
1904
|
+
}
|
|
1905
|
+
runSearch(text);
|
|
1906
|
+
};
|
|
1907
|
+
const runSearch = (text) => {
|
|
1908
|
+
setSearching(true);
|
|
1909
|
+
setSearchResults(void 0);
|
|
1910
|
+
link.call("plugins.remote-list", {}).then((result) => {
|
|
1911
|
+
setSearching(false);
|
|
1912
|
+
if (!result.ok) {
|
|
1913
|
+
setMessage({
|
|
1914
|
+
kind: "error",
|
|
1915
|
+
text: `搜索失败:${rpcErrorText(result.error)}`
|
|
1916
|
+
});
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
const needle = text.toLowerCase();
|
|
1920
|
+
setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
|
|
1921
|
+
}).catch((cause) => {
|
|
1922
|
+
setSearching(false);
|
|
1923
|
+
setMessage({
|
|
1924
|
+
kind: "error",
|
|
1925
|
+
text: String(cause)
|
|
1926
|
+
});
|
|
1927
|
+
});
|
|
1928
|
+
};
|
|
1929
|
+
/** A search-result entry that is not installed yet: preview first. The
|
|
1930
|
+
* entry's own coordinates decide where the zip comes from — a federation
|
|
1931
|
+
* row downloads from the author's release, a same-directory row from its
|
|
1932
|
+
* feed base. */
|
|
1933
|
+
const previewRemote = (item) => {
|
|
1934
|
+
if (item.url !== void 0) {
|
|
1935
|
+
inspectFromUrl(item.url);
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
if (item.feedUrl === void 0 || item.file === void 0) return;
|
|
1939
|
+
const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
|
|
1940
|
+
inspectFromUrl(`${base}${item.file}`);
|
|
1941
|
+
};
|
|
1942
|
+
const onDrop = (event) => {
|
|
1943
|
+
event.preventDefault();
|
|
1944
|
+
setDragging(false);
|
|
1945
|
+
const file = event.dataTransfer.files[0];
|
|
1946
|
+
if (file === void 0) return;
|
|
1947
|
+
if (!file.name.toLowerCase().endsWith(".zip")) {
|
|
1948
|
+
setMessage({
|
|
1949
|
+
kind: "error",
|
|
1950
|
+
text: "只支持 .zip 插件包或组合包"
|
|
1951
|
+
});
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
const zipPath = droppedZipPath(file);
|
|
1955
|
+
if (zipPath === null) {
|
|
1956
|
+
setMessage({
|
|
1957
|
+
kind: "error",
|
|
1958
|
+
text: "当前环境不支持拖拽安装(缺少路径桥)"
|
|
1959
|
+
});
|
|
1960
|
+
return;
|
|
1961
|
+
}
|
|
1962
|
+
inspectPath(zipPath);
|
|
1963
|
+
};
|
|
1964
|
+
const restart = () => {
|
|
1965
|
+
link.call("window.relaunch", {});
|
|
1966
|
+
};
|
|
1967
|
+
const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
|
|
1968
|
+
const spans = /* @__PURE__ */ new Map();
|
|
1969
|
+
for (let index = 0; index < rows.length;) {
|
|
1970
|
+
const category = rows[index].category;
|
|
1971
|
+
let end = index + 1;
|
|
1972
|
+
while (end < rows.length && rows[end].category === category) end += 1;
|
|
1973
|
+
spans.set(index, end - index);
|
|
1974
|
+
index = end;
|
|
1975
|
+
}
|
|
1976
|
+
return jsxs(Page, {
|
|
1977
|
+
title: "插件管理",
|
|
1978
|
+
titleExtra: jsx(IconButton, {
|
|
1979
|
+
icon: jsx(PlusIcon, {}),
|
|
1980
|
+
label: "安装插件",
|
|
1981
|
+
onClick: openInstall
|
|
1982
|
+
}),
|
|
1983
|
+
actions: restartNeeded ? jsx(Button, {
|
|
1984
|
+
intent: "primary",
|
|
1985
|
+
onClick: restart,
|
|
1986
|
+
children: "重启生效"
|
|
1987
|
+
}) : void 0,
|
|
1988
|
+
children: [
|
|
1989
|
+
jsxs(Stack, {
|
|
1990
|
+
gap: "lg",
|
|
1991
|
+
children: [error !== void 0 && jsx("div", {
|
|
1992
|
+
role: "alert",
|
|
1993
|
+
style: { color: "var(--snap-color-danger)" },
|
|
1994
|
+
children: error
|
|
1995
|
+
}), rows.length === 0 ? jsx(EmptyState, {
|
|
1996
|
+
title: "还没有安装插件",
|
|
1997
|
+
action: jsx(Button, {
|
|
1998
|
+
intent: "primary",
|
|
1999
|
+
onClick: openInstall,
|
|
2000
|
+
children: "安装插件"
|
|
2001
|
+
})
|
|
2002
|
+
}) : jsxs(Table, {
|
|
2003
|
+
"data-plugins-table": true,
|
|
2004
|
+
children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
|
|
2005
|
+
jsx(TableHead, {
|
|
2006
|
+
style: { width: "6em" },
|
|
2007
|
+
children: "分类"
|
|
2008
|
+
}),
|
|
2009
|
+
jsx(TableHead, { children: "名称" }),
|
|
2010
|
+
jsx(TableHead, { children: "类型" }),
|
|
2011
|
+
jsx(TableHead, { children: "版本" }),
|
|
2012
|
+
jsx(TableHead, { children: "状态" }),
|
|
2013
|
+
jsx(TableHead, { children: "操作" })
|
|
2014
|
+
] }) }), jsx(TableBody, { children: rows.map((row, index) => {
|
|
2015
|
+
const update = updates.get(row.packageName);
|
|
2016
|
+
const span = spans.get(index);
|
|
2017
|
+
return jsxs(TableRow, { children: [
|
|
2018
|
+
span !== void 0 && jsx(TableCell, {
|
|
2019
|
+
rowSpan: span,
|
|
2020
|
+
style: {
|
|
2021
|
+
verticalAlign: "middle",
|
|
2022
|
+
color: "var(--snap-color-muted)",
|
|
2023
|
+
fontWeight: 600
|
|
2024
|
+
},
|
|
2025
|
+
children: row.category
|
|
2026
|
+
}),
|
|
2027
|
+
jsx(TableCell, { children: jsxs("div", {
|
|
2028
|
+
style: {
|
|
2029
|
+
display: "flex",
|
|
2030
|
+
flexDirection: "column"
|
|
2031
|
+
},
|
|
2032
|
+
children: [jsxs("span", {
|
|
2033
|
+
style: {
|
|
2034
|
+
display: "flex",
|
|
2035
|
+
alignItems: "center",
|
|
2036
|
+
gap: "var(--snap-space-sm)"
|
|
2037
|
+
},
|
|
2038
|
+
children: [row.title, row.builtinDefault && jsx(Badge, {
|
|
2039
|
+
intent: "neutral",
|
|
2040
|
+
children: "内置默认"
|
|
2041
|
+
})]
|
|
2042
|
+
}), jsx("span", {
|
|
2043
|
+
style: {
|
|
2044
|
+
color: "var(--snap-color-muted)",
|
|
2045
|
+
fontSize: "var(--snap-text-xs)"
|
|
2046
|
+
},
|
|
2047
|
+
children: row.packageName
|
|
2048
|
+
})]
|
|
2049
|
+
}) }),
|
|
2050
|
+
jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
|
|
2051
|
+
intent: "neutral",
|
|
2052
|
+
children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
|
|
2053
|
+
})] }),
|
|
2054
|
+
jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
|
|
2055
|
+
intent: "primary",
|
|
2056
|
+
emphasis: "ghost",
|
|
2057
|
+
size: "sm",
|
|
2058
|
+
title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
|
|
2059
|
+
disabled: updatingName === row.packageName,
|
|
2060
|
+
onClick: () => requestUpdate(update),
|
|
2061
|
+
children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
|
|
2062
|
+
}) : row.version ?? "—" }),
|
|
2063
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
|
|
2064
|
+
checked: true,
|
|
2065
|
+
disabled: true,
|
|
2066
|
+
"aria-label": `启用 ${row.title}`
|
|
2067
|
+
}) : jsxs("div", {
|
|
2068
|
+
style: {
|
|
2069
|
+
display: "flex",
|
|
2070
|
+
alignItems: "center",
|
|
2071
|
+
gap: "var(--snap-space-sm)"
|
|
2072
|
+
},
|
|
2073
|
+
children: [jsx(Switch, {
|
|
2074
|
+
checked: row.enabled,
|
|
2075
|
+
disabled: busy === row.packageName,
|
|
2076
|
+
onCheckedChange: (next) => toggle(row, next),
|
|
2077
|
+
"aria-label": `启用 ${row.title}`
|
|
2078
|
+
}), touched.has(row.packageName) && jsx(Badge, {
|
|
2079
|
+
intent: "warning",
|
|
2080
|
+
children: "待重启"
|
|
2081
|
+
})]
|
|
2082
|
+
}) }),
|
|
2083
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
|
|
2084
|
+
style: { color: "var(--snap-color-muted)" },
|
|
2085
|
+
children: "内置默认不可卸载"
|
|
2086
|
+
}) : jsx(Button, {
|
|
2087
|
+
intent: "danger",
|
|
2088
|
+
emphasis: "ghost",
|
|
2089
|
+
size: "sm",
|
|
2090
|
+
disabled: busy === row.packageName,
|
|
2091
|
+
onClick: () => uninstall(row),
|
|
2092
|
+
children: "卸载"
|
|
2093
|
+
}) })
|
|
2094
|
+
] }, row.packageName);
|
|
2095
|
+
}) })]
|
|
2096
|
+
})]
|
|
2097
|
+
}),
|
|
2098
|
+
jsx(Dialog, {
|
|
2099
|
+
open: installOpen,
|
|
2100
|
+
onOpenChange: (next) => {
|
|
2101
|
+
if (!next) closeInstall();
|
|
2102
|
+
},
|
|
2103
|
+
children: jsxs(DialogContent, {
|
|
2104
|
+
presentation: "modal",
|
|
2105
|
+
size: "lg",
|
|
2106
|
+
"data-plugins-dropzone": true,
|
|
2107
|
+
"aria-describedby": void 0,
|
|
2108
|
+
onDragOver: (event) => {
|
|
2109
|
+
event.preventDefault();
|
|
2110
|
+
setDragging(true);
|
|
2111
|
+
},
|
|
2112
|
+
onDragLeave: (event) => {
|
|
2113
|
+
if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
|
|
2114
|
+
},
|
|
2115
|
+
onDrop,
|
|
2116
|
+
children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
|
|
2117
|
+
gap: "sm",
|
|
2118
|
+
children: [
|
|
2119
|
+
jsx("div", {
|
|
2120
|
+
"data-plugins-drop-hint": true,
|
|
2121
|
+
style: {
|
|
2122
|
+
height: "calc(var(--snap-control-height-md) * 3)",
|
|
2123
|
+
display: "flex",
|
|
2124
|
+
alignItems: "center",
|
|
2125
|
+
justifyContent: "center",
|
|
2126
|
+
border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
|
|
2127
|
+
borderRadius: "var(--snap-radius-md)",
|
|
2128
|
+
background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
|
|
2129
|
+
color: "var(--snap-color-muted)",
|
|
2130
|
+
fontSize: "var(--snap-text-sm)"
|
|
2131
|
+
},
|
|
2132
|
+
children: dragging ? "释放以安装" : "拖入 .zip 安装"
|
|
2133
|
+
}),
|
|
2134
|
+
jsxs("div", {
|
|
2135
|
+
style: {
|
|
2136
|
+
display: "flex",
|
|
2137
|
+
gap: "var(--snap-space-sm)"
|
|
2138
|
+
},
|
|
2139
|
+
children: [jsx(Input, {
|
|
2140
|
+
value: query,
|
|
2141
|
+
placeholder: "本地路径 / https://… / 插件名",
|
|
2142
|
+
style: {
|
|
2143
|
+
flex: 1,
|
|
2144
|
+
minWidth: 0
|
|
2145
|
+
},
|
|
2146
|
+
onChange: (event) => setQuery(event.target.value),
|
|
2147
|
+
onKeyDown: (event) => {
|
|
2148
|
+
if (event.key === "Enter") submitQuery();
|
|
2149
|
+
}
|
|
2150
|
+
}), jsx(Button, {
|
|
2151
|
+
intent: "neutral",
|
|
2152
|
+
emphasis: "outline",
|
|
2153
|
+
disabled: searching,
|
|
2154
|
+
onClick: submitQuery,
|
|
2155
|
+
children: searching ? "搜索中…" : "搜索"
|
|
2156
|
+
})]
|
|
2157
|
+
}),
|
|
2158
|
+
message !== void 0 && jsx("div", {
|
|
2159
|
+
role: message.kind === "error" ? "alert" : "status",
|
|
2160
|
+
style: {
|
|
2161
|
+
fontSize: "var(--snap-text-xs)",
|
|
2162
|
+
color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
|
|
2163
|
+
},
|
|
2164
|
+
children: message.text
|
|
2165
|
+
}),
|
|
2166
|
+
visibleResults !== void 0 && jsxs(Stack, {
|
|
2167
|
+
gap: "sm",
|
|
2168
|
+
children: [
|
|
2169
|
+
jsxs("div", {
|
|
2170
|
+
style: {
|
|
2171
|
+
display: "flex",
|
|
2172
|
+
justifyContent: "space-between",
|
|
2173
|
+
alignItems: "center"
|
|
2174
|
+
},
|
|
2175
|
+
children: [jsxs("span", {
|
|
2176
|
+
style: {
|
|
2177
|
+
fontSize: "var(--snap-text-sm)",
|
|
2178
|
+
color: "var(--snap-color-muted)"
|
|
2179
|
+
},
|
|
2180
|
+
children: [
|
|
2181
|
+
"搜索“",
|
|
2182
|
+
query.trim(),
|
|
2183
|
+
"”(",
|
|
2184
|
+
searchResults?.length ?? 0,
|
|
2185
|
+
")"
|
|
2186
|
+
]
|
|
2187
|
+
}), jsx(Button, {
|
|
2188
|
+
intent: "neutral",
|
|
2189
|
+
emphasis: "ghost",
|
|
2190
|
+
size: "sm",
|
|
2191
|
+
onClick: () => setSearchResults(void 0),
|
|
2192
|
+
children: "✕"
|
|
2193
|
+
})]
|
|
2194
|
+
}),
|
|
2195
|
+
visibleResults.length === 0 && jsx("div", {
|
|
2196
|
+
style: {
|
|
2197
|
+
padding: "12px 0",
|
|
2198
|
+
textAlign: "center",
|
|
2199
|
+
color: "var(--snap-color-muted)",
|
|
2200
|
+
fontSize: "var(--snap-text-sm)"
|
|
2201
|
+
},
|
|
2202
|
+
children: "没有匹配的插件。"
|
|
2203
|
+
}),
|
|
2204
|
+
visibleResults.map((item) => {
|
|
2205
|
+
const installed = item.installed !== void 0;
|
|
2206
|
+
return jsxs("div", {
|
|
2207
|
+
style: {
|
|
2208
|
+
display: "flex",
|
|
2209
|
+
gap: "var(--snap-space-md)",
|
|
2210
|
+
alignItems: "center",
|
|
2211
|
+
justifyContent: "space-between",
|
|
2212
|
+
borderBottom: "1px solid var(--snap-color-border)",
|
|
2213
|
+
paddingBottom: "var(--snap-space-sm)"
|
|
2214
|
+
},
|
|
2215
|
+
children: [jsxs("div", {
|
|
2216
|
+
style: { minWidth: 0 },
|
|
2217
|
+
children: [jsxs("div", {
|
|
2218
|
+
style: {
|
|
2219
|
+
display: "flex",
|
|
2220
|
+
gap: "var(--snap-space-sm)",
|
|
2221
|
+
alignItems: "center"
|
|
2222
|
+
},
|
|
2223
|
+
children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
|
|
2224
|
+
intent: "neutral",
|
|
2225
|
+
children: item.source
|
|
2226
|
+
})]
|
|
2227
|
+
}), jsxs("div", {
|
|
2228
|
+
style: {
|
|
2229
|
+
fontSize: "var(--snap-text-xs)",
|
|
2230
|
+
color: "var(--snap-color-muted)"
|
|
2231
|
+
},
|
|
2232
|
+
children: [
|
|
2233
|
+
item.name,
|
|
2234
|
+
" · ",
|
|
2235
|
+
item.version
|
|
2236
|
+
]
|
|
2237
|
+
})]
|
|
2238
|
+
}), item.action === "install" ? jsx(Button, {
|
|
2239
|
+
intent: "primary",
|
|
2240
|
+
emphasis: "outline",
|
|
2241
|
+
size: "sm",
|
|
2242
|
+
onClick: () => previewRemote(item),
|
|
2243
|
+
children: "安装"
|
|
2244
|
+
}) : item.action === "update" && installed ? jsx(Button, {
|
|
2245
|
+
intent: "primary",
|
|
2246
|
+
emphasis: "ghost",
|
|
2247
|
+
size: "sm",
|
|
2248
|
+
title: `当前 ${item.installed?.version} → ${item.version}`,
|
|
2249
|
+
disabled: updatingName === item.name,
|
|
2250
|
+
onClick: () => requestUpdate({
|
|
2251
|
+
name: item.name,
|
|
2252
|
+
installedVersion: item.installed?.version ?? "",
|
|
2253
|
+
feedVersion: item.version
|
|
2254
|
+
}),
|
|
2255
|
+
children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
|
|
2256
|
+
}) : jsx("span", {
|
|
2257
|
+
style: {
|
|
2258
|
+
fontSize: "var(--snap-text-xs)",
|
|
2259
|
+
color: "var(--snap-color-muted)"
|
|
2260
|
+
},
|
|
2261
|
+
children: item.action === "current" ? "已是最新" : "本地更新"
|
|
2262
|
+
})]
|
|
2263
|
+
}, item.name);
|
|
2264
|
+
}),
|
|
2265
|
+
(searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
|
|
2266
|
+
style: {
|
|
2267
|
+
fontSize: "var(--snap-text-xs)",
|
|
2268
|
+
color: "var(--snap-color-muted)"
|
|
2269
|
+
},
|
|
2270
|
+
children: [
|
|
2271
|
+
"已显示前 ",
|
|
2272
|
+
SEARCH_ROW_CAP,
|
|
2273
|
+
" 条,共 ",
|
|
2274
|
+
searchResults?.length,
|
|
2275
|
+
" 条。"
|
|
2276
|
+
]
|
|
2277
|
+
})
|
|
2278
|
+
]
|
|
2279
|
+
})
|
|
2280
|
+
]
|
|
2281
|
+
}) })]
|
|
2282
|
+
})
|
|
2283
|
+
}),
|
|
2284
|
+
jsx(Dialog, {
|
|
2285
|
+
open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
|
|
2286
|
+
onOpenChange: (next) => {
|
|
2287
|
+
if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
|
|
2288
|
+
},
|
|
2289
|
+
children: jsxs(DialogContent, {
|
|
2290
|
+
presentation: "modal",
|
|
2291
|
+
"aria-describedby": void 0,
|
|
2292
|
+
children: [
|
|
2293
|
+
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}` })] }),
|
|
2294
|
+
jsxs(DialogBody, { children: [
|
|
2295
|
+
phase.kind === "error" && jsx("div", {
|
|
2296
|
+
style: {
|
|
2297
|
+
color: "var(--snap-color-danger)",
|
|
2298
|
+
whiteSpace: "pre-wrap",
|
|
2299
|
+
fontSize: "var(--snap-text-sm)"
|
|
2300
|
+
},
|
|
2301
|
+
children: phase.message
|
|
2302
|
+
}),
|
|
2303
|
+
phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
|
|
2304
|
+
gap: "sm",
|
|
2305
|
+
children: [
|
|
2306
|
+
phase.archive.combo.description !== void 0 && jsx("div", {
|
|
2307
|
+
style: {
|
|
2308
|
+
color: "var(--snap-color-muted)",
|
|
2309
|
+
fontSize: "var(--snap-text-sm)"
|
|
2310
|
+
},
|
|
2311
|
+
children: phase.archive.combo.description
|
|
2312
|
+
}),
|
|
2313
|
+
jsxs("div", {
|
|
2314
|
+
style: {
|
|
2315
|
+
display: "grid",
|
|
2316
|
+
gap: "var(--snap-space-xs)",
|
|
2317
|
+
fontSize: "var(--snap-text-sm)"
|
|
2318
|
+
},
|
|
2319
|
+
children: [jsxs("div", { children: [
|
|
2320
|
+
"插件(",
|
|
2321
|
+
phase.archive.combo.plugins.length,
|
|
2322
|
+
")"
|
|
2323
|
+
] }), phase.archive.combo.plugins.map((plugin) => {
|
|
2324
|
+
const line = signatureText(plugin.signature, phase.viaUrl);
|
|
2325
|
+
const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
|
|
2326
|
+
return jsxs("div", {
|
|
2327
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
2328
|
+
children: [
|
|
2329
|
+
plugin.title ?? plugin.name,
|
|
2330
|
+
" ",
|
|
2331
|
+
plugin.version,
|
|
2332
|
+
" · ",
|
|
2333
|
+
action,
|
|
2334
|
+
line.warning ? " · ⚠ 未验证" : ""
|
|
2335
|
+
]
|
|
2336
|
+
}, plugin.name);
|
|
2337
|
+
})]
|
|
2338
|
+
}),
|
|
2339
|
+
phase.archive.combo.missing.length > 0 && jsxs("div", {
|
|
2340
|
+
style: {
|
|
2341
|
+
color: "var(--snap-color-danger)",
|
|
2342
|
+
fontSize: "var(--snap-text-sm)"
|
|
2343
|
+
},
|
|
2344
|
+
children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
|
|
2345
|
+
})
|
|
2346
|
+
]
|
|
2347
|
+
}),
|
|
2348
|
+
phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
|
|
2349
|
+
gap: "sm",
|
|
2350
|
+
children: [
|
|
2351
|
+
phase.risk ? jsx("div", {
|
|
2352
|
+
"data-plugins-risk": true,
|
|
2353
|
+
style: {
|
|
2354
|
+
color: "var(--snap-color-warning)",
|
|
2355
|
+
fontWeight: 600
|
|
2356
|
+
},
|
|
2357
|
+
children: "⚠ 此插件未经发布者验证"
|
|
2358
|
+
}) : void 0,
|
|
2359
|
+
!phase.risk && jsxs(Stack, {
|
|
2360
|
+
gap: "sm",
|
|
2361
|
+
children: [
|
|
2362
|
+
phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
|
|
2363
|
+
jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
|
|
2364
|
+
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] })
|
|
2365
|
+
]
|
|
2366
|
+
}),
|
|
2367
|
+
(() => {
|
|
2368
|
+
const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
|
|
2369
|
+
return jsxs("div", {
|
|
2370
|
+
"data-plugins-signature": phase.archive.plugin.signature.state,
|
|
2371
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
2372
|
+
children: ["签名:", line.text]
|
|
2373
|
+
});
|
|
2374
|
+
})(),
|
|
2375
|
+
!phase.risk && jsxs(Stack, {
|
|
2376
|
+
gap: "sm",
|
|
2377
|
+
children: [
|
|
2378
|
+
jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
|
|
2379
|
+
phase.archive.plugin.missing.length > 0 && jsxs("div", {
|
|
2380
|
+
style: {
|
|
2381
|
+
color: "var(--snap-color-danger)",
|
|
2382
|
+
fontSize: "var(--snap-text-sm)"
|
|
2383
|
+
},
|
|
2384
|
+
children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
|
|
2385
|
+
}),
|
|
2386
|
+
phase.archive.plugin.action === "blocked" && jsxs("div", {
|
|
2387
|
+
style: {
|
|
2388
|
+
color: "var(--snap-color-danger)",
|
|
2389
|
+
fontSize: "var(--snap-text-sm)"
|
|
2390
|
+
},
|
|
2391
|
+
children: [
|
|
2392
|
+
"已安装 v",
|
|
2393
|
+
phase.archive.plugin.installed?.version,
|
|
2394
|
+
",安装包 v",
|
|
2395
|
+
phase.archive.plugin.version,
|
|
2396
|
+
" 不高于已装版本,无法覆盖。"
|
|
2397
|
+
]
|
|
2398
|
+
})
|
|
2399
|
+
]
|
|
2400
|
+
}),
|
|
2401
|
+
phase.risk && jsx("div", {
|
|
2402
|
+
style: {
|
|
2403
|
+
color: "var(--snap-color-muted)",
|
|
2404
|
+
fontSize: "var(--snap-text-sm)"
|
|
2405
|
+
},
|
|
2406
|
+
children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
|
|
2407
|
+
})
|
|
2408
|
+
]
|
|
2409
|
+
})
|
|
2410
|
+
] }),
|
|
2411
|
+
jsxs(DialogFooter, { children: [
|
|
2412
|
+
phase.kind === "error" && jsx(Button, {
|
|
2413
|
+
intent: "neutral",
|
|
2414
|
+
emphasis: "outline",
|
|
2415
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
2416
|
+
children: "返回"
|
|
2417
|
+
}),
|
|
2418
|
+
phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
|
|
2419
|
+
intent: "neutral",
|
|
2420
|
+
emphasis: "outline",
|
|
2421
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
2422
|
+
children: "取消"
|
|
2423
|
+
}), phase.risk ? jsx(Button, {
|
|
2424
|
+
intent: "primary",
|
|
2425
|
+
"data-plugins-risk-confirm": true,
|
|
2426
|
+
onClick: () => runInstall(phase.zipPath, phase.archive),
|
|
2427
|
+
children: "我知晓风险,仍要安装"
|
|
2428
|
+
}) : jsx(Button, {
|
|
2429
|
+
intent: "primary",
|
|
2430
|
+
"data-plugins-install-confirm": true,
|
|
2431
|
+
disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
|
|
2432
|
+
onClick: () => {
|
|
2433
|
+
if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
|
|
2434
|
+
setPhase({
|
|
2435
|
+
...phase,
|
|
2436
|
+
risk: true
|
|
2437
|
+
});
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
runInstall(phase.zipPath, phase.archive);
|
|
2441
|
+
},
|
|
2442
|
+
children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
|
|
2443
|
+
})] }),
|
|
2444
|
+
phase.kind === "installing" && jsx("span", {
|
|
2445
|
+
style: { color: "var(--snap-color-muted)" },
|
|
2446
|
+
children: "正在安装…"
|
|
2447
|
+
})
|
|
2448
|
+
] })
|
|
2449
|
+
]
|
|
2450
|
+
})
|
|
2451
|
+
}),
|
|
2452
|
+
jsx(Dialog, {
|
|
2453
|
+
open: keyChange !== void 0,
|
|
2454
|
+
onOpenChange: (next) => {
|
|
2455
|
+
if (!next) setKeyChange(void 0);
|
|
2456
|
+
},
|
|
2457
|
+
children: jsxs(DialogContent, {
|
|
2458
|
+
presentation: "modal",
|
|
2459
|
+
children: [
|
|
2460
|
+
jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
|
|
2461
|
+
jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
|
|
2462
|
+
style: { fontSize: "var(--snap-text-sm)" },
|
|
2463
|
+
children: [
|
|
2464
|
+
"已安装 v",
|
|
2465
|
+
keyChange.installedVersion,
|
|
2466
|
+
" → 源上 v",
|
|
2467
|
+
keyChange.feedVersion,
|
|
2468
|
+
"。"
|
|
2469
|
+
]
|
|
2470
|
+
}) }),
|
|
2471
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
2472
|
+
intent: "neutral",
|
|
2473
|
+
emphasis: "outline",
|
|
2474
|
+
onClick: () => setKeyChange(void 0),
|
|
2475
|
+
children: "取消"
|
|
2476
|
+
}), jsx(Button, {
|
|
2477
|
+
intent: "primary",
|
|
2478
|
+
"data-plugins-keychange-confirm": true,
|
|
2479
|
+
onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
|
|
2480
|
+
children: "仍要更新"
|
|
2481
|
+
})] })
|
|
2482
|
+
]
|
|
2483
|
+
})
|
|
2484
|
+
})
|
|
2485
|
+
]
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2488
|
+
//#endregion
|
|
2489
|
+
//#region lib/types/settings.js
|
|
2490
|
+
/** Sort pages by order, then registration time. */
|
|
2491
|
+
function orderedPages(pages) {
|
|
2492
|
+
return [...pages].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
|
|
2493
|
+
}
|
|
2494
|
+
/** A page-level boundary: one broken settings page must not take down the shell. */
|
|
2495
|
+
var SettingsPageBoundary = class extends Component {
|
|
2496
|
+
state = { failed: false };
|
|
2497
|
+
static getDerivedStateFromError() {
|
|
2498
|
+
return { failed: true };
|
|
2499
|
+
}
|
|
2500
|
+
componentDidCatch(error) {
|
|
2501
|
+
console.error(`[snap-rail ui] settings page ${this.props.page} failed`, error);
|
|
2502
|
+
}
|
|
2503
|
+
render() {
|
|
2504
|
+
return this.state.failed ? jsx(EmptyState, {
|
|
2505
|
+
title: "设置页加载失败",
|
|
2506
|
+
description: "该页面抛出了异常,其他设置页仍可使用。"
|
|
2507
|
+
}) : this.props.children;
|
|
2508
|
+
}
|
|
2509
|
+
};
|
|
2510
|
+
/** The gear glyph used by the default trigger. */
|
|
2511
|
+
function GearIcon() {
|
|
2512
|
+
return jsxs("svg", {
|
|
2513
|
+
viewBox: "0 0 24 24",
|
|
2514
|
+
width: "18",
|
|
2515
|
+
height: "18",
|
|
2516
|
+
fill: "none",
|
|
2517
|
+
stroke: "currentColor",
|
|
2518
|
+
strokeWidth: "1.8",
|
|
2519
|
+
"aria-hidden": "true",
|
|
2520
|
+
children: [jsx("circle", {
|
|
2521
|
+
cx: "12",
|
|
2522
|
+
cy: "12",
|
|
2523
|
+
r: "3"
|
|
2524
|
+
}), 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" })]
|
|
2525
|
+
});
|
|
2526
|
+
}
|
|
2527
|
+
/** The close glyph used by the surface's dismiss control. */
|
|
2528
|
+
function CloseIcon() {
|
|
2529
|
+
return jsx("svg", {
|
|
2530
|
+
viewBox: "0 0 24 24",
|
|
2531
|
+
width: "18",
|
|
2532
|
+
height: "18",
|
|
2533
|
+
fill: "none",
|
|
2534
|
+
stroke: "currentColor",
|
|
2535
|
+
strokeWidth: "1.8",
|
|
2536
|
+
"aria-hidden": "true",
|
|
2537
|
+
children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
/** The default settings trigger; the layout decides placement/presentation. */
|
|
2541
|
+
function SettingsEntry(props) {
|
|
2542
|
+
if (props.presentation === "label") return jsx(Button, {
|
|
2543
|
+
intent: "neutral",
|
|
2544
|
+
emphasis: "ghost",
|
|
2545
|
+
icon: jsx(GearIcon, {}),
|
|
2546
|
+
onClick: props.open,
|
|
2547
|
+
children: "设置"
|
|
2548
|
+
});
|
|
2549
|
+
return jsx(IconButton, {
|
|
2550
|
+
icon: jsx(GearIcon, {}),
|
|
2551
|
+
label: "设置",
|
|
2552
|
+
active: props.isOpen,
|
|
2553
|
+
onClick: props.open
|
|
2554
|
+
});
|
|
2555
|
+
}
|
|
2556
|
+
/** The default settings surface. */
|
|
2557
|
+
function SettingsSurface(props) {
|
|
2558
|
+
const { service, ctx } = props;
|
|
2559
|
+
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
2560
|
+
const open = service.isOpen();
|
|
2561
|
+
const pages = service.listPages();
|
|
2562
|
+
const activeId = service.activePage();
|
|
2563
|
+
const active = pages.find((page) => page.id === activeId);
|
|
2564
|
+
const [feedOpen, setFeedOpen] = useState(false);
|
|
2565
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2566
|
+
for (const page of pages) {
|
|
2567
|
+
const group = page.group ?? "其他";
|
|
2568
|
+
const bucket = groups.get(group);
|
|
2569
|
+
if (bucket === void 0) groups.set(group, [page]);
|
|
2570
|
+
else bucket.push(page);
|
|
2571
|
+
}
|
|
2572
|
+
return jsxs(Fragment, { children: [jsx(Dialog, {
|
|
2573
|
+
open,
|
|
2574
|
+
onOpenChange: (next) => {
|
|
2575
|
+
if (!next) service.close();
|
|
2576
|
+
},
|
|
2577
|
+
children: jsx(DialogContent, {
|
|
2578
|
+
presentation: "fullscreen",
|
|
2579
|
+
showClose: false,
|
|
2580
|
+
children: jsxs("div", {
|
|
2581
|
+
...part("settings", "root"),
|
|
2582
|
+
className: "snap-settings",
|
|
2583
|
+
children: [jsxs("header", {
|
|
2584
|
+
...part("settings", "header"),
|
|
2585
|
+
className: "snap-settings-header",
|
|
2586
|
+
children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
|
|
2587
|
+
style: {
|
|
2588
|
+
display: "flex",
|
|
2589
|
+
alignItems: "center",
|
|
2590
|
+
gap: 4
|
|
2591
|
+
},
|
|
2592
|
+
children: [jsx(IconButton, {
|
|
2593
|
+
icon: jsx(GearIcon, {}),
|
|
2594
|
+
label: "配置插件源",
|
|
2595
|
+
onClick: () => setFeedOpen(true)
|
|
2596
|
+
}), jsx(IconButton, {
|
|
2597
|
+
icon: jsx(CloseIcon, {}),
|
|
2598
|
+
label: "关闭",
|
|
2599
|
+
onClick: () => service.close()
|
|
2600
|
+
})]
|
|
2601
|
+
})]
|
|
2602
|
+
}), jsxs("div", {
|
|
2603
|
+
...part("settings", "body"),
|
|
2604
|
+
className: "snap-settings-body",
|
|
2605
|
+
children: [jsx("nav", {
|
|
2606
|
+
...part("settings", "nav"),
|
|
2607
|
+
className: "snap-settings-nav",
|
|
2608
|
+
"aria-label": "设置页",
|
|
2609
|
+
children: [...groups.entries()].map(([group, entries]) => jsxs("div", {
|
|
2610
|
+
...part("settings", "group"),
|
|
2611
|
+
className: "snap-settings-group",
|
|
2612
|
+
children: [jsx("div", {
|
|
2613
|
+
...part("settings", "group-title"),
|
|
2614
|
+
className: "snap-settings-group-title",
|
|
2615
|
+
children: group
|
|
2616
|
+
}), entries.map((page) => jsxs("button", {
|
|
2617
|
+
type: "button",
|
|
2618
|
+
...part("settings", "nav-item"),
|
|
2619
|
+
className: cn("snap-settings-nav-item", page.id === activeId && "is-active"),
|
|
2620
|
+
"data-active": page.id === activeId || void 0,
|
|
2621
|
+
"aria-current": page.id === activeId ? "page" : void 0,
|
|
2622
|
+
onClick: () => service.open(page.id),
|
|
2623
|
+
children: [page.icon !== void 0 && jsx("span", {
|
|
2624
|
+
...part("settings", "nav-icon"),
|
|
2625
|
+
children: page.icon
|
|
2626
|
+
}), jsx("span", { children: page.title })]
|
|
2627
|
+
}, page.id))]
|
|
2628
|
+
}, group))
|
|
2629
|
+
}), jsx("main", {
|
|
2630
|
+
...part("settings", "content"),
|
|
2631
|
+
className: "snap-settings-content",
|
|
2632
|
+
"data-active-page": activeId,
|
|
2633
|
+
children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
|
|
2634
|
+
page: active.id,
|
|
2635
|
+
children: active.render()
|
|
2636
|
+
})
|
|
2637
|
+
})]
|
|
2638
|
+
})]
|
|
2639
|
+
})
|
|
2640
|
+
})
|
|
2641
|
+
}), jsx(PluginFeedDialog, {
|
|
2642
|
+
ctx,
|
|
2643
|
+
open: feedOpen,
|
|
2644
|
+
onOpenChange: setFeedOpen
|
|
2645
|
+
})] });
|
|
2646
|
+
}
|
|
2647
|
+
/** Mount the settings registry and its default slot contributions. */
|
|
2648
|
+
const settingsPlugin = {
|
|
2649
|
+
name: "snap-rail settings",
|
|
2650
|
+
inject: ["ui"],
|
|
2651
|
+
apply(ctx) {
|
|
2652
|
+
const pages = /* @__PURE__ */ new Map();
|
|
2653
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2654
|
+
let open = false;
|
|
2655
|
+
let requestedId;
|
|
2656
|
+
let revision = 0;
|
|
2657
|
+
let seq = 0;
|
|
2658
|
+
const notify = (kind) => {
|
|
2659
|
+
revision += 1;
|
|
2660
|
+
for (const listener of listeners) listener();
|
|
2661
|
+
ctx.emit(kind === "pages" ? "settings/pages-changed" : "settings/open-changed");
|
|
2662
|
+
};
|
|
2663
|
+
const firstId = () => orderedPages(pages.values())[0]?.id;
|
|
2664
|
+
const activeId = () => {
|
|
2665
|
+
if (!open) return void 0;
|
|
2666
|
+
if (requestedId !== void 0 && pages.has(requestedId)) return requestedId;
|
|
2667
|
+
return firstId();
|
|
2668
|
+
};
|
|
2669
|
+
const service = {
|
|
2670
|
+
registerPage(caller, page) {
|
|
2671
|
+
pages.set(page.id, {
|
|
2672
|
+
page,
|
|
2673
|
+
seq: seq++
|
|
2674
|
+
});
|
|
2675
|
+
notify("pages");
|
|
2676
|
+
const remove = () => {
|
|
2677
|
+
if (pages.delete(page.id)) notify("pages");
|
|
2678
|
+
};
|
|
2679
|
+
caller.effect(() => remove);
|
|
2680
|
+
return remove;
|
|
2681
|
+
},
|
|
2682
|
+
listPages: () => orderedPages(pages.values()),
|
|
2683
|
+
open(pageId) {
|
|
2684
|
+
if (pageId !== void 0) requestedId = pageId;
|
|
2685
|
+
if (open && pageId === void 0) return;
|
|
2686
|
+
open = true;
|
|
2687
|
+
notify("open");
|
|
2688
|
+
},
|
|
2689
|
+
close() {
|
|
2690
|
+
if (!open) return;
|
|
2691
|
+
open = false;
|
|
2692
|
+
notify("open");
|
|
2693
|
+
},
|
|
2694
|
+
toggle() {
|
|
2695
|
+
if (open) service.close();
|
|
2696
|
+
else service.open();
|
|
2697
|
+
},
|
|
2698
|
+
isOpen: () => open,
|
|
2699
|
+
activePage: activeId,
|
|
2700
|
+
subscribe(listener) {
|
|
2701
|
+
listeners.add(listener);
|
|
2702
|
+
return () => {
|
|
2703
|
+
listeners.delete(listener);
|
|
2704
|
+
};
|
|
2705
|
+
},
|
|
2706
|
+
version: () => revision
|
|
2707
|
+
};
|
|
2708
|
+
ctx.provide("settings", service);
|
|
2709
|
+
ctx.settings.registerPage(ctx, {
|
|
2710
|
+
id: "plugins",
|
|
2711
|
+
title: "插件管理",
|
|
2712
|
+
group: "系统",
|
|
2713
|
+
order: 0,
|
|
2714
|
+
keywords: [
|
|
2715
|
+
"安装",
|
|
2716
|
+
"启用",
|
|
2717
|
+
"卸载",
|
|
2718
|
+
"驱动",
|
|
2719
|
+
"皮肤"
|
|
2720
|
+
],
|
|
2721
|
+
render: () => jsx(PluginsPage, { ctx })
|
|
2722
|
+
});
|
|
2723
|
+
ctx.settings.registerPage(ctx, {
|
|
2724
|
+
id: "appearance",
|
|
2725
|
+
title: "外观与显示",
|
|
2726
|
+
group: "系统",
|
|
2727
|
+
order: 1,
|
|
2728
|
+
keywords: [
|
|
2729
|
+
"主题",
|
|
2730
|
+
"皮肤",
|
|
2731
|
+
"窗口",
|
|
2732
|
+
"悬浮球",
|
|
2733
|
+
"尺寸"
|
|
2734
|
+
],
|
|
2735
|
+
render: () => jsx(AppearancePage, {})
|
|
2736
|
+
});
|
|
2737
|
+
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsEntry, {
|
|
2738
|
+
id: "settings.default-entry",
|
|
2739
|
+
order: 0,
|
|
2740
|
+
render: (context) => jsx(SettingsEntry, {
|
|
2741
|
+
presentation: context.presentation,
|
|
2742
|
+
open: context.open,
|
|
2743
|
+
isOpen: context.isOpen
|
|
2744
|
+
})
|
|
2745
|
+
});
|
|
2746
|
+
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
|
|
2747
|
+
id: "settings.default-surface",
|
|
2748
|
+
order: 0,
|
|
2749
|
+
render: () => jsx(SettingsSurface, {
|
|
2750
|
+
service,
|
|
2751
|
+
ctx
|
|
2752
|
+
})
|
|
2753
|
+
});
|
|
2754
|
+
}
|
|
2755
|
+
};
|
|
2756
|
+
//#endregion
|
|
2757
|
+
//#region lib/types/runtime.js
|
|
2758
|
+
/**
|
|
2759
|
+
* The built-in renderer runtime: it takes over the kernel root, mounts the
|
|
2760
|
+
* core services, the skins, the layout/page plugins, and finally the fallback
|
|
2761
|
+
* layout. There is no framework row and no framework seed: the substrate is
|
|
2762
|
+
* always present, so a fresh install has a usable UI before any plugin is
|
|
2763
|
+
* installed.
|
|
2764
|
+
*
|
|
2765
|
+
* @module @snap-rail/ui/runtime
|
|
2766
|
+
*/
|
|
2767
|
+
/** The React context carrying the host link/surface into builtin pages. */
|
|
2768
|
+
const ClientContext = createContext(null);
|
|
2769
|
+
/** Provide the client services to builtin page components. */
|
|
2770
|
+
function ClientProvider(props) {
|
|
2771
|
+
return jsx(ClientContext.Provider, {
|
|
2772
|
+
value: props.service,
|
|
2773
|
+
children: props.children
|
|
2774
|
+
});
|
|
2775
|
+
}
|
|
2776
|
+
/** Read the client services (host link + surface) from a builtin page. */
|
|
2777
|
+
function useClient() {
|
|
2778
|
+
const service = useContext(ClientContext);
|
|
2779
|
+
if (service === null) throw new Error("useClient: no ClientProvider in the tree");
|
|
2780
|
+
return service;
|
|
2781
|
+
}
|
|
2782
|
+
/**
|
|
2783
|
+
* Wire an element as a ball face's single drag/click surface. Past the travel
|
|
2784
|
+
* threshold the face only signals `shell.ball.move` `begin`/`end`; the host
|
|
2785
|
+
* anchors the grab from the OS cursor and runs the dock settle, so the face
|
|
2786
|
+
* never streams coordinates. A press-release inside the threshold is the
|
|
2787
|
+
* click. Returns the disposer removing every listener.
|
|
2788
|
+
*/
|
|
2789
|
+
const attachBallDrag = attachBallDrag$1;
|
|
2790
|
+
/** Re-render on settings open/page changes. */
|
|
2791
|
+
function useSettingsVersion(ctx) {
|
|
2792
|
+
return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
|
|
2793
|
+
}
|
|
2794
|
+
/** Apply the active layout's stage profiles to the host. */
|
|
2795
|
+
function StageProfiles(props) {
|
|
2796
|
+
const link = props.ctx.client.link;
|
|
2797
|
+
const layout = props.layout;
|
|
2798
|
+
useEffect(() => {
|
|
2799
|
+
if (layout?.window !== void 0) link.call("shell.window.configure", { profile: layout.window }).catch(() => {});
|
|
2800
|
+
if (layout?.ball !== void 0) link.call("shell.ball.configure", { profile: layout.ball }).catch(() => {});
|
|
2801
|
+
}, [layout?.id]);
|
|
2802
|
+
return null;
|
|
2803
|
+
}
|
|
2804
|
+
/** The global overlay host: registry-owned surfaces do not depend on a layout. */
|
|
2805
|
+
function OverlayHost(props) {
|
|
2806
|
+
useUiVersion(props.ctx.ui);
|
|
2807
|
+
useSettingsVersion(props.ctx);
|
|
2808
|
+
const overlays = props.ctx.ui.list(UI_SLOT_IDS.overlay);
|
|
2809
|
+
const settingsSurfaces = props.ctx.settings.isOpen() ? props.ctx.ui.list(UI_SLOT_IDS.settingsSurface) : [];
|
|
2810
|
+
const context = {
|
|
2811
|
+
pages: props.ctx.settings.listPages().map((page) => ({
|
|
2812
|
+
id: page.id,
|
|
2813
|
+
title: page.title,
|
|
2814
|
+
...page.group !== void 0 ? { group: page.group } : {},
|
|
2815
|
+
order: page.order
|
|
2816
|
+
})),
|
|
2817
|
+
...props.ctx.settings.activePage() !== void 0 ? { activeId: props.ctx.settings.activePage() } : {},
|
|
2818
|
+
close: () => props.ctx.settings.close()
|
|
2819
|
+
};
|
|
2820
|
+
return jsxs(Fragment, { children: [overlays.map((item) => jsx("span", { children: item.render({ surface: "main" }) }, item.id)), settingsSurfaces.map((item) => jsx("span", { children: item.render(context) }, item.id))] });
|
|
2821
|
+
}
|
|
2822
|
+
/** The floating settings fallback, rendered only when no layout provides the seat. */
|
|
2823
|
+
function SettingsFallbackHost(props) {
|
|
2824
|
+
useUiVersion(props.ctx.ui);
|
|
2825
|
+
useSettingsVersion(props.ctx);
|
|
2826
|
+
if (props.ctx.ui.hasProvider(UI_SLOT_IDS.settingsEntry)) return null;
|
|
2827
|
+
const entry = props.ctx.ui.list(UI_SLOT_IDS.settingsEntry)[0];
|
|
2828
|
+
if (entry === void 0) return null;
|
|
2829
|
+
return jsx("div", {
|
|
2830
|
+
"data-snap-part": "settings.fallback",
|
|
2831
|
+
style: {
|
|
2832
|
+
position: "fixed",
|
|
2833
|
+
right: 16,
|
|
2834
|
+
bottom: 16,
|
|
2835
|
+
zIndex: "var(--snap-z-overlay)"
|
|
2836
|
+
},
|
|
2837
|
+
children: entry.render({
|
|
2838
|
+
presentation: "icon",
|
|
2839
|
+
open: () => props.ctx.settings.open(),
|
|
2840
|
+
isOpen: props.ctx.settings.isOpen()
|
|
2841
|
+
})
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
/** The operator-window root. */
|
|
2845
|
+
function MainRoot(props) {
|
|
2846
|
+
const layout = useActiveLayout();
|
|
2847
|
+
return jsxs(Fragment, { children: [
|
|
2848
|
+
jsx(StageProfiles, {
|
|
2849
|
+
ctx: props.ctx,
|
|
2850
|
+
layout
|
|
2851
|
+
}),
|
|
2852
|
+
layout === void 0 ? jsx("div", {
|
|
2853
|
+
style: { padding: 24 },
|
|
2854
|
+
children: "没有已加载的布局插件。"
|
|
2855
|
+
}) : layout.render(),
|
|
2856
|
+
jsx(OverlayHost, { ctx: props.ctx }),
|
|
2857
|
+
jsx(SettingsFallbackHost, { ctx: props.ctx })
|
|
2858
|
+
] });
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
* The fallback ball face used when no plugin occupies `shell.ball`: a themed
|
|
2862
|
+
* disc that follows the active skin tokens (visible on any colour mode). The
|
|
2863
|
+
* whole ball is one drag/click surface ({@link attachBallDrag}): press-move
|
|
2864
|
+
* drags the window over `shell.ball.move`, a press-release summons the
|
|
2865
|
+
* operator window — the same anatomy the kernel's crash fallback paints.
|
|
2866
|
+
*/
|
|
2867
|
+
function BallRoot(props) {
|
|
2868
|
+
useUiVersion(props.ctx.ui);
|
|
2869
|
+
const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
|
|
2870
|
+
const link = props.ctx.client.link;
|
|
2871
|
+
const hasOccupant = occupant !== void 0;
|
|
2872
|
+
const rootRef = useRef(null);
|
|
2873
|
+
useEffect(() => {
|
|
2874
|
+
if (hasOccupant) return void 0;
|
|
2875
|
+
const element = rootRef.current;
|
|
2876
|
+
if (element === null) return void 0;
|
|
2877
|
+
return attachBallDrag(element, {
|
|
2878
|
+
link,
|
|
2879
|
+
onClick: () => {
|
|
2880
|
+
link.call("shell.surface.present", { surface: "main" });
|
|
2881
|
+
}
|
|
2882
|
+
});
|
|
2883
|
+
}, [hasOccupant, link]);
|
|
2884
|
+
if (occupant !== void 0) return jsx("div", {
|
|
2885
|
+
style: {
|
|
2886
|
+
width: "100%",
|
|
2887
|
+
height: "100%"
|
|
2888
|
+
},
|
|
2889
|
+
children: occupant.render({ surface: "ball" })
|
|
2890
|
+
});
|
|
2891
|
+
return jsx("div", {
|
|
2892
|
+
ref: rootRef,
|
|
2893
|
+
"data-snap-part": "ball.root",
|
|
2894
|
+
style: {
|
|
2895
|
+
display: "flex",
|
|
2896
|
+
alignItems: "center",
|
|
2897
|
+
justifyContent: "center",
|
|
2898
|
+
width: "100%",
|
|
2899
|
+
height: "100%"
|
|
2900
|
+
},
|
|
2901
|
+
children: jsx("div", {
|
|
2902
|
+
"data-snap-part": "ball.orb",
|
|
2903
|
+
style: {
|
|
2904
|
+
display: "flex",
|
|
2905
|
+
alignItems: "center",
|
|
2906
|
+
justifyContent: "center",
|
|
2907
|
+
width: "calc(100% - 16px)",
|
|
2908
|
+
height: "calc(100% - 16px)",
|
|
2909
|
+
borderRadius: "50%",
|
|
2910
|
+
background: "var(--snap-color-surface-raised)",
|
|
2911
|
+
border: "var(--snap-border-width) solid var(--snap-color-border)"
|
|
2912
|
+
},
|
|
2913
|
+
children: jsx("button", {
|
|
2914
|
+
type: "button",
|
|
2915
|
+
"data-snap-part": "ball.core",
|
|
2916
|
+
title: "打开主窗口",
|
|
2917
|
+
style: {
|
|
2918
|
+
width: "calc(100% - 16px)",
|
|
2919
|
+
height: "calc(100% - 16px)",
|
|
2920
|
+
borderRadius: "50%",
|
|
2921
|
+
border: "none",
|
|
2922
|
+
background: "var(--snap-color-surface)",
|
|
2923
|
+
color: "var(--snap-color-text)",
|
|
2924
|
+
fontSize: "var(--snap-text-xs)",
|
|
2925
|
+
fontWeight: "var(--snap-weight-medium)",
|
|
2926
|
+
cursor: "default"
|
|
2927
|
+
},
|
|
2928
|
+
children: "snap-rail"
|
|
2929
|
+
})
|
|
2930
|
+
})
|
|
2931
|
+
});
|
|
2932
|
+
}
|
|
2933
|
+
/** The root that mounts the layout (or the ball face) and the global overlays. */
|
|
2934
|
+
function UiRoot(props) {
|
|
2935
|
+
return jsx(ClientProvider, {
|
|
2936
|
+
service: props.ctx.client,
|
|
2937
|
+
children: jsx(UiProvider, {
|
|
2938
|
+
service: props.ctx.ui,
|
|
2939
|
+
children: jsx(SkinsProvider, {
|
|
2940
|
+
service: props.ctx.skins,
|
|
2941
|
+
children: props.surface === "main" ? jsx(MainRoot, { ctx: props.ctx }) : jsx(BallRoot, { ctx: props.ctx })
|
|
2942
|
+
})
|
|
2943
|
+
})
|
|
2944
|
+
});
|
|
2945
|
+
}
|
|
2946
|
+
/**
|
|
2947
|
+
* Take over the kernel root and mount the UI substrate.
|
|
2948
|
+
*
|
|
2949
|
+
* @param handle - the kernel boot result.
|
|
2950
|
+
* @param options - see {@link RuntimeOptions}.
|
|
2951
|
+
*/
|
|
2952
|
+
async function createClientRuntime(handle, options) {
|
|
2953
|
+
const surface = options.surface ?? "main";
|
|
2954
|
+
const ctx = new Context();
|
|
2955
|
+
ctx.provide("client", {
|
|
2956
|
+
link: handle.link,
|
|
2957
|
+
surface
|
|
2958
|
+
});
|
|
2959
|
+
await ctx.plugin(TimerService);
|
|
2960
|
+
await ctx.plugin(slotsPlugin);
|
|
2961
|
+
await ctx.plugin(pagesPlugin);
|
|
2962
|
+
await ctx.plugin(skinsPlugin);
|
|
2963
|
+
await ctx.plugin(settingsPlugin);
|
|
2964
|
+
const applyThemeRow = (value) => {
|
|
2965
|
+
const row = value;
|
|
2966
|
+
const selection = typeof row?.id === "string" && row.id !== "" ? row.id : row?.mode === "light" ? DEFAULT_LIGHT_ID : DEFAULT_DARK_ID;
|
|
2967
|
+
if (!ctx.skins.activate(selection)) ctx.skins.activate(DEFAULT_DARK_ID);
|
|
2968
|
+
};
|
|
2969
|
+
handle.link.call("settings.get", { key: "ui.theme" }).then((result) => {
|
|
2970
|
+
if (result.ok) applyThemeRow(result.value.value);
|
|
2971
|
+
}).catch(() => {});
|
|
2972
|
+
const dropTheme = subscribeFrame(handle.link, "settings/changed", settingsChangedSchema, (change) => {
|
|
2973
|
+
if (change.key === "ui.theme") applyThemeRow(change.value);
|
|
2974
|
+
});
|
|
2975
|
+
const dropOpenSettings = subscribeFrame(handle.link, "shell/settings-open-requested", shellContract.frames["shell/settings-open-requested"], () => {
|
|
2976
|
+
ctx.settings.open();
|
|
2977
|
+
});
|
|
2978
|
+
ctx.effect(() => () => {
|
|
2979
|
+
dropTheme();
|
|
2980
|
+
dropOpenSettings();
|
|
2981
|
+
});
|
|
2982
|
+
for (const page of options.builtinPages ?? []) ctx.settings.registerPage(ctx, page);
|
|
2983
|
+
for (const seat of options.plugins) {
|
|
2984
|
+
const spec = "plugin" in seat ? seat : { plugin: seat };
|
|
2985
|
+
const plugin = spec.plugin;
|
|
2986
|
+
await ctx.plugin(plugin, spec.config === void 0 ? {} : spec.config);
|
|
2987
|
+
}
|
|
2988
|
+
if (surface === "main") await ctx.plugin(fallbackPlugin);
|
|
2989
|
+
handle.root.unmount();
|
|
2990
|
+
const shellRoot = createRoot(handle.element);
|
|
2991
|
+
shellRoot.render(jsx(UiRoot, {
|
|
2992
|
+
ctx,
|
|
2993
|
+
surface
|
|
2994
|
+
}));
|
|
2995
|
+
return {
|
|
2996
|
+
ctx,
|
|
2997
|
+
dispose: () => ctx.fiber.dispose().then(() => {
|
|
2998
|
+
shellRoot.unmount();
|
|
2999
|
+
})
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
//#endregion
|
|
3003
|
+
export { ClientProvider, Slot, attachBallDrag, createClientRuntime, fallbackPlugin, pagesPlugin, settingsPlugin, skinsPlugin, slotsPlugin, useClient };
|