@snap-rail/ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/lib/charts.js +118 -0
- package/lib/contract.js +527 -0
- package/lib/fallback.js +399 -0
- package/lib/index.js +1282 -0
- package/lib/pages.js +68 -0
- package/lib/runtime.js +3003 -0
- package/lib/settings.js +2069 -0
- package/lib/skins.js +258 -0
- package/lib/slots.js +267 -0
- package/lib/types/charts.d.ts +62 -0
- package/lib/types/charts.js +41 -0
- package/lib/types/components/button.d.ts +39 -0
- package/lib/types/components/button.js +27 -0
- package/lib/types/components/controls.d.ts +66 -0
- package/lib/types/components/controls.js +66 -0
- package/lib/types/components/dialog.d.ts +58 -0
- package/lib/types/components/dialog.js +46 -0
- package/lib/types/components/feedback.d.ts +46 -0
- package/lib/types/components/feedback.js +20 -0
- package/lib/types/components/form.d.ts +31 -0
- package/lib/types/components/form.js +13 -0
- package/lib/types/components/index.d.ts +15 -0
- package/lib/types/components/index.js +15 -0
- package/lib/types/components/input.d.ts +40 -0
- package/lib/types/components/input.js +18 -0
- package/lib/types/components/layout.d.ts +103 -0
- package/lib/types/components/layout.js +80 -0
- package/lib/types/components/schema-form.d.ts +44 -0
- package/lib/types/components/schema-form.js +84 -0
- package/lib/types/components/surface.d.ts +49 -0
- package/lib/types/components/surface.js +59 -0
- package/lib/types/contract.d.ts +350 -0
- package/lib/types/contract.js +231 -0
- package/lib/types/fallback.d.ts +14 -0
- package/lib/types/fallback.js +50 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/index.js +19 -0
- package/lib/types/pages.d.ts +40 -0
- package/lib/types/pages.js +69 -0
- package/lib/types/runtime.d.ts +93 -0
- package/lib/types/runtime.js +233 -0
- package/lib/types/settings-pages/appearance.d.ts +15 -0
- package/lib/types/settings-pages/appearance.js +128 -0
- package/lib/types/settings-pages/index.d.ts +3 -0
- package/lib/types/settings-pages/index.js +3 -0
- package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
- package/lib/types/settings-pages/plugin-feed.js +66 -0
- package/lib/types/settings-pages/plugins.d.ts +21 -0
- package/lib/types/settings-pages/plugins.js +372 -0
- package/lib/types/settings.d.ts +59 -0
- package/lib/types/settings.js +176 -0
- package/lib/types/skins.d.ts +137 -0
- package/lib/types/skins.js +271 -0
- package/lib/types/slots.d.ts +69 -0
- package/lib/types/slots.js +210 -0
- package/lib/types/utils.d.ts +15 -0
- package/lib/types/utils.js +26 -0
- package/package.json +105 -3
- package/src/styles/base.css +329 -0
- package/src/styles/default.css +735 -0
- package/README.md +0 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in UI substrate's root barrel: semantic contract, region slots,
|
|
3
|
+
* skin registry, and (as they land) components, layout primitives, settings,
|
|
4
|
+
* charts, runtime, and fallback.
|
|
5
|
+
*
|
|
6
|
+
* @module @snap-rail/ui
|
|
7
|
+
*/
|
|
8
|
+
export * from "./contract.js";
|
|
9
|
+
export * from "./charts.js";
|
|
10
|
+
export * from "./components/index.js";
|
|
11
|
+
export * from "./fallback.js";
|
|
12
|
+
export * from "./pages.js";
|
|
13
|
+
export * from "./runtime.js";
|
|
14
|
+
export * from "./settings.js";
|
|
15
|
+
export * from "./slots.js";
|
|
16
|
+
export * from "./skins.js";
|
|
17
|
+
export { default as slotsPlugin } from "./slots.js";
|
|
18
|
+
export { default as skinsPlugin } from "./skins.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The main-page registry: business views contribute a page, a layout renders
|
|
3
|
+
* the active one. This is deliberately separate from settings pages and from
|
|
4
|
+
* the chrome slots; gating/workflows can wrap it later without changing the
|
|
5
|
+
* page authoring surface.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/pages
|
|
8
|
+
*/
|
|
9
|
+
import { Context, type Plugin } from '@snap-rail/cordis';
|
|
10
|
+
import { type ReactNode } from 'react';
|
|
11
|
+
/** One main page contributed by a plugin. */
|
|
12
|
+
export interface PageDefinition {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
order: number;
|
|
16
|
+
render(): ReactNode;
|
|
17
|
+
}
|
|
18
|
+
/** The page registry exposed as `ctx.pages`. */
|
|
19
|
+
export interface PagesService {
|
|
20
|
+
registerPage(caller: Context, page: PageDefinition): () => void;
|
|
21
|
+
list(): readonly PageDefinition[];
|
|
22
|
+
active(): PageDefinition | undefined;
|
|
23
|
+
setActive(id: string): void;
|
|
24
|
+
subscribe(listener: () => void): () => void;
|
|
25
|
+
version(): number;
|
|
26
|
+
}
|
|
27
|
+
declare module '@snap-rail/cordis' {
|
|
28
|
+
interface Context {
|
|
29
|
+
pages: PagesService;
|
|
30
|
+
}
|
|
31
|
+
interface Events {
|
|
32
|
+
'pages/changed'(): void;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Mount the page registry. */
|
|
36
|
+
declare const pagesPlugin: Plugin.Object<void>;
|
|
37
|
+
/** Re-render a layout when the page registry or active page changes. */
|
|
38
|
+
export declare function usePagesVersion(ctx: Context): number;
|
|
39
|
+
export default pagesPlugin;
|
|
40
|
+
//# sourceMappingURL=pages.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The main-page registry: business views contribute a page, a layout renders
|
|
3
|
+
* the active one. This is deliberately separate from settings pages and from
|
|
4
|
+
* the chrome slots; gating/workflows can wrap it later without changing the
|
|
5
|
+
* page authoring surface.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/pages
|
|
8
|
+
*/
|
|
9
|
+
import { useSyncExternalStore } from 'react';
|
|
10
|
+
/** Mount the page registry. */
|
|
11
|
+
const pagesPlugin = {
|
|
12
|
+
name: 'snap-rail ui pages',
|
|
13
|
+
apply(ctx) {
|
|
14
|
+
const pages = new Map();
|
|
15
|
+
const listeners = new Set();
|
|
16
|
+
let revision = 0;
|
|
17
|
+
let seq = 0;
|
|
18
|
+
let activeId;
|
|
19
|
+
const ordered = () => [...pages.values()]
|
|
20
|
+
.sort((a, b) => a.page.order - b.page.order || a.seq - b.seq)
|
|
21
|
+
.map(entry => entry.page);
|
|
22
|
+
const notify = () => {
|
|
23
|
+
revision += 1;
|
|
24
|
+
for (const listener of listeners)
|
|
25
|
+
listener();
|
|
26
|
+
ctx.emit('pages/changed');
|
|
27
|
+
};
|
|
28
|
+
const service = {
|
|
29
|
+
registerPage(caller, page) {
|
|
30
|
+
pages.set(page.id, { page, seq: seq++ });
|
|
31
|
+
activeId ??= page.id;
|
|
32
|
+
notify();
|
|
33
|
+
const remove = () => {
|
|
34
|
+
if (!pages.delete(page.id))
|
|
35
|
+
return;
|
|
36
|
+
if (activeId === page.id)
|
|
37
|
+
activeId = ordered()[0]?.id;
|
|
38
|
+
notify();
|
|
39
|
+
};
|
|
40
|
+
caller.effect(() => remove);
|
|
41
|
+
return remove;
|
|
42
|
+
},
|
|
43
|
+
list: ordered,
|
|
44
|
+
active() {
|
|
45
|
+
if (activeId === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
return pages.get(activeId)?.page ?? ordered()[0];
|
|
48
|
+
},
|
|
49
|
+
setActive(id) {
|
|
50
|
+
if (!pages.has(id) || activeId === id)
|
|
51
|
+
return;
|
|
52
|
+
activeId = id;
|
|
53
|
+
notify();
|
|
54
|
+
},
|
|
55
|
+
subscribe(listener) {
|
|
56
|
+
listeners.add(listener);
|
|
57
|
+
return () => { listeners.delete(listener); };
|
|
58
|
+
},
|
|
59
|
+
version: () => revision,
|
|
60
|
+
};
|
|
61
|
+
ctx.provide('pages', service);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
/** Re-render a layout when the page registry or active page changes. */
|
|
65
|
+
export function usePagesVersion(ctx) {
|
|
66
|
+
return useSyncExternalStore(ctx.pages.subscribe, ctx.pages.version, ctx.pages.version);
|
|
67
|
+
}
|
|
68
|
+
export default pagesPlugin;
|
|
69
|
+
//# sourceMappingURL=pages.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in renderer runtime: it takes over the kernel root, mounts the
|
|
3
|
+
* core services, the skins, the layout/page plugins, and finally the fallback
|
|
4
|
+
* layout. There is no framework row and no framework seed: the substrate is
|
|
5
|
+
* always present, so a fresh install has a usable UI before any plugin is
|
|
6
|
+
* installed.
|
|
7
|
+
*
|
|
8
|
+
* @module @snap-rail/ui/runtime
|
|
9
|
+
*/
|
|
10
|
+
import { type ClientHandle } from '@snap-rail/client-kernel';
|
|
11
|
+
import { type HostLink } from '@snap-rail/connection';
|
|
12
|
+
import { Context, type Plugin } from '@snap-rail/cordis';
|
|
13
|
+
import type { SurfaceId } from '@snap-rail/protocol';
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import fallbackPlugin from './fallback.tsx';
|
|
16
|
+
import pagesPlugin from './pages.tsx';
|
|
17
|
+
import type { SettingsPageDefinition } from './settings.tsx';
|
|
18
|
+
import settingsPlugin from './settings.tsx';
|
|
19
|
+
import { Slot } from './slots.tsx';
|
|
20
|
+
import slotsPlugin from './slots.tsx';
|
|
21
|
+
import skinsPlugin from './skins.tsx';
|
|
22
|
+
/** The shared services every occupant may consume. */
|
|
23
|
+
export interface ClientServices {
|
|
24
|
+
/** The typed host link shared by every occupant. */
|
|
25
|
+
link: HostLink;
|
|
26
|
+
/** Which window this client tree serves. */
|
|
27
|
+
surface: SurfaceId;
|
|
28
|
+
}
|
|
29
|
+
declare module '@snap-rail/cordis' {
|
|
30
|
+
interface Context {
|
|
31
|
+
client: ClientServices;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Provide the client services to builtin page components. */
|
|
35
|
+
export declare function ClientProvider(props: {
|
|
36
|
+
service: ClientServices;
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
}): ReactNode;
|
|
39
|
+
/** Read the client services (host link + surface) from a builtin page. */
|
|
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;
|
|
63
|
+
/** One occupant seat. */
|
|
64
|
+
export interface OccupantSpec {
|
|
65
|
+
plugin: Plugin;
|
|
66
|
+
config?: unknown;
|
|
67
|
+
}
|
|
68
|
+
/** Options for {@link createClientRuntime}. */
|
|
69
|
+
export interface RuntimeOptions {
|
|
70
|
+
/** Layout/page/feature plugins, already ordered by the boot loader. */
|
|
71
|
+
plugins: readonly (Plugin | OccupantSpec)[];
|
|
72
|
+
/** The window this runtime serves; defaults to `main`. */
|
|
73
|
+
surface?: SurfaceId;
|
|
74
|
+
/** Core settings pages registered by the app (equipment, about, ...). */
|
|
75
|
+
builtinPages?: readonly SettingsPageDefinition[];
|
|
76
|
+
}
|
|
77
|
+
/** The runtime handle. */
|
|
78
|
+
export interface RuntimeHandle {
|
|
79
|
+
ctx: Context;
|
|
80
|
+
dispose(): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Take over the kernel root and mount the UI substrate.
|
|
84
|
+
*
|
|
85
|
+
* @param handle - the kernel boot result.
|
|
86
|
+
* @param options - see {@link RuntimeOptions}.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createClientRuntime(handle: ClientHandle, options: RuntimeOptions): Promise<RuntimeHandle>;
|
|
89
|
+
/** The built-in fallback layout plugin (exported for tests and custom hosts). */
|
|
90
|
+
export { fallbackPlugin };
|
|
91
|
+
export { pagesPlugin, settingsPlugin, slotsPlugin, skinsPlugin };
|
|
92
|
+
export { Slot };
|
|
93
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,233 @@
|
|
|
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';
|
|
12
|
+
import { subscribeFrame } from '@snap-rail/connection';
|
|
13
|
+
import { settingsChangedSchema } from '@snap-rail/station-rpc/contract';
|
|
14
|
+
import { Context } from '@snap-rail/cordis';
|
|
15
|
+
import { TimerService as timerPlugin } from '@snap-rail/cordis-plugin-timer';
|
|
16
|
+
import { shellContract } from '@snap-rail/shell/contract';
|
|
17
|
+
import { createContext, useContext, useEffect, useRef, useSyncExternalStore } from 'react';
|
|
18
|
+
import { createRoot } from 'react-dom/client';
|
|
19
|
+
import fallbackPlugin from "./fallback.js";
|
|
20
|
+
import pagesPlugin from "./pages.js";
|
|
21
|
+
import settingsPlugin from "./settings.js";
|
|
22
|
+
import { UI_SLOT_IDS } from "./contract.js";
|
|
23
|
+
import { Slot, UiProvider, useActiveLayout, useUiVersion } from "./slots.js";
|
|
24
|
+
import slotsPlugin from "./slots.js";
|
|
25
|
+
import { DEFAULT_DARK_ID, DEFAULT_LIGHT_ID, SkinsProvider } from "./skins.js";
|
|
26
|
+
import skinsPlugin from "./skins.js";
|
|
27
|
+
/** The React context carrying the host link/surface into builtin pages. */
|
|
28
|
+
const ClientContext = createContext(null);
|
|
29
|
+
/** Provide the client services to builtin page components. */
|
|
30
|
+
export function ClientProvider(props) {
|
|
31
|
+
return _jsx(ClientContext.Provider, { value: props.service, children: props.children });
|
|
32
|
+
}
|
|
33
|
+
/** Read the client services (host link + surface) from a builtin page. */
|
|
34
|
+
export function useClient() {
|
|
35
|
+
const service = useContext(ClientContext);
|
|
36
|
+
if (service === null)
|
|
37
|
+
throw new Error('useClient: no ClientProvider in the tree');
|
|
38
|
+
return service;
|
|
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;
|
|
48
|
+
/** Re-render on settings open/page changes. */
|
|
49
|
+
function useSettingsVersion(ctx) {
|
|
50
|
+
return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
|
|
51
|
+
}
|
|
52
|
+
/** Apply the active layout's stage profiles to the host. */
|
|
53
|
+
function StageProfiles(props) {
|
|
54
|
+
const link = props.ctx.client.link;
|
|
55
|
+
const layout = props.layout;
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (layout?.window !== undefined) {
|
|
58
|
+
void link.call('shell.window.configure', { profile: layout.window }).catch(() => { });
|
|
59
|
+
}
|
|
60
|
+
if (layout?.ball !== undefined) {
|
|
61
|
+
void link.call('shell.ball.configure', { profile: layout.ball }).catch(() => { });
|
|
62
|
+
}
|
|
63
|
+
}, [layout?.id]);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/** The global overlay host: registry-owned surfaces do not depend on a layout. */
|
|
67
|
+
function OverlayHost(props) {
|
|
68
|
+
useUiVersion(props.ctx.ui);
|
|
69
|
+
useSettingsVersion(props.ctx);
|
|
70
|
+
const overlays = props.ctx.ui.list(UI_SLOT_IDS.overlay);
|
|
71
|
+
const settingsOpen = props.ctx.settings.isOpen();
|
|
72
|
+
const settingsSurfaces = settingsOpen ? props.ctx.ui.list(UI_SLOT_IDS.settingsSurface) : [];
|
|
73
|
+
const pages = props.ctx.settings.listPages().map(page => ({
|
|
74
|
+
id: page.id,
|
|
75
|
+
title: page.title,
|
|
76
|
+
...page.group !== undefined ? { group: page.group } : {},
|
|
77
|
+
order: page.order,
|
|
78
|
+
}));
|
|
79
|
+
const context = {
|
|
80
|
+
pages,
|
|
81
|
+
...props.ctx.settings.activePage() !== undefined ? { activeId: props.ctx.settings.activePage() } : {},
|
|
82
|
+
close: () => props.ctx.settings.close(),
|
|
83
|
+
};
|
|
84
|
+
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))] }));
|
|
85
|
+
}
|
|
86
|
+
/** The floating settings fallback, rendered only when no layout provides the seat. */
|
|
87
|
+
function SettingsFallbackHost(props) {
|
|
88
|
+
useUiVersion(props.ctx.ui);
|
|
89
|
+
useSettingsVersion(props.ctx);
|
|
90
|
+
if (props.ctx.ui.hasProvider(UI_SLOT_IDS.settingsEntry))
|
|
91
|
+
return null;
|
|
92
|
+
const entry = props.ctx.ui.list(UI_SLOT_IDS.settingsEntry)[0];
|
|
93
|
+
if (entry === undefined)
|
|
94
|
+
return null;
|
|
95
|
+
return (_jsx("div", { "data-snap-part": "settings.fallback", style: { position: 'fixed', right: 16, bottom: 16, zIndex: 'var(--snap-z-overlay)' }, children: entry.render({
|
|
96
|
+
presentation: 'icon',
|
|
97
|
+
open: () => props.ctx.settings.open(),
|
|
98
|
+
isOpen: props.ctx.settings.isOpen(),
|
|
99
|
+
}) }));
|
|
100
|
+
}
|
|
101
|
+
/** The operator-window root. */
|
|
102
|
+
function MainRoot(props) {
|
|
103
|
+
const layout = useActiveLayout();
|
|
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 })] }));
|
|
105
|
+
}
|
|
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
|
+
*/
|
|
113
|
+
function BallRoot(props) {
|
|
114
|
+
useUiVersion(props.ctx.ui);
|
|
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]);
|
|
132
|
+
if (occupant !== undefined) {
|
|
133
|
+
return _jsx("div", { style: { width: '100%', height: '100%' }, children: occupant.render({ surface: 'ball' }) });
|
|
134
|
+
}
|
|
135
|
+
return (_jsx("div", { ref: rootRef, "data-snap-part": "ball.root", style: {
|
|
136
|
+
display: 'flex',
|
|
137
|
+
alignItems: 'center',
|
|
138
|
+
justifyContent: 'center',
|
|
139
|
+
width: '100%',
|
|
140
|
+
height: '100%',
|
|
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" }) }) }));
|
|
161
|
+
}
|
|
162
|
+
/** The root that mounts the layout (or the ball face) and the global overlays. */
|
|
163
|
+
function UiRoot(props) {
|
|
164
|
+
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 }) }) }) }));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Take over the kernel root and mount the UI substrate.
|
|
168
|
+
*
|
|
169
|
+
* @param handle - the kernel boot result.
|
|
170
|
+
* @param options - see {@link RuntimeOptions}.
|
|
171
|
+
*/
|
|
172
|
+
export async function createClientRuntime(handle, options) {
|
|
173
|
+
const surface = options.surface ?? 'main';
|
|
174
|
+
const ctx = new Context();
|
|
175
|
+
ctx.provide('client', { link: handle.link, surface });
|
|
176
|
+
await ctx.plugin(timerPlugin);
|
|
177
|
+
await ctx.plugin(slotsPlugin);
|
|
178
|
+
await ctx.plugin(pagesPlugin);
|
|
179
|
+
await ctx.plugin(skinsPlugin);
|
|
180
|
+
await ctx.plugin(settingsPlugin);
|
|
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.
|
|
185
|
+
const applyThemeRow = (value) => {
|
|
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);
|
|
192
|
+
};
|
|
193
|
+
void handle.link.call('settings.get', { key: 'ui.theme' })
|
|
194
|
+
.then(result => { if (result.ok)
|
|
195
|
+
applyThemeRow(result.value.value); })
|
|
196
|
+
.catch(() => { });
|
|
197
|
+
const dropTheme = subscribeFrame(handle.link, 'settings/changed', settingsChangedSchema, change => {
|
|
198
|
+
if (change.key === 'ui.theme')
|
|
199
|
+
applyThemeRow(change.value);
|
|
200
|
+
});
|
|
201
|
+
const dropOpenSettings = subscribeFrame(handle.link, 'shell/settings-open-requested', shellContract.frames['shell/settings-open-requested'], () => { ctx.settings.open(); });
|
|
202
|
+
ctx.effect(() => () => {
|
|
203
|
+
dropTheme();
|
|
204
|
+
dropOpenSettings();
|
|
205
|
+
});
|
|
206
|
+
// Core settings pages ride the same registry as plugin pages; the app owns
|
|
207
|
+
// the equipment page component and hands it in here.
|
|
208
|
+
for (const page of options.builtinPages ?? [])
|
|
209
|
+
ctx.settings.registerPage(ctx, page);
|
|
210
|
+
for (const seat of options.plugins) {
|
|
211
|
+
const spec = 'plugin' in seat ? seat : { plugin: seat };
|
|
212
|
+
const plugin = spec.plugin;
|
|
213
|
+
await ctx.plugin(plugin, spec.config === undefined ? {} : spec.config);
|
|
214
|
+
}
|
|
215
|
+
// The fallback is a normal low-precedence layout occupant; a suite layout
|
|
216
|
+
// shadows it and its disposal brings the fallback back.
|
|
217
|
+
if (surface === 'main')
|
|
218
|
+
await ctx.plugin(fallbackPlugin);
|
|
219
|
+
handle.root.unmount();
|
|
220
|
+
const shellRoot = createRoot(handle.element);
|
|
221
|
+
shellRoot.render(_jsx(UiRoot, { ctx: ctx, surface: surface }));
|
|
222
|
+
return {
|
|
223
|
+
ctx,
|
|
224
|
+
dispose: () => ctx.fiber.dispose().then(() => {
|
|
225
|
+
shellRoot.unmount();
|
|
226
|
+
}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/** The built-in fallback layout plugin (exported for tests and custom hosts). */
|
|
230
|
+
export { fallbackPlugin };
|
|
231
|
+
export { pagesPlugin, settingsPlugin, slotsPlugin, skinsPlugin };
|
|
232
|
+
export { Slot };
|
|
233
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* @module @snap-rail/ui/settings-pages/appearance
|
|
10
|
+
*/
|
|
11
|
+
import { type ReactNode } from 'react';
|
|
12
|
+
/** The appearance/display page. */
|
|
13
|
+
export declare function AppearancePage(): ReactNode;
|
|
14
|
+
export default AppearancePage;
|
|
15
|
+
//# sourceMappingURL=appearance.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { rpcErrorText } from '@snap-rail/connection';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Button, Page, Row, Section, Stack, Switch, Tabs, TabsList, TabsTrigger } from "../components/index.js";
|
|
5
|
+
import { useSkinId, useSkins } from "../skins.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 skins = useSkins();
|
|
30
|
+
const activeId = useSkinId();
|
|
31
|
+
const [packages, setPackages] = useState([]);
|
|
32
|
+
const [windowPreset, setWindowPreset] = useState(undefined);
|
|
33
|
+
const [ballSize, setBallSize] = useState(128);
|
|
34
|
+
const [ballEnabled, setBallEnabled] = useState(true);
|
|
35
|
+
const [ballCollapse, setBallCollapse] = useState(true);
|
|
36
|
+
const [error, setError] = useState(undefined);
|
|
37
|
+
const [busy, setBusy] = useState(false);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
void Promise.all([
|
|
40
|
+
readSetting(link, WINDOW_KEY),
|
|
41
|
+
readSetting(link, BALL_KEY),
|
|
42
|
+
link.call('plugins.list', {}),
|
|
43
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
44
|
+
const windowProfile = windowRow;
|
|
45
|
+
if (windowProfile !== null && windowProfile !== undefined && typeof windowProfile.width === 'number' && typeof windowProfile.height === 'number') {
|
|
46
|
+
const preset = WINDOW_PRESETS.find(item => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
47
|
+
setWindowPreset(preset?.label);
|
|
48
|
+
}
|
|
49
|
+
const ballProfile = ballRow;
|
|
50
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.size === 'number')
|
|
51
|
+
setBallSize(ballProfile.size);
|
|
52
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.enabled === 'boolean')
|
|
53
|
+
setBallEnabled(ballProfile.enabled);
|
|
54
|
+
if (ballProfile !== null && ballProfile !== undefined && typeof ballProfile.collapse === 'boolean')
|
|
55
|
+
setBallCollapse(ballProfile.collapse);
|
|
56
|
+
if (plugins.ok) {
|
|
57
|
+
setPackages(plugins.value.plugins
|
|
58
|
+
.filter(plugin => plugin.kind === 'skin' && plugin.source !== 'builtin')
|
|
59
|
+
.map(plugin => ({ name: plugin.packageName, title: plugin.title ?? plugin.packageName, enabled: plugin.enabled })));
|
|
60
|
+
}
|
|
61
|
+
}).catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); });
|
|
62
|
+
}, [link]);
|
|
63
|
+
const saveWindow = (width, height, label) => {
|
|
64
|
+
setWindowPreset(label);
|
|
65
|
+
void writeSetting(link, WINDOW_KEY, { width, height, minWidth: 960, minHeight: 600 }).catch(cause => {
|
|
66
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const resetWindow = () => {
|
|
70
|
+
setWindowPreset(undefined);
|
|
71
|
+
void writeSetting(link, WINDOW_KEY, null).catch(cause => {
|
|
72
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const saveBall = (patch) => {
|
|
76
|
+
const next = {
|
|
77
|
+
size: patch.size ?? ballSize,
|
|
78
|
+
enabled: patch.enabled ?? ballEnabled,
|
|
79
|
+
collapse: patch.collapse ?? ballCollapse,
|
|
80
|
+
};
|
|
81
|
+
if (patch.size !== undefined)
|
|
82
|
+
setBallSize(patch.size);
|
|
83
|
+
if (patch.enabled !== undefined)
|
|
84
|
+
setBallEnabled(patch.enabled);
|
|
85
|
+
if (patch.collapse !== undefined)
|
|
86
|
+
setBallCollapse(patch.collapse);
|
|
87
|
+
void writeSetting(link, BALL_KEY, next).catch(cause => {
|
|
88
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
89
|
+
});
|
|
90
|
+
};
|
|
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
|
+
}
|
|
108
|
+
setBusy(true);
|
|
109
|
+
void link.call('plugins.set-enabled', { name: tab.enable, enabled: true })
|
|
110
|
+
.then(result => {
|
|
111
|
+
if (!result.ok) {
|
|
112
|
+
setError(rpcErrorText(result.error));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
setPackages(current => current.map(pkg => pkg.name === tab.enable ? { ...pkg, enabled: true } : pkg));
|
|
116
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
117
|
+
})
|
|
118
|
+
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
119
|
+
.finally(() => { setBusy(false); });
|
|
120
|
+
};
|
|
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 }) })] })] }) })] }) }));
|
|
126
|
+
}
|
|
127
|
+
export default AppearancePage;
|
|
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
|