@snap-rail/ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/lib/charts.js +142 -0
- package/lib/contract.js +543 -0
- package/lib/fallback.js +400 -0
- package/lib/index.js +3345 -0
- package/lib/pages.js +68 -0
- package/lib/runtime.js +2064 -0
- package/lib/settings.js +1195 -0
- package/lib/skins.js +284 -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 +37 -0
- package/lib/types/components/input.js +15 -0
- package/lib/types/components/layout.d.ts +100 -0
- package/lib/types/components/layout.js +80 -0
- package/lib/types/components/schema-form.d.ts +34 -0
- package/lib/types/components/schema-form.js +61 -0
- package/lib/types/components/surface.d.ts +49 -0
- package/lib/types/components/surface.js +59 -0
- package/lib/types/contract.d.ts +358 -0
- package/lib/types/contract.js +235 -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 +71 -0
- package/lib/types/runtime.js +177 -0
- package/lib/types/settings-pages/appearance.d.ts +13 -0
- package/lib/types/settings-pages/appearance.js +131 -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/plugins.d.ts +16 -0
- package/lib/types/settings-pages/plugins.js +109 -0
- package/lib/types/settings.d.ts +58 -0
- package/lib/types/settings.js +170 -0
- package/lib/types/skins.d.ts +143 -0
- package/lib/types/skins.js +268 -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 +321 -0
- package/src/styles/default.css +734 -0
- package/README.md +0 -3
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { subscribeFrame } from '@snap-rail/connection';
|
|
3
|
+
import { settingsChangedSchema } from '@snap-rail/station-rpc/contract';
|
|
4
|
+
import { Context } from '@snap-rail/cordis';
|
|
5
|
+
import { TimerService as timerPlugin } from '@snap-rail/cordis-plugin-timer';
|
|
6
|
+
import { shellContract } from '@snap-rail/shell/contract';
|
|
7
|
+
import { createContext, useContext, useEffect, useSyncExternalStore } from 'react';
|
|
8
|
+
import { createRoot } from 'react-dom/client';
|
|
9
|
+
import fallbackPlugin from "./fallback.js";
|
|
10
|
+
import pagesPlugin from "./pages.js";
|
|
11
|
+
import settingsPlugin from "./settings.js";
|
|
12
|
+
import { UI_SLOT_IDS } from "./contract.js";
|
|
13
|
+
import { Slot, UiProvider, useActiveLayout, useUiVersion } from "./slots.js";
|
|
14
|
+
import slotsPlugin from "./slots.js";
|
|
15
|
+
import { SkinsProvider } from "./skins.js";
|
|
16
|
+
import skinsPlugin from "./skins.js";
|
|
17
|
+
/** The React context carrying the host link/surface into builtin pages. */
|
|
18
|
+
const ClientContext = createContext(null);
|
|
19
|
+
/** Provide the client services to builtin page components. */
|
|
20
|
+
export function ClientProvider(props) {
|
|
21
|
+
return _jsx(ClientContext.Provider, { value: props.service, children: props.children });
|
|
22
|
+
}
|
|
23
|
+
/** Read the client services (host link + surface) from a builtin page. */
|
|
24
|
+
export function useClient() {
|
|
25
|
+
const service = useContext(ClientContext);
|
|
26
|
+
if (service === null)
|
|
27
|
+
throw new Error('useClient: no ClientProvider in the tree');
|
|
28
|
+
return service;
|
|
29
|
+
}
|
|
30
|
+
/** Re-render on settings open/page changes. */
|
|
31
|
+
function useSettingsVersion(ctx) {
|
|
32
|
+
return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
|
|
33
|
+
}
|
|
34
|
+
/** Apply the active layout's stage profiles to the host. */
|
|
35
|
+
function StageProfiles(props) {
|
|
36
|
+
const link = props.ctx.client.link;
|
|
37
|
+
const layout = props.layout;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (layout?.window !== undefined) {
|
|
40
|
+
void link.call('shell.window.configure', { profile: layout.window }).catch(() => { });
|
|
41
|
+
}
|
|
42
|
+
if (layout?.ball !== undefined) {
|
|
43
|
+
void link.call('shell.ball.configure', { profile: layout.ball }).catch(() => { });
|
|
44
|
+
}
|
|
45
|
+
}, [layout?.id]);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** The global overlay host: registry-owned surfaces do not depend on a layout. */
|
|
49
|
+
function OverlayHost(props) {
|
|
50
|
+
useUiVersion(props.ctx.ui);
|
|
51
|
+
useSettingsVersion(props.ctx);
|
|
52
|
+
const overlays = props.ctx.ui.list(UI_SLOT_IDS.overlay);
|
|
53
|
+
const settingsOpen = props.ctx.settings.isOpen();
|
|
54
|
+
const settingsSurfaces = settingsOpen ? props.ctx.ui.list(UI_SLOT_IDS.settingsSurface) : [];
|
|
55
|
+
const pages = props.ctx.settings.listPages().map(page => ({
|
|
56
|
+
id: page.id,
|
|
57
|
+
title: page.title,
|
|
58
|
+
...page.group !== undefined ? { group: page.group } : {},
|
|
59
|
+
order: page.order,
|
|
60
|
+
}));
|
|
61
|
+
const context = {
|
|
62
|
+
pages,
|
|
63
|
+
...props.ctx.settings.activePage() !== undefined ? { activeId: props.ctx.settings.activePage() } : {},
|
|
64
|
+
close: () => props.ctx.settings.close(),
|
|
65
|
+
};
|
|
66
|
+
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))] }));
|
|
67
|
+
}
|
|
68
|
+
/** The floating settings fallback, rendered only when no layout provides the seat. */
|
|
69
|
+
function SettingsFallbackHost(props) {
|
|
70
|
+
useUiVersion(props.ctx.ui);
|
|
71
|
+
useSettingsVersion(props.ctx);
|
|
72
|
+
if (props.ctx.ui.hasProvider(UI_SLOT_IDS.settingsEntry))
|
|
73
|
+
return null;
|
|
74
|
+
const entry = props.ctx.ui.list(UI_SLOT_IDS.settingsEntry)[0];
|
|
75
|
+
if (entry === undefined)
|
|
76
|
+
return null;
|
|
77
|
+
return (_jsx("div", { "data-snap-part": "settings.fallback", style: { position: 'fixed', right: 16, bottom: 16, zIndex: 'var(--snap-z-overlay)' }, children: entry.render({
|
|
78
|
+
presentation: 'icon',
|
|
79
|
+
open: () => props.ctx.settings.open(),
|
|
80
|
+
isOpen: props.ctx.settings.isOpen(),
|
|
81
|
+
}) }));
|
|
82
|
+
}
|
|
83
|
+
/** The operator-window root. */
|
|
84
|
+
function MainRoot(props) {
|
|
85
|
+
const layout = useActiveLayout();
|
|
86
|
+
return (_jsxs(_Fragment, { children: [_jsx(StageProfiles, { ctx: props.ctx, layout: layout }), layout === undefined ? _jsx("div", { style: { padding: 24 }, children: "\u6CA1\u6709\u5DF2\u52A0\u8F7D\u7684\u5E03\u5C40\u63D2\u4EF6\u3002" }) : layout.render(), _jsx(OverlayHost, { ctx: props.ctx }), _jsx(SettingsFallbackHost, { ctx: props.ctx })] }));
|
|
87
|
+
}
|
|
88
|
+
/** The fallback ball face used when no plugin occupies `shell.ball`. */
|
|
89
|
+
function BallRoot(props) {
|
|
90
|
+
useUiVersion(props.ctx.ui);
|
|
91
|
+
const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
|
|
92
|
+
if (occupant !== undefined) {
|
|
93
|
+
return _jsx("div", { style: { width: '100%', height: '100%' }, children: occupant.render({ surface: 'ball' }) });
|
|
94
|
+
}
|
|
95
|
+
return (_jsx("div", { "data-snap-part": "ball.root", style: {
|
|
96
|
+
display: 'flex',
|
|
97
|
+
alignItems: 'center',
|
|
98
|
+
justifyContent: 'center',
|
|
99
|
+
width: '100%',
|
|
100
|
+
height: '100%',
|
|
101
|
+
color: 'var(--snap-color-muted)',
|
|
102
|
+
fontSize: 'var(--snap-text-xs)',
|
|
103
|
+
}, children: "snap-rail" }));
|
|
104
|
+
}
|
|
105
|
+
/** The root that mounts the layout (or the ball face) and the global overlays. */
|
|
106
|
+
function UiRoot(props) {
|
|
107
|
+
return (_jsx(ClientProvider, { service: props.ctx.client, children: _jsx(UiProvider, { service: props.ctx.ui, children: _jsx(SkinsProvider, { service: props.ctx.skins, children: props.surface === 'main' ? _jsx(MainRoot, { ctx: props.ctx }) : _jsx(BallRoot, { ctx: props.ctx }) }) }) }));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Take over the kernel root and mount the UI substrate.
|
|
111
|
+
*
|
|
112
|
+
* @param handle - the kernel boot result.
|
|
113
|
+
* @param options - see {@link RuntimeOptions}.
|
|
114
|
+
*/
|
|
115
|
+
export async function createClientRuntime(handle, options) {
|
|
116
|
+
const surface = options.surface ?? 'main';
|
|
117
|
+
const ctx = new Context();
|
|
118
|
+
ctx.provide('client', { link: handle.link, surface });
|
|
119
|
+
await ctx.plugin(timerPlugin);
|
|
120
|
+
await ctx.plugin(slotsPlugin);
|
|
121
|
+
await ctx.plugin(pagesPlugin);
|
|
122
|
+
await ctx.plugin(skinsPlugin);
|
|
123
|
+
await ctx.plugin(settingsPlugin);
|
|
124
|
+
// The operator's theme row is a simple settings.json value; apply it to the
|
|
125
|
+
// skin service now and follow the settings/changed frame without a reload.
|
|
126
|
+
const applyThemeRow = (value) => {
|
|
127
|
+
const mode = value?.mode;
|
|
128
|
+
const choice = mode === 'light' || mode === 'dark' || mode === 'system' ? mode : 'dark';
|
|
129
|
+
const prefersLight = typeof window !== 'undefined'
|
|
130
|
+
&& typeof window.matchMedia === 'function'
|
|
131
|
+
&& window.matchMedia('(prefers-color-scheme: light)').matches;
|
|
132
|
+
const resolved = choice === 'system' ? (prefersLight ? 'light' : 'dark') : choice;
|
|
133
|
+
ctx.skins.setMode(resolved);
|
|
134
|
+
if (typeof document !== 'undefined')
|
|
135
|
+
document.documentElement.dataset['mode'] = resolved;
|
|
136
|
+
};
|
|
137
|
+
void handle.link.call('settings.get', { key: 'ui.theme' })
|
|
138
|
+
.then(result => { if (result.ok)
|
|
139
|
+
applyThemeRow(result.value.value); })
|
|
140
|
+
.catch(() => { });
|
|
141
|
+
const dropTheme = subscribeFrame(handle.link, 'settings/changed', settingsChangedSchema, change => {
|
|
142
|
+
if (change.key === 'ui.theme')
|
|
143
|
+
applyThemeRow(change.value);
|
|
144
|
+
});
|
|
145
|
+
const dropOpenSettings = subscribeFrame(handle.link, 'shell/settings-open-requested', shellContract.frames['shell/settings-open-requested'], () => { ctx.settings.open(); });
|
|
146
|
+
ctx.effect(() => () => {
|
|
147
|
+
dropTheme();
|
|
148
|
+
dropOpenSettings();
|
|
149
|
+
});
|
|
150
|
+
// Core settings pages ride the same registry as plugin pages; the app owns
|
|
151
|
+
// the equipment page component and hands it in here.
|
|
152
|
+
for (const page of options.builtinPages ?? [])
|
|
153
|
+
ctx.settings.registerPage(ctx, page);
|
|
154
|
+
for (const seat of options.plugins) {
|
|
155
|
+
const spec = 'plugin' in seat ? seat : { plugin: seat };
|
|
156
|
+
const plugin = spec.plugin;
|
|
157
|
+
await ctx.plugin(plugin, spec.config === undefined ? {} : spec.config);
|
|
158
|
+
}
|
|
159
|
+
// The fallback is a normal low-precedence layout occupant; a suite layout
|
|
160
|
+
// shadows it and its disposal brings the fallback back.
|
|
161
|
+
if (surface === 'main')
|
|
162
|
+
await ctx.plugin(fallbackPlugin);
|
|
163
|
+
handle.root.unmount();
|
|
164
|
+
const shellRoot = createRoot(handle.element);
|
|
165
|
+
shellRoot.render(_jsx(UiRoot, { ctx: ctx, surface: surface }));
|
|
166
|
+
return {
|
|
167
|
+
ctx,
|
|
168
|
+
dispose: () => ctx.fiber.dispose().then(() => {
|
|
169
|
+
shellRoot.unmount();
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** The built-in fallback layout plugin (exported for tests and custom hosts). */
|
|
174
|
+
export { fallbackPlugin };
|
|
175
|
+
export { pagesPlugin, settingsPlugin, slotsPlugin, skinsPlugin };
|
|
176
|
+
export { Slot };
|
|
177
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in 外观与显示 page: colour mode, installed skins, the operator
|
|
3
|
+
* window profile, and the floating-ball profile. Everything writes the same
|
|
4
|
+
* settings.json rows the host applies live, so the page is a control surface,
|
|
5
|
+
* not a second source of truth.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/settings-pages/appearance
|
|
8
|
+
*/
|
|
9
|
+
import { type ReactNode } from 'react';
|
|
10
|
+
/** The appearance/display page. */
|
|
11
|
+
export declare function AppearancePage(): ReactNode;
|
|
12
|
+
export default AppearancePage;
|
|
13
|
+
//# sourceMappingURL=appearance.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { rpcErrorText, subscribeFrame } from '@snap-rail/connection';
|
|
3
|
+
import { settingsChangedSchema } from '@snap-rail/station-rpc/contract';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { Badge, Button, Page, Row, Section, Stack, Switch, Tabs, TabsList, TabsTrigger } from "../components/index.js";
|
|
6
|
+
import { useClient } from "../runtime.js";
|
|
7
|
+
const THEME_KEY = 'ui.theme';
|
|
8
|
+
const WINDOW_KEY = 'ui.window';
|
|
9
|
+
const BALL_KEY = 'ui.ball';
|
|
10
|
+
const WINDOW_PRESETS = [
|
|
11
|
+
{ label: '1280 × 800', width: 1280, height: 800 },
|
|
12
|
+
{ label: '1440 × 900', width: 1440, height: 900 },
|
|
13
|
+
{ label: '1600 × 900', width: 1600, height: 900 },
|
|
14
|
+
{ label: '1920 × 1080', width: 1920, height: 1080 },
|
|
15
|
+
];
|
|
16
|
+
const BALL_SIZES = [96, 112, 128, 160, 192];
|
|
17
|
+
/** Read a settings value through the host link. */
|
|
18
|
+
async function readSetting(link, key) {
|
|
19
|
+
const result = await link.call('settings.get', { key });
|
|
20
|
+
return result.ok ? result.value.value : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Write a settings value; `null` clears the row. */
|
|
23
|
+
async function writeSetting(link, key, value) {
|
|
24
|
+
await link.call('settings.set', { key, value });
|
|
25
|
+
}
|
|
26
|
+
/** The appearance/display page. */
|
|
27
|
+
export function AppearancePage() {
|
|
28
|
+
const { link } = useClient();
|
|
29
|
+
const [mode, setMode] = useState('dark');
|
|
30
|
+
const [windowPreset, setWindowPreset] = useState(undefined);
|
|
31
|
+
const [ballSize, setBallSize] = useState(128);
|
|
32
|
+
const [ballEnabled, setBallEnabled] = useState(true);
|
|
33
|
+
const [ballDockable, setBallDockable] = useState(true);
|
|
34
|
+
const [ballCollapse, setBallCollapse] = useState(true);
|
|
35
|
+
const [skins, setSkins] = useState([]);
|
|
36
|
+
const [error, setError] = useState(undefined);
|
|
37
|
+
const [busy, setBusy] = useState(false);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
void Promise.all([
|
|
40
|
+
readSetting(link, THEME_KEY),
|
|
41
|
+
readSetting(link, WINDOW_KEY),
|
|
42
|
+
readSetting(link, BALL_KEY),
|
|
43
|
+
link.call('plugins.list', {}),
|
|
44
|
+
]).then(([theme, windowRow, ballRow, plugins]) => {
|
|
45
|
+
const themeMode = theme?.mode;
|
|
46
|
+
if (themeMode === 'system' || themeMode === 'light' || themeMode === 'dark')
|
|
47
|
+
setMode(themeMode);
|
|
48
|
+
const windowProfile = windowRow;
|
|
49
|
+
if (windowProfile !== null && windowProfile !== undefined && typeof windowProfile.width === 'number' && typeof windowProfile.height === 'number') {
|
|
50
|
+
const preset = WINDOW_PRESETS.find(item => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
51
|
+
setWindowPreset(preset?.label);
|
|
52
|
+
}
|
|
53
|
+
const ballProfile = ballRow;
|
|
54
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.size === 'number')
|
|
55
|
+
setBallSize(ballProfile.size);
|
|
56
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.enabled === 'boolean')
|
|
57
|
+
setBallEnabled(ballProfile.enabled);
|
|
58
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.dockable === 'boolean')
|
|
59
|
+
setBallDockable(ballProfile.dockable);
|
|
60
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.collapse === 'boolean')
|
|
61
|
+
setBallCollapse(ballProfile.collapse);
|
|
62
|
+
if (plugins.ok) {
|
|
63
|
+
setSkins(plugins.value.plugins
|
|
64
|
+
.filter(plugin => plugin.kind === 'skin' && plugin.source !== 'builtin')
|
|
65
|
+
.map(plugin => ({ name: plugin.packageName, title: plugin.title ?? plugin.packageName, enabled: plugin.enabled })));
|
|
66
|
+
}
|
|
67
|
+
}).catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); });
|
|
68
|
+
return subscribeFrame(link, 'settings/changed', settingsChangedSchema, change => {
|
|
69
|
+
if (change.key === THEME_KEY) {
|
|
70
|
+
const next = change.value?.mode;
|
|
71
|
+
if (next === 'system' || next === 'light' || next === 'dark')
|
|
72
|
+
setMode(next);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}, [link]);
|
|
76
|
+
const saveTheme = (next) => {
|
|
77
|
+
setMode(next);
|
|
78
|
+
void writeSetting(link, THEME_KEY, { mode: next }).catch(cause => {
|
|
79
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const saveWindow = (width, height, label) => {
|
|
83
|
+
setWindowPreset(label);
|
|
84
|
+
void writeSetting(link, WINDOW_KEY, { width, height, minWidth: 960, minHeight: 600 }).catch(cause => {
|
|
85
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const resetWindow = () => {
|
|
89
|
+
setWindowPreset(undefined);
|
|
90
|
+
void writeSetting(link, WINDOW_KEY, null).catch(cause => {
|
|
91
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const saveBall = (patch) => {
|
|
95
|
+
const next = {
|
|
96
|
+
size: patch.size ?? ballSize,
|
|
97
|
+
enabled: patch.enabled ?? ballEnabled,
|
|
98
|
+
dockable: patch.dockable ?? ballDockable,
|
|
99
|
+
collapse: patch.collapse ?? ballCollapse,
|
|
100
|
+
};
|
|
101
|
+
if (patch.size !== undefined)
|
|
102
|
+
setBallSize(patch.size);
|
|
103
|
+
if (patch.enabled !== undefined)
|
|
104
|
+
setBallEnabled(patch.enabled);
|
|
105
|
+
if (patch.dockable !== undefined)
|
|
106
|
+
setBallDockable(patch.dockable);
|
|
107
|
+
if (patch.collapse !== undefined)
|
|
108
|
+
setBallCollapse(patch.collapse);
|
|
109
|
+
void writeSetting(link, BALL_KEY, next).catch(cause => {
|
|
110
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const toggleSkin = (skin) => {
|
|
114
|
+
setBusy(true);
|
|
115
|
+
void link.call('plugins.set-enabled', { name: skin.name, enabled: !skin.enabled })
|
|
116
|
+
.then(result => {
|
|
117
|
+
if (!result.ok) {
|
|
118
|
+
setError(rpcErrorText(result.error));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
setSkins(current => current.map(item => item.name === skin.name ? { ...item, enabled: !item.enabled } : item));
|
|
122
|
+
})
|
|
123
|
+
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
124
|
+
.finally(() => { setBusy(false); });
|
|
125
|
+
};
|
|
126
|
+
return (_jsx(Page, { title: "\u5916\u89C2\u4E0E\u663E\u793A", description: "\u4E3B\u9898\u3001\u76AE\u80A4\u3001\u4E3B\u7A97\u53E3\u5C3A\u5BF8\u548C\u60AC\u6D6E\u7403\u5916\u89C2\uFF1B\u4FDD\u5B58\u540E\u7ACB\u5373\u751F\u6548\u3002", children: _jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx("div", { role: "alert", style: { color: 'var(--snap-color-danger)' }, children: error }), _jsx(Section, { title: "\u4E3B\u9898\u6A21\u5F0F", children: _jsx(Tabs, { value: mode, onValueChange: value => saveTheme(value), children: _jsxs(TabsList, { "aria-label": "\u4E3B\u9898\u6A21\u5F0F", children: [_jsx(TabsTrigger, { value: "system", children: "\u8DDF\u968F\u7CFB\u7EDF" }), _jsx(TabsTrigger, { value: "light", children: "\u767D\u5929" }), _jsx(TabsTrigger, { value: "dark", children: "\u9ED1\u591C" })] }) }) }), _jsx(Section, { title: "\u754C\u9762\u76AE\u80A4", description: "\u76AE\u80A4\u7531\u72EC\u7ACB\u63D2\u4EF6\u63D0\u4F9B\uFF1B\u542F\u7528\u540E\u9700\u8981\u91CD\u542F\u7EC8\u7AEF\u3002", children: _jsxs(Stack, { gap: "sm", children: [_jsxs(Row, { gap: "sm", align: "center", children: [_jsx(Badge, { intent: "success", children: "\u9ED8\u8BA4\uFF08\u5185\u7F6E\uFF09" }), _jsx("span", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: "\u5DE5\u4E1A\u94B4\u84DD\uFF0C\u59CB\u7EC8\u53EF\u7528" })] }), skins.length === 0
|
|
127
|
+
? _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u5C1A\u672A\u5B89\u88C5\u5176\u4ED6\u76AE\u80A4\u63D2\u4EF6\u3002" })
|
|
128
|
+
: skins.map(skin => (_jsxs(Row, { gap: "sm", align: "center", children: [_jsx("span", { children: skin.title }), _jsx(Badge, { intent: skin.enabled ? 'success' : 'neutral', children: skin.enabled ? '已启用' : '未启用' }), _jsx(Button, { size: "sm", emphasis: "outline", disabled: busy, onClick: () => toggleSkin(skin), children: skin.enabled ? '停用' : '启用' })] }, skin.name)))] }) }), _jsx(Section, { title: "\u4E3B\u7A97\u53E3", description: "\u5E03\u5C40/\u5957\u4EF6\u4F1A\u58F0\u660E\u63A8\u8350\u5C3A\u5BF8\uFF1B\u8FD9\u91CC\u7684\u9009\u62E9\u4F1A\u8986\u76D6\u5E03\u5C40\u63A8\u8350\u3002", children: _jsxs(Stack, { gap: "sm", children: [_jsxs(Row, { gap: "sm", wrap: true, children: [WINDOW_PRESETS.map(preset => (_jsx(Button, { size: "sm", intent: windowPreset === preset.label ? 'primary' : 'neutral', emphasis: windowPreset === preset.label ? 'solid' : 'outline', onClick: () => saveWindow(preset.width, preset.height, preset.label), children: preset.label }, preset.label))), _jsx(Button, { size: "sm", emphasis: "ghost", onClick: resetWindow, children: "\u8DDF\u968F\u5E03\u5C40" })] }), _jsxs("span", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: ["\u5F53\u524D\uFF1A", windowPreset ?? '跟随布局推荐 / 默认 1280 × 800'] })] }) }), _jsx(Section, { title: "\u60AC\u6D6E\u7403", description: "\u7403\u9762\u5C3A\u5BF8\u4E0E\u505C\u6CCA\u884C\u4E3A\uFF1B\u7403\u5185\u663E\u793A\u5185\u5BB9\u7531\u4E1A\u52A1\u5957\u4EF6\u51B3\u5B9A\u3002", children: _jsxs(Stack, { gap: "md", children: [_jsx(Row, { gap: "sm", wrap: true, align: "center", children: BALL_SIZES.map(size => (_jsxs(Button, { size: "sm", intent: ballSize === size ? 'primary' : 'neutral', emphasis: ballSize === size ? 'solid' : 'outline', onClick: () => saveBall({ size }), children: [size, "px"] }, size))) }), _jsxs(Row, { gap: "lg", wrap: true, align: "center", children: [_jsx(Switch, { label: "\u542F\u7528\u60AC\u6D6E\u7403", checked: ballEnabled, onCheckedChange: enabled => saveBall({ enabled }) }), _jsx(Switch, { label: "\u5141\u8BB8\u8D34\u8FB9", checked: ballDockable, onCheckedChange: dockable => saveBall({ dockable }) }), _jsx(Switch, { label: "\u8D34\u8FB9\u540E\u6536\u8D77", checked: ballCollapse, onCheckedChange: collapse => saveBall({ collapse }) })] })] }) })] }) }));
|
|
129
|
+
}
|
|
130
|
+
export default AppearancePage;
|
|
131
|
+
//# sourceMappingURL=appearance.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in 插件管理 settings page: a category-grouped, flat list of
|
|
3
|
+
* installable pool plugins. Rows are one package each; enabling/disabling
|
|
4
|
+
* writes the same `plugins.yml` the file interface uses and asks for a restart
|
|
5
|
+
* because renderer rows only re-mount at boot.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/settings-pages/plugins
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@snap-rail/cordis';
|
|
10
|
+
import '@snap-rail/app-boot/contract';
|
|
11
|
+
import { type ReactNode } from 'react';
|
|
12
|
+
/** The plugin management page. */
|
|
13
|
+
export declare function PluginsPage({ ctx }: {
|
|
14
|
+
ctx: Context;
|
|
15
|
+
}): ReactNode;
|
|
16
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import '@snap-rail/app-boot/contract';
|
|
3
|
+
import { rpcErrorText } from '@snap-rail/connection';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { Badge, Button, EmptyState, Page, Section, Stack, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/index.js";
|
|
6
|
+
/** Human labels for the package kinds. */
|
|
7
|
+
const KIND_LABELS = {
|
|
8
|
+
skin: '界面风格',
|
|
9
|
+
driver: '通讯驱动',
|
|
10
|
+
suite: '业务套件',
|
|
11
|
+
plugin: '插件',
|
|
12
|
+
};
|
|
13
|
+
const PROFILE_LABELS = {
|
|
14
|
+
native: '皮肤原生',
|
|
15
|
+
integrated: '图表桥接',
|
|
16
|
+
custom: '自定义界面',
|
|
17
|
+
};
|
|
18
|
+
/** Collapse entry rows into package rows (one master switch per package). */
|
|
19
|
+
function packageRows(plugins) {
|
|
20
|
+
const byPackage = new Map();
|
|
21
|
+
for (const plugin of plugins) {
|
|
22
|
+
if (plugin.source === 'builtin')
|
|
23
|
+
continue;
|
|
24
|
+
const existing = byPackage.get(plugin.packageName);
|
|
25
|
+
if (existing !== undefined) {
|
|
26
|
+
existing.enabled = existing.enabled || plugin.enabled;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
byPackage.set(plugin.packageName, {
|
|
30
|
+
packageName: plugin.packageName,
|
|
31
|
+
title: plugin.title ?? plugin.packageName,
|
|
32
|
+
category: plugin.category ?? '其他',
|
|
33
|
+
kind: plugin.kind ?? 'plugin',
|
|
34
|
+
...plugin.version !== undefined ? { version: plugin.version } : {},
|
|
35
|
+
enabled: plugin.enabled,
|
|
36
|
+
source: plugin.source,
|
|
37
|
+
builtinDefault: plugin.source === 'builtin-default',
|
|
38
|
+
clientOnly: plugin.clientOnly === true,
|
|
39
|
+
...(plugin.uiProfile !== undefined ? { uiProfile: plugin.uiProfile } : {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
43
|
+
}
|
|
44
|
+
/** The plugin management page. */
|
|
45
|
+
export function PluginsPage({ ctx }) {
|
|
46
|
+
const [rows, setRows] = useState([]);
|
|
47
|
+
const [error, setError] = useState(undefined);
|
|
48
|
+
const [busy, setBusy] = useState(undefined);
|
|
49
|
+
const [touched, setTouched] = useState(new Set());
|
|
50
|
+
const load = () => {
|
|
51
|
+
setError(undefined);
|
|
52
|
+
void ctx.client.link.call('plugins.list', {}).then(result => {
|
|
53
|
+
if (!result.ok) {
|
|
54
|
+
setError(rpcErrorText(result.error));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setRows(packageRows(result.value.plugins));
|
|
58
|
+
}).catch(cause => {
|
|
59
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
useEffect(load, []);
|
|
63
|
+
const toggle = (row, enabled) => {
|
|
64
|
+
setBusy(row.packageName);
|
|
65
|
+
void ctx.client.link.call('plugins.set-enabled', { name: row.packageName, enabled })
|
|
66
|
+
.then(result => {
|
|
67
|
+
if (!result.ok) {
|
|
68
|
+
setError(rpcErrorText(result.error));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
setRows(current => current.map(item => item.packageName === row.packageName ? { ...item, enabled } : item));
|
|
72
|
+
setTouched(current => new Set(current).add(row.packageName));
|
|
73
|
+
})
|
|
74
|
+
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
75
|
+
.finally(() => { setBusy(undefined); });
|
|
76
|
+
};
|
|
77
|
+
const uninstall = (row) => {
|
|
78
|
+
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`))
|
|
79
|
+
return;
|
|
80
|
+
setBusy(row.packageName);
|
|
81
|
+
void ctx.client.link.call('plugins.uninstall', { name: row.packageName })
|
|
82
|
+
.then(result => {
|
|
83
|
+
if (!result.ok) {
|
|
84
|
+
setError(rpcErrorText(result.error));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
setTouched(current => new Set(current).add(row.packageName));
|
|
88
|
+
load();
|
|
89
|
+
})
|
|
90
|
+
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
91
|
+
.finally(() => { setBusy(undefined); });
|
|
92
|
+
};
|
|
93
|
+
const groups = new Map();
|
|
94
|
+
for (const row of rows) {
|
|
95
|
+
const bucket = groups.get(row.category);
|
|
96
|
+
if (bucket === undefined)
|
|
97
|
+
groups.set(row.category, [row]);
|
|
98
|
+
else
|
|
99
|
+
bucket.push(row);
|
|
100
|
+
}
|
|
101
|
+
return (_jsx(Page, { title: "\u63D2\u4EF6\u7BA1\u7406", description: "\u5B89\u88C5\u9A71\u52A8\u3001\u4E1A\u52A1\u9875\u9762\u548C\u754C\u9762\u98CE\u683C\u3002\u542F\u7528/\u505C\u7528\u5199\u5165 plugins.yml\uFF0C\u6E32\u67D3\u7AEF\u5728\u4E0B\u4E00\u6B21\u91CD\u542F\u540E\u751F\u6548\u3002", actions: _jsx(Button, { intent: "neutral", emphasis: "outline", onClick: load, children: "\u5237\u65B0" }), children: _jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx("div", { role: "alert", style: { color: 'var(--snap-color-danger)' }, children: error }), rows.length === 0
|
|
102
|
+
? _jsx(EmptyState, { title: "\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6", description: "\u628A\u63D2\u4EF6 zip \u62D6\u5165\u63D2\u4EF6\u5B89\u88C5\u5165\u53E3\uFF0C\u6216\u4ECE\u63D2\u4EF6\u6E90\u641C\u7D22\u5B89\u88C5\u3002" })
|
|
103
|
+
: [...groups.entries()].map(([category, entries]) => (_jsx(Section, { title: category, children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "\u540D\u79F0" }), _jsx(TableHead, { children: "\u7C7B\u578B" }), _jsx(TableHead, { children: "\u7248\u672C" }), _jsx(TableHead, { children: "\u72B6\u6001" }), _jsx(TableHead, { children: "\u64CD\u4F5C" })] }) }), _jsx(TableBody, { children: entries.map(row => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsxs("span", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [row.title, row.builtinDefault && _jsx(Badge, { intent: "neutral", children: "\u5185\u7F6E\u9ED8\u8BA4" })] }), _jsx("span", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-xs)' }, children: row.packageName })] }) }), _jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== undefined && (_jsx(Badge, { intent: "neutral", children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile }))] }), _jsx(TableCell, { children: row.version ?? '—' }), _jsx(TableCell, { children: row.builtinDefault
|
|
104
|
+
? _jsx(Badge, { intent: "success", children: "\u59CB\u7EC8\u968F\u5E95\u5EA7" })
|
|
105
|
+
: (_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [_jsx(Switch, { checked: row.enabled, disabled: busy === row.packageName, onCheckedChange: next => toggle(row, next), "aria-label": `启用 ${row.title}` }), touched.has(row.packageName) && _jsx(Badge, { intent: "warning", children: "\u5F85\u91CD\u542F" })] })) }), _jsx(TableCell, { children: row.builtinDefault
|
|
106
|
+
? _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u5185\u7F6E\u9ED8\u8BA4\u4E0D\u53EF\u5378\u8F7D" })
|
|
107
|
+
: (_jsx(Button, { intent: "danger", emphasis: "ghost", size: "sm", disabled: busy === row.packageName, onClick: () => uninstall(row), children: "\u5378\u8F7D" })) })] }, row.packageName))) })] }) }, category)))] }) }));
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in settings feature: a page registry plus the open/close state,
|
|
3
|
+
* the default trigger contribution, and the default settings surface. The
|
|
4
|
+
* shell is a semantic composition; a skin styles it, and any plugin may
|
|
5
|
+
* replace the entry or surface through the region slots.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/settings
|
|
8
|
+
*/
|
|
9
|
+
import { Context, type Plugin } from '@snap-rail/cordis';
|
|
10
|
+
import { type ReactNode } from 'react';
|
|
11
|
+
import { type SettingsPageInfo } from './contract.ts';
|
|
12
|
+
/** What one plugin contributes to the settings surface. */
|
|
13
|
+
export interface SettingsPageDefinition {
|
|
14
|
+
id: string;
|
|
15
|
+
title: string;
|
|
16
|
+
group?: string | undefined;
|
|
17
|
+
icon?: ReactNode;
|
|
18
|
+
order: number;
|
|
19
|
+
keywords?: readonly string[] | undefined;
|
|
20
|
+
render(): ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/** The settings registry and surface state exposed as `ctx.settings`. */
|
|
23
|
+
export interface SettingsService {
|
|
24
|
+
registerPage(caller: Context, page: SettingsPageDefinition): () => void;
|
|
25
|
+
listPages(): readonly SettingsPageDefinition[];
|
|
26
|
+
open(pageId?: string): void;
|
|
27
|
+
close(): void;
|
|
28
|
+
toggle(): void;
|
|
29
|
+
isOpen(): boolean;
|
|
30
|
+
activePage(): string | undefined;
|
|
31
|
+
subscribe(listener: () => void): () => void;
|
|
32
|
+
version(): number;
|
|
33
|
+
}
|
|
34
|
+
declare module '@snap-rail/cordis' {
|
|
35
|
+
interface Context {
|
|
36
|
+
settings: SettingsService;
|
|
37
|
+
}
|
|
38
|
+
interface Events {
|
|
39
|
+
'settings/pages-changed'(): void;
|
|
40
|
+
'settings/open-changed'(): void;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The default settings trigger; the layout decides placement/presentation. */
|
|
44
|
+
export declare function SettingsEntry(props: {
|
|
45
|
+
presentation: 'icon' | 'label';
|
|
46
|
+
open(): void;
|
|
47
|
+
isOpen: boolean;
|
|
48
|
+
}): ReactNode;
|
|
49
|
+
/** The default settings surface. */
|
|
50
|
+
export declare function SettingsSurface(props: {
|
|
51
|
+
service: SettingsService;
|
|
52
|
+
}): ReactNode;
|
|
53
|
+
/** Mount the settings registry and its default slot contributions. */
|
|
54
|
+
declare const settingsPlugin: Plugin.Object<void>;
|
|
55
|
+
/** The settings page info the slot context exposes. */
|
|
56
|
+
export declare function settingsPageInfo(page: SettingsPageDefinition): SettingsPageInfo;
|
|
57
|
+
export default settingsPlugin;
|
|
58
|
+
//# sourceMappingURL=settings.d.ts.map
|