@snap-rail/ui 0.1.0 → 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.
@@ -228,8 +228,4 @@ export const UI_COMPONENTS = {
228
228
  ],
229
229
  },
230
230
  };
231
- /** The presentation targets a skin may tune. */
232
- export const PRESENTATION_TARGETS = ['dialog', 'select', 'tabs', 'toast'];
233
- /** The presentation variants the core implements. */
234
- export const PRESENTATION_VARIANTS = ['modal', 'sheet', 'fullscreen', 'popover', 'segmented', 'inline'];
235
231
  //# sourceMappingURL=contract.js.map
@@ -22,7 +22,7 @@ function FallbackShell(props) {
22
22
  } }), _jsx(IconButton, { icon: _jsx(Glyph, { children: "\u2014" }), label: "\u6700\u5C0F\u5316", onClick: () => control('minimize') }), _jsx(IconButton, { icon: _jsx(Glyph, { children: "\u25A1" }), label: "\u6700\u5927\u5316\u5207\u6362", onClick: () => control('toggle-maximize') }), _jsx(IconButton, { icon: _jsx(Glyph, { children: "\u00D7" }), label: "\u5173\u95ED", onClick: () => control('close') })] })] }));
23
23
  return (_jsx(AppShell, { header: header, children: active !== undefined
24
24
  ? active.render()
25
- : (_jsx("div", { style: { display: 'flex', minHeight: '100%', alignItems: 'center', justifyContent: 'center', padding: 24 }, children: _jsx(EmptyState, { title: "\u5C1A\u672A\u6FC0\u6D3B\u4E1A\u52A1\u5957\u4EF6", description: "\u6253\u5F00\u8BBE\u7F6E\u7684\u300C\u63D2\u4EF6\u7BA1\u7406\u300D\u9875\uFF0C\u5B89\u88C5\u5E76\u542F\u7528\u4E00\u4E2A\u4E1A\u52A1\u5957\u4EF6\uFF1B\u9A71\u52A8\u4E5F\u5728\u540C\u4E00\u5904\u5B89\u88C5\u3002", action: _jsx(Button, { intent: "primary", onClick: () => props.ctx.settings.open('plugins'), children: "\u6253\u5F00\u8BBE\u7F6E" }) }) })) }));
25
+ : (_jsx("div", { style: { display: 'flex', minHeight: '100%', alignItems: 'center', justifyContent: 'center', padding: 24 }, children: _jsx(EmptyState, { title: "\u5C1A\u672A\u6FC0\u6D3B\u4E1A\u52A1\u5957\u4EF6", action: _jsx(Button, { intent: "primary", onClick: () => props.ctx.settings.open('plugins'), children: "\u6253\u5F00\u8BBE\u7F6E" }) }) })) }));
26
26
  }
27
27
  /** The fallback layout occupant. */
