@snap-rail/ui 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/charts.js +6 -29
- package/lib/contract.js +119 -78
- package/lib/fallback.js +11 -1
- package/lib/index.js +2466 -735
- package/lib/runtime.js +1552 -490
- package/lib/settings.js +1162 -244
- package/lib/skins.js +163 -189
- package/lib/types/charts.d.ts +1 -1
- package/lib/types/charts.js +5 -5
- package/lib/types/components/alert.d.ts +57 -0
- package/lib/types/components/alert.js +46 -0
- package/lib/types/components/controls.d.ts +74 -11
- package/lib/types/components/controls.js +60 -17
- package/lib/types/components/dialog.d.ts +5 -5
- package/lib/types/components/dialog.js +2 -2
- package/lib/types/components/form-rhf.d.ts +56 -0
- package/lib/types/components/form-rhf.js +74 -0
- package/lib/types/components/form.d.ts +33 -5
- package/lib/types/components/form.js +22 -6
- package/lib/types/components/index.d.ts +7 -0
- package/lib/types/components/index.js +7 -0
- package/lib/types/components/input.d.ts +16 -7
- package/lib/types/components/input.js +39 -9
- package/lib/types/components/layout.d.ts +32 -7
- package/lib/types/components/layout.js +88 -15
- package/lib/types/components/overlay.d.ts +95 -0
- package/lib/types/components/overlay.js +138 -0
- package/lib/types/components/schema-form.d.ts +16 -4
- package/lib/types/components/schema-form.js +69 -40
- package/lib/types/components/slider.d.ts +18 -0
- package/lib/types/components/slider.js +15 -0
- package/lib/types/contract.d.ts +49 -37
- package/lib/types/contract.js +49 -33
- package/lib/types/fallback.js +1 -1
- package/lib/types/runtime.d.ts +23 -1
- package/lib/types/runtime.js +77 -20
- package/lib/types/settings-pages/appearance.d.ts +6 -4
- package/lib/types/settings-pages/appearance.js +33 -36
- package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
- package/lib/types/settings-pages/plugin-feed.js +66 -0
- package/lib/types/settings-pages/plugins.d.ts +10 -5
- package/lib/types/settings-pages/plugins.js +284 -21
- package/lib/types/settings.d.ts +1 -0
- package/lib/types/settings.js +14 -8
- package/lib/types/skins.d.ts +38 -44
- package/lib/types/skins.js +172 -169
- package/package.json +16 -9
- package/src/styles/base.css +251 -5
- package/src/styles/default.css +315 -136
package/lib/types/runtime.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The built-in renderer runtime: it takes over the kernel root, mounts the
|
|
4
|
+
* core services, the skins, the layout/page plugins, and finally the fallback
|
|
5
|
+
* layout. There is no framework row and no framework seed: the substrate is
|
|
6
|
+
* always present, so a fresh install has a usable UI before any plugin is
|
|
7
|
+
* installed.
|
|
8
|
+
*
|
|
9
|
+
* @module @snap-rail/ui/runtime
|
|
10
|
+
*/
|
|
11
|
+
import { attachBallDrag as kernelAttachBallDrag } from '@snap-rail/client-kernel';
|
|
2
12
|
import { subscribeFrame } from '@snap-rail/connection';
|
|
3
13
|
import { settingsChangedSchema } from '@snap-rail/station-rpc/contract';
|
|
4
14
|
import { Context } from '@snap-rail/cordis';
|
|
5
15
|
import { TimerService as timerPlugin } from '@snap-rail/cordis-plugin-timer';
|
|
6
16
|
import { shellContract } from '@snap-rail/shell/contract';
|
|
7
|
-
import { createContext, useContext, useEffect, useSyncExternalStore } from 'react';
|
|
17
|
+
import { createContext, useContext, useEffect, useRef, useSyncExternalStore } from 'react';
|
|
8
18
|
import { createRoot } from 'react-dom/client';
|
|
9
19
|
import fallbackPlugin from "./fallback.js";
|
|
20
|
+
import { Toaster, TooltipProvider } from "./components/overlay.js";
|
|
10
21
|
import pagesPlugin from "./pages.js";
|
|
11
22
|
import settingsPlugin from "./settings.js";
|
|
12
23
|
import { UI_SLOT_IDS } from "./contract.js";
|
|
13
24
|
import { Slot, UiProvider, useActiveLayout, useUiVersion } from "./slots.js";
|
|
14
25
|
import slotsPlugin from "./slots.js";
|
|
15
|
-
import { SkinsProvider } from "./skins.js";
|
|
26
|
+
import { DEFAULT_DARK_ID, DEFAULT_LIGHT_ID, SkinsProvider } from "./skins.js";
|
|
16
27
|
import skinsPlugin from "./skins.js";
|
|
17
28
|
/** The React context carrying the host link/surface into builtin pages. */
|
|
18
29
|
const ClientContext = createContext(null);
|
|
@@ -27,6 +38,14 @@ export function useClient() {
|
|
|
27
38
|
throw new Error('useClient: no ClientProvider in the tree');
|
|
28
39
|
return service;
|
|
29
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Wire an element as a ball face's single drag/click surface. Past the travel
|
|
43
|
+
* threshold the face only signals `shell.ball.move` `begin`/`end`; the host
|
|
44
|
+
* anchors the grab from the OS cursor and runs the dock settle, so the face
|
|
45
|
+
* never streams coordinates. A press-release inside the threshold is the
|
|
46
|
+
* click. Returns the disposer removing every listener.
|
|
47
|
+
*/
|
|
48
|
+
export const attachBallDrag = kernelAttachBallDrag;
|
|
30
49
|
/** Re-render on settings open/page changes. */
|
|
31
50
|
function useSettingsVersion(ctx) {
|
|
32
51
|
return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
|
|
@@ -83,24 +102,63 @@ function SettingsFallbackHost(props) {
|
|
|
83
102
|
/** The operator-window root. */
|
|
84
103
|
function MainRoot(props) {
|
|
85
104
|
const layout = useActiveLayout();
|
|
86
|
-
return (
|
|
105
|
+
return (_jsx(_Fragment, { children: _jsxs(TooltipProvider, { 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 }), _jsx(Toaster, {})] }) }));
|
|
87
106
|
}
|
|
88
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* The fallback ball face used when no plugin occupies `shell.ball`: a themed
|
|
109
|
+
* disc that follows the active skin tokens (visible on any colour mode). The
|
|
110
|
+
* whole ball is one drag/click surface ({@link attachBallDrag}): press-move
|
|
111
|
+
* drags the window over `shell.ball.move`, a press-release summons the
|
|
112
|
+
* operator window — the same anatomy the kernel's crash fallback paints.
|
|
113
|
+
*/
|
|
89
114
|
function BallRoot(props) {
|
|
90
115
|
useUiVersion(props.ctx.ui);
|
|
91
116
|
const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
|
|
117
|
+
const link = props.ctx.client.link;
|
|
118
|
+
const hasOccupant = occupant !== undefined;
|
|
119
|
+
const rootRef = useRef(null);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (hasOccupant)
|
|
122
|
+
return undefined;
|
|
123
|
+
const element = rootRef.current;
|
|
124
|
+
if (element === null)
|
|
125
|
+
return undefined;
|
|
126
|
+
return attachBallDrag(element, {
|
|
127
|
+
link,
|
|
128
|
+
onClick: () => {
|
|
129
|
+
void link.call('shell.surface.present', { surface: 'main' });
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}, [hasOccupant, link]);
|
|
92
133
|
if (occupant !== undefined) {
|
|
93
|
-
return _jsx("div", { style: { width: '100%', height: '100%' }, children: occupant.render({ surface: 'ball' }) });
|
|
134
|
+
return (_jsxs(TooltipProvider, { children: [_jsx("div", { style: { width: '100%', height: '100%' }, children: occupant.render({ surface: 'ball' }) }), _jsx(Toaster, {})] }));
|
|
94
135
|
}
|
|
95
|
-
return (_jsx("div", { "data-snap-part": "ball.root", style: {
|
|
136
|
+
return (_jsx("div", { ref: rootRef, "data-snap-part": "ball.root", style: {
|
|
96
137
|
display: 'flex',
|
|
97
138
|
alignItems: 'center',
|
|
98
139
|
justifyContent: 'center',
|
|
99
140
|
width: '100%',
|
|
100
141
|
height: '100%',
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
142
|
+
}, children: _jsx("div", { "data-snap-part": "ball.orb", style: {
|
|
143
|
+
display: 'flex',
|
|
144
|
+
alignItems: 'center',
|
|
145
|
+
justifyContent: 'center',
|
|
146
|
+
width: 'calc(100% - 16px)',
|
|
147
|
+
height: 'calc(100% - 16px)',
|
|
148
|
+
borderRadius: '50%',
|
|
149
|
+
background: 'var(--snap-color-surface-raised)',
|
|
150
|
+
border: 'var(--snap-border-width) solid var(--snap-color-border)',
|
|
151
|
+
}, children: _jsx("button", { type: "button", "data-snap-part": "ball.core", title: "\u6253\u5F00\u4E3B\u7A97\u53E3", style: {
|
|
152
|
+
width: 'calc(100% - 16px)',
|
|
153
|
+
height: 'calc(100% - 16px)',
|
|
154
|
+
borderRadius: '50%',
|
|
155
|
+
border: 'none',
|
|
156
|
+
background: 'var(--snap-color-surface)',
|
|
157
|
+
color: 'var(--snap-color-text)',
|
|
158
|
+
fontSize: 'var(--snap-text-xs)',
|
|
159
|
+
fontWeight: 'var(--snap-weight-medium)',
|
|
160
|
+
cursor: 'default',
|
|
161
|
+
}, children: "snap-rail" }) }) }));
|
|
104
162
|
}
|
|
105
163
|
/** The root that mounts the layout (or the ball face) and the global overlays. */
|
|
106
164
|
function UiRoot(props) {
|
|
@@ -121,18 +179,17 @@ export async function createClientRuntime(handle, options) {
|
|
|
121
179
|
await ctx.plugin(pagesPlugin);
|
|
122
180
|
await ctx.plugin(skinsPlugin);
|
|
123
181
|
await ctx.plugin(settingsPlugin);
|
|
124
|
-
// The operator's theme
|
|
125
|
-
// skin service now and follow the settings/changed frame
|
|
182
|
+
// The operator's theme selection is a simple settings.json value (`{id}`);
|
|
183
|
+
// apply it to the skin service now and follow the settings/changed frame
|
|
184
|
+
// hot, so every surface (main window and ball alike) re-tokens in place. A
|
|
185
|
+
// legacy `{mode}` row maps onto the matching factory theme once, on read.
|
|
126
186
|
const applyThemeRow = (value) => {
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
ctx.skins.setMode(resolved);
|
|
134
|
-
if (typeof document !== 'undefined')
|
|
135
|
-
document.documentElement.dataset['mode'] = resolved;
|
|
187
|
+
const row = value;
|
|
188
|
+
const selection = typeof row?.id === 'string' && row.id !== ''
|
|
189
|
+
? row.id
|
|
190
|
+
: row?.mode === 'light' ? DEFAULT_LIGHT_ID : DEFAULT_DARK_ID;
|
|
191
|
+
if (!ctx.skins.activate(selection))
|
|
192
|
+
ctx.skins.activate(DEFAULT_DARK_ID);
|
|
136
193
|
};
|
|
137
194
|
void handle.link.call('settings.get', { key: 'ui.theme' })
|
|
138
195
|
.then(result => { if (result.ok)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The built-in 外观与显示 page:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The built-in 外观与显示 page: the theme (one flat list — the factory
|
|
3
|
+
* day/night pair plus every installed skin package), the operator window
|
|
4
|
+
* profile, and the floating-ball profile. Picking a loaded theme writes one
|
|
5
|
+
* settings row (`ui.theme {id}`) the runtime applies live; picking an
|
|
6
|
+
* unloaded skin package enables it first and the window reloads once, so the
|
|
7
|
+
* selection lands on boot.
|
|
6
8
|
*
|
|
7
9
|
* @module @snap-rail/ui/settings-pages/appearance
|
|
8
10
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { rpcErrorText
|
|
3
|
-
import { settingsChangedSchema } from '@snap-rail/station-rpc/contract';
|
|
2
|
+
import { rpcErrorText } from '@snap-rail/connection';
|
|
4
3
|
import { useEffect, useState } from 'react';
|
|
5
|
-
import {
|
|
4
|
+
import { Alert, Button, Page, Row, Section, Stack, Switch, Tabs, TabsList, TabsTrigger } from "../components/index.js";
|
|
5
|
+
import { useSkinId, useSkins } from "../skins.js";
|
|
6
6
|
import { useClient } from "../runtime.js";
|
|
7
7
|
const THEME_KEY = 'ui.theme';
|
|
8
8
|
const WINDOW_KEY = 'ui.window';
|
|
@@ -26,25 +26,21 @@ async function writeSetting(link, key, value) {
|
|
|
26
26
|
/** The appearance/display page. */
|
|
27
27
|
export function AppearancePage() {
|
|
28
28
|
const { link } = useClient();
|
|
29
|
-
const
|
|
29
|
+
const skins = useSkins();
|
|
30
|
+
const activeId = useSkinId();
|
|
31
|
+
const [packages, setPackages] = useState([]);
|
|
30
32
|
const [windowPreset, setWindowPreset] = useState(undefined);
|
|
31
33
|
const [ballSize, setBallSize] = useState(128);
|
|
32
34
|
const [ballEnabled, setBallEnabled] = useState(true);
|
|
33
|
-
const [ballDockable, setBallDockable] = useState(true);
|
|
34
35
|
const [ballCollapse, setBallCollapse] = useState(true);
|
|
35
|
-
const [skins, setSkins] = useState([]);
|
|
36
36
|
const [error, setError] = useState(undefined);
|
|
37
37
|
const [busy, setBusy] = useState(false);
|
|
38
38
|
useEffect(() => {
|
|
39
39
|
void Promise.all([
|
|
40
|
-
readSetting(link, THEME_KEY),
|
|
41
40
|
readSetting(link, WINDOW_KEY),
|
|
42
41
|
readSetting(link, BALL_KEY),
|
|
43
42
|
link.call('plugins.list', {}),
|
|
44
|
-
]).then(([
|
|
45
|
-
const themeMode = theme?.mode;
|
|
46
|
-
if (themeMode === 'system' || themeMode === 'light' || themeMode === 'dark')
|
|
47
|
-
setMode(themeMode);
|
|
43
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
48
44
|
const windowProfile = windowRow;
|
|
49
45
|
if (windowProfile !== null && windowProfile !== undefined && typeof windowProfile.width === 'number' && typeof windowProfile.height === 'number') {
|
|
50
46
|
const preset = WINDOW_PRESETS.find(item => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
@@ -55,30 +51,15 @@ export function AppearancePage() {
|
|
|
55
51
|
setBallSize(ballProfile.size);
|
|
56
52
|
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.enabled === 'boolean')
|
|
57
53
|
setBallEnabled(ballProfile.enabled);
|
|
58
|
-
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.dockable === 'boolean')
|
|
59
|
-
setBallDockable(ballProfile.dockable);
|
|
60
54
|
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.collapse === 'boolean')
|
|
61
55
|
setBallCollapse(ballProfile.collapse);
|
|
62
56
|
if (plugins.ok) {
|
|
63
|
-
|
|
57
|
+
setPackages(plugins.value.plugins
|
|
64
58
|
.filter(plugin => plugin.kind === 'skin' && plugin.source !== 'builtin')
|
|
65
59
|
.map(plugin => ({ name: plugin.packageName, title: plugin.title ?? plugin.packageName, enabled: plugin.enabled })));
|
|
66
60
|
}
|
|
67
61
|
}).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
62
|
}, [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
63
|
const saveWindow = (width, height, label) => {
|
|
83
64
|
setWindowPreset(label);
|
|
84
65
|
void writeSetting(link, WINDOW_KEY, { width, height, minWidth: 960, minHeight: 600 }).catch(cause => {
|
|
@@ -95,37 +76,53 @@ export function AppearancePage() {
|
|
|
95
76
|
const next = {
|
|
96
77
|
size: patch.size ?? ballSize,
|
|
97
78
|
enabled: patch.enabled ?? ballEnabled,
|
|
98
|
-
dockable: patch.dockable ?? ballDockable,
|
|
99
79
|
collapse: patch.collapse ?? ballCollapse,
|
|
100
80
|
};
|
|
101
81
|
if (patch.size !== undefined)
|
|
102
82
|
setBallSize(patch.size);
|
|
103
83
|
if (patch.enabled !== undefined)
|
|
104
84
|
setBallEnabled(patch.enabled);
|
|
105
|
-
if (patch.dockable !== undefined)
|
|
106
|
-
setBallDockable(patch.dockable);
|
|
107
85
|
if (patch.collapse !== undefined)
|
|
108
86
|
setBallCollapse(patch.collapse);
|
|
109
87
|
void writeSetting(link, BALL_KEY, next).catch(cause => {
|
|
110
88
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
111
89
|
});
|
|
112
90
|
};
|
|
113
|
-
|
|
91
|
+
// Loaded themes select through the settings row alone and the runtime
|
|
92
|
+
// re-tokens every surface in place. An unloaded package needs its row
|
|
93
|
+
// enabled first; the row change reloads the window and the stored
|
|
94
|
+
// selection activates on boot.
|
|
95
|
+
const tabs = [
|
|
96
|
+
...skins.list().map(row => ({ id: row.id, title: row.title })),
|
|
97
|
+
...packages.filter(pkg => !pkg.enabled).map(pkg => ({ id: pkg.name, title: pkg.title, enable: pkg.name })),
|
|
98
|
+
];
|
|
99
|
+
const selectTheme = (tab) => {
|
|
100
|
+
if (busy)
|
|
101
|
+
return;
|
|
102
|
+
if (tab.enable === undefined) {
|
|
103
|
+
void writeSetting(link, THEME_KEY, { id: tab.id }).catch(cause => {
|
|
104
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
114
108
|
setBusy(true);
|
|
115
|
-
void link.call('plugins.set-enabled', { name:
|
|
109
|
+
void link.call('plugins.set-enabled', { name: tab.enable, enabled: true })
|
|
116
110
|
.then(result => {
|
|
117
111
|
if (!result.ok) {
|
|
118
112
|
setError(rpcErrorText(result.error));
|
|
119
113
|
return;
|
|
120
114
|
}
|
|
121
|
-
|
|
115
|
+
setPackages(current => current.map(pkg => pkg.name === tab.enable ? { ...pkg, enabled: true } : pkg));
|
|
116
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
122
117
|
})
|
|
123
118
|
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
124
119
|
.finally(() => { setBusy(false); });
|
|
125
120
|
};
|
|
126
|
-
return (_jsx(Page, { title: "\u5916\u89C2\u4E0E\u663E\u793A", description: "\u4E3B\u9898\u3001\
|
|
127
|
-
|
|
128
|
-
|
|
121
|
+
return (_jsx(Page, { title: "\u5916\u89C2\u4E0E\u663E\u793A", description: "\u4E3B\u9898\u3001\u4E3B\u7A97\u53E3\u5C3A\u5BF8\u548C\u60AC\u6D6E\u7403\u5916\u89C2\u3002", children: _jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx(Alert, { intent: "danger", children: error }), _jsx(Section, { title: "\u4E3B\u9898", children: _jsx(Tabs, { value: activeId, onValueChange: value => {
|
|
122
|
+
const tab = tabs.find(item => item.id === value);
|
|
123
|
+
if (tab !== undefined)
|
|
124
|
+
selectTheme(tab);
|
|
125
|
+
}, children: _jsx(TabsList, { "aria-label": "\u4E3B\u9898", children: tabs.map(tab => (_jsx(TabsTrigger, { value: tab.id, disabled: busy, children: tab.title }, tab.id))) }) }) }), _jsx(Section, { title: "\u4E3B\u7A97\u53E3", 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\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\u6536\u8D77", checked: ballCollapse, onCheckedChange: collapse => saveBall({ collapse }) })] })] }) })] }) }));
|
|
129
126
|
}
|
|
130
127
|
export default AppearancePage;
|
|
131
128
|
//# sourceMappingURL=appearance.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin feed-source editor: the URL list the search and update sweep
|
|
3
|
+
* merge. Split out of the plugins page so the settings shell hosts the entry
|
|
4
|
+
* beside its own close control.
|
|
5
|
+
*
|
|
6
|
+
* @module @snap-rail/ui/settings-pages/plugin-feed
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@snap-rail/cordis';
|
|
9
|
+
import '@snap-rail/app-boot/contract';
|
|
10
|
+
import { type ReactNode } from 'react';
|
|
11
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
12
|
+
export declare function PluginFeedDialog(props: {
|
|
13
|
+
ctx: Context;
|
|
14
|
+
open: boolean;
|
|
15
|
+
onOpenChange: (open: boolean) => void;
|
|
16
|
+
}): ReactNode;
|
|
17
|
+
//# sourceMappingURL=plugin-feed.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PLUGINS_FEED_URLS_KEY } from '@snap-rail/app-boot/contract';
|
|
3
|
+
import '@snap-rail/app-boot/contract';
|
|
4
|
+
import { rpcErrorText } from '@snap-rail/connection';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { Button, Dialog, DialogBody, DialogContent, DialogFooter, DialogHeader, DialogTitle, Input, Stack } from "../components/index.js";
|
|
7
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
8
|
+
export function PluginFeedDialog(props) {
|
|
9
|
+
const { open } = props;
|
|
10
|
+
const link = props.ctx.client.link;
|
|
11
|
+
const [urls, setUrls] = useState([]);
|
|
12
|
+
const [draft, setDraft] = useState('');
|
|
13
|
+
const [error, setError] = useState(undefined);
|
|
14
|
+
// A fresh read per open; an empty read means the factory default list is
|
|
15
|
+
// in force.
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!open)
|
|
18
|
+
return;
|
|
19
|
+
void link.call('settings.get', { key: PLUGINS_FEED_URLS_KEY }).then(result => {
|
|
20
|
+
if (result.ok && Array.isArray(result.value.value)) {
|
|
21
|
+
setUrls(result.value.value.filter((entry) => typeof entry === 'string'));
|
|
22
|
+
}
|
|
23
|
+
}).catch(() => undefined);
|
|
24
|
+
}, [open, link]);
|
|
25
|
+
const save = () => {
|
|
26
|
+
for (const url of urls) {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = new URL(url);
|
|
29
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
30
|
+
throw new Error('protocol');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
setError('插件源地址需要以 http(s) 开头');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
setError(undefined);
|
|
38
|
+
void link.call('settings.set', { key: PLUGINS_FEED_URLS_KEY, value: urls }).then(result => {
|
|
39
|
+
if (!result.ok) {
|
|
40
|
+
setError(rpcErrorText(result.error));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
props.onOpenChange(false);
|
|
44
|
+
}).catch(cause => setError(String(cause)));
|
|
45
|
+
};
|
|
46
|
+
const append = () => {
|
|
47
|
+
const value = draft.trim();
|
|
48
|
+
if (value === '')
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
const parsed = new URL(value);
|
|
52
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
53
|
+
throw new Error('protocol');
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
setError('请填写 http(s) 开头的插件源地址');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setError(undefined);
|
|
60
|
+
setDraft('');
|
|
61
|
+
setUrls(current => current.includes(value) ? current : [...current, value]);
|
|
62
|
+
};
|
|
63
|
+
return (_jsx(Dialog, { open: open, onOpenChange: props.onOpenChange, children: _jsxs(DialogContent, { presentation: "modal", "aria-describedby": undefined, children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "\u63D2\u4EF6\u6E90" }) }), _jsx(DialogBody, { children: _jsxs(Stack, { gap: "sm", children: [urls.length === 0 && (_jsx("div", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: "\u5C1A\u672A\u6DFB\u52A0\u81EA\u5B9A\u4E49\u6E90\uFF08\u5F53\u524D\u4F7F\u7528\u51FA\u5382\u9ED8\u8BA4\u6E90\uFF09\u3002" })), urls.map((url, index) => (_jsxs("div", { style: { display: 'flex', gap: 'var(--snap-space-sm)', alignItems: 'center' }, children: [_jsx("span", { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontSize: 'var(--snap-text-xs)' }, children: url }), _jsx(Button, { intent: "neutral", emphasis: "ghost", size: "sm", "aria-label": `移除 ${url}`, onClick: () => setUrls(current => current.filter((_, at) => at !== index)), children: "\u2715" })] }, url))), _jsxs("div", { style: { display: 'flex', gap: 'var(--snap-space-sm)', width: '100%' }, children: [_jsx(Input, { value: draft, placeholder: "https://\u2026", style: { flex: 1, minWidth: 0 }, onChange: event => setDraft(event.target.value), onKeyDown: event => { if (event.key === 'Enter')
|
|
64
|
+
append(); } }), _jsx(Button, { intent: "neutral", emphasis: "outline", onClick: append, children: "\u6DFB\u52A0\u6E90" })] }), error !== undefined && (_jsx("div", { role: "alert", style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: error }))] }) }), _jsxs(DialogFooter, { children: [_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => props.onOpenChange(false), children: "\u53D6\u6D88" }), _jsx(Button, { intent: "primary", "data-plugins-feed-save": true, onClick: save, children: "\u4FDD\u5B58" })] })] }) }));
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=plugin-feed.js.map
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The built-in 插件管理 settings page: a
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The built-in 插件管理 settings page: a single flat table of installable
|
|
3
|
+
* pool plugins (one category cell per group, merged across its rows) plus
|
|
4
|
+
* the full install pipeline behind a header entry — a dialog holding the
|
|
5
|
+
* tri-form input (feed search term / http(s) address / local path) whose
|
|
6
|
+
* whole surface accepts a dropped .zip, the pending-update pills, and the
|
|
7
|
+
* inspect→confirm→install flow with its unverified-signature risk step.
|
|
8
|
+
* Every action rides the regular `plugins.*` wire methods — the same
|
|
9
|
+
* pipeline the kernel's recovery page bootstraps with (that page keeps its
|
|
10
|
+
* own self-contained copy: it renders precisely when this substrate is
|
|
11
|
+
* dead).
|
|
6
12
|
*
|
|
7
13
|
* @module @snap-rail/ui/settings-pages/plugins
|
|
8
14
|
*/
|
|
9
15
|
import type { Context } from '@snap-rail/cordis';
|
|
10
|
-
import '@snap-rail/app-boot/contract';
|
|
11
16
|
import { type ReactNode } from 'react';
|
|
12
17
|
/** The plugin management page. */
|
|
13
18
|
export declare function PluginsPage({ ctx }: {
|