28
28
  const fallbackPlugin = {
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @module @snap-rail/ui/runtime
9
9
  */
10
- import type { ClientHandle } from '@snap-rail/client-kernel';
10
+ import { type ClientHandle } from '@snap-rail/client-kernel';
11
11
  import { type HostLink } from '@snap-rail/connection';
12
12
  import { Context, type Plugin } from '@snap-rail/cordis';
13
13
  import type { SurfaceId } from '@snap-rail/protocol';
@@ -38,6 +38,28 @@ export declare function ClientProvider(props: {
38
38
  }): ReactNode;
39
39
  /** Read the client services (host link + surface) from a builtin page. */
40
40
  export declare function useClient(): ClientServices;
41
+ /**
42
+ * Options for {@link attachBallDrag}. Declared here (not re-exported from the
43
+ * kernel) so the published substrate's d.ts stands alone: the kernel is
44
+ * app-internal and never reaches npm, while this module is a base seed every
45
+ * pool face can `require` at runtime.
46
+ */
47
+ export interface BallDragOptions {
48
+ /** The surface's host link; the drag rides `shell.ball.move`. */
49
+ link: HostLink;
50
+ /** Answered when a press-release never turned into a drag. */
51
+ onClick: () => void;
52
+ /** Pointer travel in px beyond which a press becomes a drag (default 4). */
53
+ threshold?: number;
54
+ }
55
+ /**
56
+ * Wire an element as a ball face's single drag/click surface. Past the travel
57
+ * threshold the face only signals `shell.ball.move` `begin`/`end`; the host
58
+ * anchors the grab from the OS cursor and runs the dock settle, so the face
59
+ * never streams coordinates. A press-release inside the threshold is the
60
+ * click. Returns the disposer removing every listener.
61
+ */
62
+ export declare const attachBallDrag: (element: HTMLElement, options: BallDragOptions) => () => void;
41
63
  /** One occupant seat. */
42
64
  export interface OccupantSpec {
43
65
  plugin: Plugin;
@@ -1,10 +1,20 @@
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";
10
20
  import pagesPlugin from "./pages.js";
@@ -12,7 +22,7 @@ import settingsPlugin from "./settings.js";
12
22
  import { UI_SLOT_IDS } from "./contract.js";
13
23
  import { Slot, UiProvider, useActiveLayout, useUiVersion } from "./slots.js";
14
24
  import slotsPlugin from "./slots.js";
15
- import { SkinsProvider } from "./skins.js";
25
+ import { DEFAULT_DARK_ID, DEFAULT_LIGHT_ID, SkinsProvider } from "./skins.js";
16
26
  import skinsPlugin from "./skins.js";
17
27
  /** The React context carrying the host link/surface into builtin pages. */
18
28
  const ClientContext = createContext(null);
@@ -27,6 +37,14 @@ export function useClient() {
27
37
  throw new Error('useClient: no ClientProvider in the tree');
28
38
  return service;
29
39
  }
40
+ /**
41
+ * Wire an element as a ball face's single drag/click surface. Past the travel
42
+ * threshold the face only signals `shell.ball.move` `begin`/`end`; the host
43
+ * anchors the grab from the OS cursor and runs the dock settle, so the face
44
+ * never streams coordinates. A press-release inside the threshold is the
45
+ * click. Returns the disposer removing every listener.
46
+ */
47
+ export const attachBallDrag = kernelAttachBallDrag;
30
48
  /** Re-render on settings open/page changes. */
31
49
  function useSettingsVersion(ctx) {
32
50
  return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
@@ -85,22 +103,61 @@ function MainRoot(props) {
85
103
  const layout = useActiveLayout();
86
104
  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
105
  }
88
- /** The fallback ball face used when no plugin occupies `shell.ball`. */
106
+ /**
107
+ * The fallback ball face used when no plugin occupies `shell.ball`: a themed
108
+ * disc that follows the active skin tokens (visible on any colour mode). The
109
+ * whole ball is one drag/click surface ({@link attachBallDrag}): press-move
110
+ * drags the window over `shell.ball.move`, a press-release summons the
111
+ * operator window — the same anatomy the kernel's crash fallback paints.
112
+ */
89
113
  function BallRoot(props) {
90
114
  useUiVersion(props.ctx.ui);
91
115
  const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
116
+ const link = props.ctx.client.link;
117
+ const hasOccupant = occupant !== undefined;
118
+ const rootRef = useRef(null);
119
+ useEffect(() => {
120
+ if (hasOccupant)
121
+ return undefined;
122
+ const element = rootRef.current;
123
+ if (element === null)
124
+ return undefined;
125
+ return attachBallDrag(element, {
126
+ link,
127
+ onClick: () => {
128
+ void link.call('shell.surface.present', { surface: 'main' });
129
+ },
130
+ });
131
+ }, [hasOccupant, link]);
92
132
  if (occupant !== undefined) {
93
133
  return _jsx("div", { style: { width: '100%', height: '100%' }, children: occupant.render({ surface: 'ball' }) });
94
134
  }
95
- return (_jsx("div", { "data-snap-part": "ball.root", style: {
135
+ return (_jsx("div", { ref: rootRef, "data-snap-part": "ball.root", style: {
96
136
  display: 'flex',
97
137
  alignItems: 'center',
98
138
  justifyContent: 'center',
99
139
  width: '100%',
100
140
  height: '100%',
101
- color: 'var(--snap-color-muted)',
102
- fontSize: 'var(--snap-text-xs)',
103
- }, children: "snap-rail" }));
141
+ }, children: _jsx("div", { "data-snap-part": "ball.orb", style: {
142
+ display: 'flex',
143
+ alignItems: 'center',
144
+ justifyContent: 'center',
145
+ width: 'calc(100% - 16px)',
146
+ height: 'calc(100% - 16px)',
147
+ borderRadius: '50%',
148
+ background: 'var(--snap-color-surface-raised)',
149
+ border: 'var(--snap-border-width) solid var(--snap-color-border)',
150
+ }, children: _jsx("button", { type: "button", "data-snap-part": "ball.core", title: "\u6253\u5F00\u4E3B\u7A97\u53E3", style: {
151
+ width: 'calc(100% - 16px)',
152
+ height: 'calc(100% - 16px)',
153
+ borderRadius: '50%',
154
+ border: 'none',
155
+ background: 'var(--snap-color-surface)',
156
+ color: 'var(--snap-color-text)',
157
+ fontSize: 'var(--snap-text-xs)',
158
+ fontWeight: 'var(--snap-weight-medium)',
159
+ cursor: 'default',
160
+ }, children: "snap-rail" }) }) }));
104
161
  }
105
162
  /** The root that mounts the layout (or the ball face) and the global overlays. */
106
163
  function UiRoot(props) {
@@ -121,18 +178,17 @@ export async function createClientRuntime(handle, options) {
121
178
  await ctx.plugin(pagesPlugin);
122
179
  await ctx.plugin(skinsPlugin);
123
180
  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.
181
+ // The operator's theme selection is a simple settings.json value (`{id}`);
182
+ // apply it to the skin service now and follow the settings/changed frame
183
+ // hot, so every surface (main window and ball alike) re-tokens in place. A
184
+ // legacy `{mode}` row maps onto the matching factory theme once, on read.
126
185
  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;
186
+ const row = value;
187
+ const selection = typeof row?.id === 'string' && row.id !== ''
188
+ ? row.id
189
+ : row?.mode === 'light' ? DEFAULT_LIGHT_ID : DEFAULT_DARK_ID;
190
+ if (!ctx.skins.activate(selection))
191
+ ctx.skins.activate(DEFAULT_DARK_ID);
136
192
  };
137
193
  void handle.link.call('settings.get', { key: 'ui.theme' })
138
194
  .then(result => { if (result.ok)
@@ -1,8 +1,10 @@
1
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.
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, subscribeFrame } from '@snap-rail/connection';
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 { Badge, Button, Page, Row, Section, Stack, Switch, Tabs, TabsList, TabsTrigger } from "../components/index.js";
4
+ import { 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 [mode, setMode] = useState('dark');
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(([theme, windowRow, ballRow, plugins]) => {
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
- setSkins(plugins.value.plugins
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
- const toggleSkin = (skin) => {
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: skin.name, enabled: !skin.enabled })
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
- setSkins(current => current.map(item => item.name === skin.name ? { ...item, enabled: !item.enabled } : item));
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\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 }) })] })] }) })] }) }));
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("div", { role: "alert", style: { color: 'var(--snap-color-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 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.
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 }: {