@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,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
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
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).
|
|
12
|
+
*
|
|
13
|
+
* @module @snap-rail/ui/settings-pages/plugins
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from '@snap-rail/cordis';
|
|
16
|
+
import { type ReactNode } from 'react';
|
|
17
|
+
/** The plugin management page. */
|
|
18
|
+
export declare function PluginsPage({ ctx }: {
|
|
19
|
+
ctx: Context;
|
|
20
|
+
}): ReactNode;
|
|
21
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { rpcErrorText } from '@snap-rail/connection';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Badge, Button, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, EmptyState, IconButton, Input, Page, Stack, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/index.js";
|
|
5
|
+
/** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
|
|
6
|
+
* Electron or in tests. Inlined rather than imported from the app-internal
|
|
7
|
+
* kernel package: it never ships in the installer, and the packaged-app gate
|
|
8
|
+
* refuses any shipped `@snap-rail/ui` lib that requires it. */
|
|
9
|
+
function droppedZipPath(file) {
|
|
10
|
+
const zipPathOf = globalThis.snapRail?.zipPathOf;
|
|
11
|
+
if (typeof zipPathOf !== 'function')
|
|
12
|
+
return null;
|
|
13
|
+
return zipPathOf(file);
|
|
14
|
+
}
|
|
15
|
+
/** Human labels for the package kinds. */
|
|
16
|
+
const KIND_LABELS = {
|
|
17
|
+
skin: '界面风格',
|
|
18
|
+
driver: '通讯驱动',
|
|
19
|
+
suite: '业务套件',
|
|
20
|
+
plugin: '插件',
|
|
21
|
+
};
|
|
22
|
+
const PROFILE_LABELS = {
|
|
23
|
+
native: '皮肤原生',
|
|
24
|
+
integrated: '图表桥接',
|
|
25
|
+
custom: '自定义界面',
|
|
26
|
+
};
|
|
27
|
+
/** Search rows shown before the tail is folded into a counter. */
|
|
28
|
+
const SEARCH_ROW_CAP = 20;
|
|
29
|
+
/** The plus glyph for the page's install entry. */
|
|
30
|
+
function PlusIcon() {
|
|
31
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M12 5v14M5 12h14" }) }));
|
|
32
|
+
}
|
|
33
|
+
/** Collapse entry rows into package rows (one master switch per package). */
|
|
34
|
+
function packageRows(plugins) {
|
|
35
|
+
const byPackage = new Map();
|
|
36
|
+
for (const plugin of plugins) {
|
|
37
|
+
if (plugin.source === 'builtin')
|
|
38
|
+
continue;
|
|
39
|
+
const existing = byPackage.get(plugin.packageName);
|
|
40
|
+
if (existing !== undefined) {
|
|
41
|
+
existing.enabled = existing.enabled || plugin.enabled;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
byPackage.set(plugin.packageName, {
|
|
45
|
+
packageName: plugin.packageName,
|
|
46
|
+
title: plugin.title ?? plugin.packageName,
|
|
47
|
+
category: plugin.category ?? '其他',
|
|
48
|
+
kind: plugin.kind ?? 'plugin',
|
|
49
|
+
...plugin.version !== undefined ? { version: plugin.version } : {},
|
|
50
|
+
enabled: plugin.enabled,
|
|
51
|
+
source: plugin.source,
|
|
52
|
+
builtinDefault: plugin.source === 'builtin-default',
|
|
53
|
+
clientOnly: plugin.clientOnly === true,
|
|
54
|
+
...(plugin.uiProfile !== undefined ? { uiProfile: plugin.uiProfile } : {}),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
58
|
+
}
|
|
59
|
+
/** The preview's signature line (one row in the confirm card). */
|
|
60
|
+
function signatureText(signature, viaUrl) {
|
|
61
|
+
if (signature.state === 'verified') {
|
|
62
|
+
return { text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`, warning: false };
|
|
63
|
+
}
|
|
64
|
+
const detail = signature.keyId !== undefined ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : '⚠ 未签名';
|
|
65
|
+
return { text: viaUrl ? `${detail} · 直链无完整性校验` : detail, warning: true };
|
|
66
|
+
}
|
|
67
|
+
/** Does the input name an http(s) address? */
|
|
68
|
+
const isHttpUrl = (text) => /^https?:\/\//i.test(text);
|
|
69
|
+
/** Does the input look like a filesystem path (drive letter, UNC, posix
|
|
70
|
+
* root, or a .zip name with a separator in it)? */
|
|
71
|
+
const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith('\\\\') || text.startsWith('/')
|
|
72
|
+
|| (/\.zip$/i.test(text) && /[/\\]/.test(text));
|
|
73
|
+
/** The plugin management page. */
|
|
74
|
+
export function PluginsPage({ ctx }) {
|
|
75
|
+
const [rows, setRows] = useState([]);
|
|
76
|
+
const [error, setError] = useState(undefined);
|
|
77
|
+
const [busy, setBusy] = useState(undefined);
|
|
78
|
+
const [touched, setTouched] = useState(new Set());
|
|
79
|
+
const [restartNeeded, setRestartNeeded] = useState(false);
|
|
80
|
+
// The install pipeline: the tri-form dialog, its search results, and the
|
|
81
|
+
// inspect→confirm→install phase machine (mirrors the kernel recovery page).
|
|
82
|
+
const [installOpen, setInstallOpen] = useState(false);
|
|
83
|
+
const [phase, setPhase] = useState({ kind: 'idle' });
|
|
84
|
+
const [message, setMessage] = useState(undefined);
|
|
85
|
+
const [updates, setUpdates] = useState(new Map());
|
|
86
|
+
const [updatingName, setUpdatingName] = useState(undefined);
|
|
87
|
+
const [keyChange, setKeyChange] = useState(undefined);
|
|
88
|
+
const [query, setQuery] = useState('');
|
|
89
|
+
const [searchResults, setSearchResults] = useState(undefined);
|
|
90
|
+
const [searching, setSearching] = useState(false);
|
|
91
|
+
const [dragging, setDragging] = useState(false);
|
|
92
|
+
const link = ctx.client.link;
|
|
93
|
+
const load = () => {
|
|
94
|
+
setError(undefined);
|
|
95
|
+
void link.call('plugins.list', {}).then(result => {
|
|
96
|
+
if (!result.ok) {
|
|
97
|
+
setError(rpcErrorText(result.error));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
setRows(packageRows(result.value.plugins));
|
|
101
|
+
}).catch(cause => {
|
|
102
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
103
|
+
});
|
|
104
|
+
void link.call('plugins.updates-check', {}).then(result => {
|
|
105
|
+
if (result.ok)
|
|
106
|
+
setUpdates(new Map(result.value.updates.map(update => [update.name, update])));
|
|
107
|
+
}).catch(() => undefined);
|
|
108
|
+
};
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
load();
|
|
111
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
|
+
}, [link]);
|
|
113
|
+
const openInstall = () => {
|
|
114
|
+
setQuery('');
|
|
115
|
+
setSearchResults(undefined);
|
|
116
|
+
setMessage(undefined);
|
|
117
|
+
setDragging(false);
|
|
118
|
+
setInstallOpen(true);
|
|
119
|
+
};
|
|
120
|
+
const closeInstall = () => {
|
|
121
|
+
setInstallOpen(false);
|
|
122
|
+
setQuery('');
|
|
123
|
+
setSearchResults(undefined);
|
|
124
|
+
setMessage(undefined);
|
|
125
|
+
setDragging(false);
|
|
126
|
+
};
|
|
127
|
+
const toggle = (row, enabled) => {
|
|
128
|
+
setBusy(row.packageName);
|
|
129
|
+
void link.call('plugins.set-enabled', { name: row.packageName, enabled })
|
|
130
|
+
.then(result => {
|
|
131
|
+
if (!result.ok) {
|
|
132
|
+
setError(rpcErrorText(result.error));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
setRows(current => current.map(item => item.packageName === row.packageName ? { ...item, enabled } : item));
|
|
136
|
+
setTouched(current => new Set(current).add(row.packageName));
|
|
137
|
+
})
|
|
138
|
+
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
139
|
+
.finally(() => { setBusy(undefined); });
|
|
140
|
+
};
|
|
141
|
+
const uninstall = (row) => {
|
|
142
|
+
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`))
|
|
143
|
+
return;
|
|
144
|
+
setBusy(row.packageName);
|
|
145
|
+
void link.call('plugins.uninstall', { name: row.packageName })
|
|
146
|
+
.then(result => {
|
|
147
|
+
if (!result.ok) {
|
|
148
|
+
setError(rpcErrorText(result.error));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
setTouched(current => new Set(current).add(row.packageName));
|
|
152
|
+
setRestartNeeded(true);
|
|
153
|
+
load();
|
|
154
|
+
})
|
|
155
|
+
.catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
|
|
156
|
+
.finally(() => { setBusy(undefined); });
|
|
157
|
+
};
|
|
158
|
+
const inspectPath = (zipPath) => {
|
|
159
|
+
setMessage(undefined);
|
|
160
|
+
void link.call('plugins.inspect', { zipPath }).then(result => {
|
|
161
|
+
if (!result.ok) {
|
|
162
|
+
setPhase({ kind: 'error', message: `读取插件包失败:${rpcErrorText(result.error)}` });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
setPhase({ kind: 'confirm', zipPath, archive: result.value.archive, viaUrl: false, risk: false });
|
|
166
|
+
}).catch(cause => setPhase({ kind: 'error', message: String(cause) }));
|
|
167
|
+
};
|
|
168
|
+
const inspectFromUrl = (url) => {
|
|
169
|
+
setMessage(undefined);
|
|
170
|
+
void link.call('plugins.inspect-from-url', { url }).then(result => {
|
|
171
|
+
if (!result.ok) {
|
|
172
|
+
setPhase({ kind: 'error', message: `下载或读取插件包失败:${rpcErrorText(result.error)}` });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
setPhase({ kind: 'confirm', zipPath: result.value.zipPath, archive: result.value.archive, viaUrl: true, risk: false });
|
|
176
|
+
}).catch(cause => setPhase({ kind: 'error', message: String(cause) }));
|
|
177
|
+
};
|
|
178
|
+
const runInstall = (zipPath, archive) => {
|
|
179
|
+
setPhase({ kind: 'installing' });
|
|
180
|
+
const call = archive.kind === 'combo'
|
|
181
|
+
? link.call('plugins.install-combo', { zipPath })
|
|
182
|
+
: link.call('plugins.install', { zipPath });
|
|
183
|
+
void call.then(result => {
|
|
184
|
+
if (!result.ok) {
|
|
185
|
+
setPhase({ kind: 'error', message: `安装失败:${rpcErrorText(result.error)}` });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setPhase({ kind: 'idle' });
|
|
189
|
+
closeInstall();
|
|
190
|
+
setRestartNeeded(true);
|
|
191
|
+
load();
|
|
192
|
+
}).catch(cause => setPhase({ kind: 'error', message: String(cause) }));
|
|
193
|
+
};
|
|
194
|
+
/** The update pill's click: a plain update installs directly; a key
|
|
195
|
+
* change confirmation intercepts first. */
|
|
196
|
+
const requestUpdate = (update) => {
|
|
197
|
+
if (update.keyChanged === true) {
|
|
198
|
+
setKeyChange(update);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
updateNow(update.name);
|
|
202
|
+
};
|
|
203
|
+
/** The update itself: the feed's entry, no preview. */
|
|
204
|
+
const updateNow = (name) => {
|
|
205
|
+
setKeyChange(undefined);
|
|
206
|
+
setUpdatingName(name);
|
|
207
|
+
setMessage(undefined);
|
|
208
|
+
void link.call('plugins.remote-install', { name }).then(result => {
|
|
209
|
+
setUpdatingName(undefined);
|
|
210
|
+
if (!result.ok) {
|
|
211
|
+
setMessage({ kind: 'error', text: rpcErrorText(result.error) });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
setRestartNeeded(true);
|
|
215
|
+
load();
|
|
216
|
+
}).catch(() => setUpdatingName(undefined));
|
|
217
|
+
};
|
|
218
|
+
/** The tri-form input: address/path → inspect, anything else → feed search. */
|
|
219
|
+
const submitQuery = () => {
|
|
220
|
+
const text = query.trim();
|
|
221
|
+
if (text === '')
|
|
222
|
+
return;
|
|
223
|
+
setMessage(undefined);
|
|
224
|
+
if (isHttpUrl(text)) {
|
|
225
|
+
inspectFromUrl(text);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (looksLikePath(text)) {
|
|
229
|
+
inspectPath(text);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
runSearch(text);
|
|
233
|
+
};
|
|
234
|
+
const runSearch = (text) => {
|
|
235
|
+
setSearching(true);
|
|
236
|
+
setSearchResults(undefined);
|
|
237
|
+
void link.call('plugins.remote-list', {}).then(result => {
|
|
238
|
+
setSearching(false);
|
|
239
|
+
if (!result.ok) {
|
|
240
|
+
setMessage({ kind: 'error', text: `搜索失败:${rpcErrorText(result.error)}` });
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const needle = text.toLowerCase();
|
|
244
|
+
setSearchResults(result.value.plugins.filter(item => item.name.toLowerCase().includes(needle)
|
|
245
|
+
|| (item.title ?? '').toLowerCase().includes(needle)
|
|
246
|
+
|| (item.description ?? '').toLowerCase().includes(needle)));
|
|
247
|
+
}).catch(cause => {
|
|
248
|
+
setSearching(false);
|
|
249
|
+
setMessage({ kind: 'error', text: String(cause) });
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
/** A search-result entry that is not installed yet: preview first. The
|
|
253
|
+
* entry's own coordinates decide where the zip comes from — a federation
|
|
254
|
+
* row downloads from the author's release, a same-directory row from its
|
|
255
|
+
* feed base. */
|
|
256
|
+
const previewRemote = (item) => {
|
|
257
|
+
if (item.url !== undefined) {
|
|
258
|
+
inspectFromUrl(item.url);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (item.feedUrl === undefined || item.file === undefined)
|
|
262
|
+
return;
|
|
263
|
+
const base = item.feedUrl.endsWith('/') ? item.feedUrl : `${item.feedUrl}/`;
|
|
264
|
+
inspectFromUrl(`${base}${item.file}`);
|
|
265
|
+
};
|
|
266
|
+
const onDrop = (event) => {
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
setDragging(false);
|
|
269
|
+
const file = event.dataTransfer.files[0];
|
|
270
|
+
if (file === undefined)
|
|
271
|
+
return;
|
|
272
|
+
if (!file.name.toLowerCase().endsWith('.zip')) {
|
|
273
|
+
setMessage({ kind: 'error', text: '只支持 .zip 插件包或组合包' });
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const zipPath = droppedZipPath(file);
|
|
277
|
+
if (zipPath === null) {
|
|
278
|
+
setMessage({ kind: 'error', text: '当前环境不支持拖拽安装(缺少路径桥)' });
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
inspectPath(zipPath);
|
|
282
|
+
};
|
|
283
|
+
const restart = () => {
|
|
284
|
+
void link.call('window.relaunch', {});
|
|
285
|
+
};
|
|
286
|
+
const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
|
|
287
|
+
// Rows arrive category-sorted; one merged cell spans each category block.
|
|
288
|
+
const spans = new Map();
|
|
289
|
+
for (let index = 0; index < rows.length;) {
|
|
290
|
+
const category = rows[index].category;
|
|
291
|
+
let end = index + 1;
|
|
292
|
+
while (end < rows.length && rows[end].category === category)
|
|
293
|
+
end += 1;
|
|
294
|
+
spans.set(index, end - index);
|
|
295
|
+
index = end;
|
|
296
|
+
}
|
|
297
|
+
return (_jsxs(Page, { title: "\u63D2\u4EF6\u7BA1\u7406", titleExtra: _jsx(IconButton, { icon: _jsx(PlusIcon, {}), label: "\u5B89\u88C5\u63D2\u4EF6", onClick: openInstall }), actions: restartNeeded ? _jsx(Button, { intent: "primary", onClick: restart, children: "\u91CD\u542F\u751F\u6548" }) : undefined, children: [_jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx("div", { role: "alert", style: { color: 'var(--snap-color-danger)' }, children: error }), rows.length === 0
|
|
298
|
+
? (_jsx(EmptyState, { title: "\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6", action: _jsx(Button, { intent: "primary", onClick: openInstall, children: "\u5B89\u88C5\u63D2\u4EF6" }) }))
|
|
299
|
+
: (_jsxs(Table, { "data-plugins-table": true, children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { style: { width: '6em' }, children: "\u5206\u7C7B" }), _jsx(TableHead, { children: "\u540D\u79F0" }), _jsx(TableHead, { children: "\u7C7B\u578B" }), _jsx(TableHead, { children: "\u7248\u672C" }), _jsx(TableHead, { children: "\u72B6\u6001" }), _jsx(TableHead, { children: "\u64CD\u4F5C" })] }) }), _jsx(TableBody, { children: rows.map((row, index) => {
|
|
300
|
+
const update = updates.get(row.packageName);
|
|
301
|
+
const span = spans.get(index);
|
|
302
|
+
return (_jsxs(TableRow, { children: [span !== undefined && (_jsx(TableCell, { rowSpan: span, style: { verticalAlign: 'middle', color: 'var(--snap-color-muted)', fontWeight: 600 }, children: row.category })), _jsx(TableCell, { children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsxs("span", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [row.title, row.builtinDefault && _jsx(Badge, { intent: "neutral", children: "\u5185\u7F6E\u9ED8\u8BA4" })] }), _jsx("span", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-xs)' }, children: row.packageName })] }) }), _jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== undefined && (_jsx(Badge, { intent: "neutral", children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile }))] }), _jsx(TableCell, { children: update !== undefined
|
|
303
|
+
? (_jsx(Button, { intent: "primary", emphasis: "ghost", size: "sm", title: update.keyChanged === true
|
|
304
|
+
? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更`
|
|
305
|
+
: `当前 ${update.installedVersion} → ${update.feedVersion}`, disabled: updatingName === row.packageName, onClick: () => requestUpdate(update), children: updatingName === row.packageName ? '更新中…' : `⟳ ${update.feedVersion}` }))
|
|
306
|
+
: (row.version ?? '—') }), _jsx(TableCell, { children: row.builtinDefault
|
|
307
|
+
? _jsx(Switch, { checked: true, disabled: true, "aria-label": `启用 ${row.title}` })
|
|
308
|
+
: (_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [_jsx(Switch, { checked: row.enabled, disabled: busy === row.packageName, onCheckedChange: next => toggle(row, next), "aria-label": `启用 ${row.title}` }), touched.has(row.packageName) && _jsx(Badge, { intent: "warning", children: "\u5F85\u91CD\u542F" })] })) }), _jsx(TableCell, { children: row.builtinDefault
|
|
309
|
+
? _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u5185\u7F6E\u9ED8\u8BA4\u4E0D\u53EF\u5378\u8F7D" })
|
|
310
|
+
: (_jsx(Button, { intent: "danger", emphasis: "ghost", size: "sm", disabled: busy === row.packageName, onClick: () => uninstall(row), children: "\u5378\u8F7D" })) })] }, row.packageName));
|
|
311
|
+
}) })] }))] }), _jsx(Dialog, { open: installOpen, onOpenChange: next => { if (!next)
|
|
312
|
+
closeInstall(); }, children: _jsxs(DialogContent, { presentation: "modal", size: "lg", "data-plugins-dropzone": true, "aria-describedby": undefined, onDragOver: event => {
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
setDragging(true);
|
|
315
|
+
}, onDragLeave: event => {
|
|
316
|
+
if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget))
|
|
317
|
+
setDragging(false);
|
|
318
|
+
}, onDrop: onDrop, children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "\u5B89\u88C5\u63D2\u4EF6" }) }), _jsx(DialogBody, { children: _jsxs(Stack, { gap: "sm", children: [_jsx("div", { "data-plugins-drop-hint": true, style: {
|
|
319
|
+
height: 'calc(var(--snap-control-height-md) * 3)',
|
|
320
|
+
display: 'flex',
|
|
321
|
+
alignItems: 'center',
|
|
322
|
+
justifyContent: 'center',
|
|
323
|
+
border: `1px dashed ${dragging ? 'var(--snap-color-accent)' : 'var(--snap-color-border)'}`,
|
|
324
|
+
borderRadius: 'var(--snap-radius-md)',
|
|
325
|
+
background: dragging ? 'color-mix(in srgb, var(--snap-color-accent) 10%, transparent)' : 'transparent',
|
|
326
|
+
color: 'var(--snap-color-muted)',
|
|
327
|
+
fontSize: 'var(--snap-text-sm)',
|
|
328
|
+
}, children: dragging ? '释放以安装' : '拖入 .zip 安装' }), _jsxs("div", { style: { display: 'flex', gap: 'var(--snap-space-sm)' }, children: [_jsx(Input, { value: query, placeholder: "\u672C\u5730\u8DEF\u5F84 / https://\u2026 / \u63D2\u4EF6\u540D", style: { flex: 1, minWidth: 0 }, onChange: event => setQuery(event.target.value), onKeyDown: event => { if (event.key === 'Enter')
|
|
329
|
+
submitQuery(); } }), _jsx(Button, { intent: "neutral", emphasis: "outline", disabled: searching, onClick: submitQuery, children: searching ? '搜索中…' : '搜索' })] }), message !== undefined && (_jsx("div", { role: message.kind === 'error' ? 'alert' : 'status', style: { fontSize: 'var(--snap-text-xs)', color: message.kind === 'error' ? 'var(--snap-color-danger)' : 'var(--snap-color-muted)' }, children: message.text })), visibleResults !== undefined && (_jsxs(Stack, { gap: "sm", children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [_jsxs("span", { style: { fontSize: 'var(--snap-text-sm)', color: 'var(--snap-color-muted)' }, children: ["\u641C\u7D22\u201C", query.trim(), "\u201D\uFF08", searchResults?.length ?? 0, "\uFF09"] }), _jsx(Button, { intent: "neutral", emphasis: "ghost", size: "sm", onClick: () => setSearchResults(undefined), children: "\u2715" })] }), visibleResults.length === 0 && (_jsx("div", { style: { padding: '12px 0', textAlign: 'center', color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: "\u6CA1\u6709\u5339\u914D\u7684\u63D2\u4EF6\u3002" })), visibleResults.map(item => {
|
|
330
|
+
const installed = item.installed !== undefined;
|
|
331
|
+
return (_jsxs("div", { style: {
|
|
332
|
+
display: 'flex', gap: 'var(--snap-space-md)', alignItems: 'center',
|
|
333
|
+
justifyContent: 'space-between', borderBottom: '1px solid var(--snap-color-border)', paddingBottom: 'var(--snap-space-sm)',
|
|
334
|
+
}, children: [_jsxs("div", { style: { minWidth: 0 }, children: [_jsxs("div", { style: { display: 'flex', gap: 'var(--snap-space-sm)', alignItems: 'center' }, children: [item.title ?? item.name, item.source !== undefined && _jsx(Badge, { intent: "neutral", children: item.source })] }), _jsxs("div", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: [item.name, " \u00B7 ", item.version] })] }), item.action === 'install'
|
|
335
|
+
? _jsx(Button, { intent: "primary", emphasis: "outline", size: "sm", onClick: () => previewRemote(item), children: "\u5B89\u88C5" })
|
|
336
|
+
: item.action === 'update' && installed
|
|
337
|
+
? (_jsx(Button, { intent: "primary", emphasis: "ghost", size: "sm", title: `当前 ${item.installed?.version} → ${item.version}`, disabled: updatingName === item.name, onClick: () => requestUpdate({
|
|
338
|
+
name: item.name,
|
|
339
|
+
installedVersion: item.installed?.version ?? '',
|
|
340
|
+
feedVersion: item.version,
|
|
341
|
+
}), children: updatingName === item.name ? '更新中…' : `⟳ ${item.version}` }))
|
|
342
|
+
: _jsx("span", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: item.action === 'current' ? '已是最新' : '本地更新' })] }, item.name));
|
|
343
|
+
}), (searchResults?.length ?? 0) > SEARCH_ROW_CAP && (_jsxs("div", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: ["\u5DF2\u663E\u793A\u524D ", SEARCH_ROW_CAP, " \u6761\uFF0C\u5171 ", searchResults?.length, " \u6761\u3002"] }))] }))] }) })] }) }), _jsx(Dialog, { open: phase.kind === 'confirm' || phase.kind === 'installing' || phase.kind === 'error', onOpenChange: next => {
|
|
344
|
+
if (!next && phase.kind !== 'installing')
|
|
345
|
+
setPhase({ kind: 'idle' });
|
|
346
|
+
}, children: _jsxs(DialogContent, { presentation: "modal", "aria-describedby": undefined, children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: phase.kind === 'confirm'
|
|
347
|
+
? phase.archive.kind === 'combo'
|
|
348
|
+
? '安装组合套件'
|
|
349
|
+
: phase.archive.plugin.action === 'update' ? '更新插件' : '安装插件'
|
|
350
|
+
: phase.kind === 'error' ? '安装失败' : '正在安装…' }), phase.kind === 'confirm' && phase.archive.kind === 'combo' && (_jsx(DialogDescription, { children: `${phase.archive.combo.title} · ${phase.archive.combo.id}` }))] }), _jsxs(DialogBody, { children: [phase.kind === 'error' && (_jsx("div", { style: { color: 'var(--snap-color-danger)', whiteSpace: 'pre-wrap', fontSize: 'var(--snap-text-sm)' }, children: phase.message })), phase.kind === 'confirm' && phase.archive.kind === 'combo' && (_jsxs(Stack, { gap: "sm", children: [phase.archive.combo.description !== undefined && (_jsx("div", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: phase.archive.combo.description })), _jsxs("div", { style: { display: 'grid', gap: 'var(--snap-space-xs)', fontSize: 'var(--snap-text-sm)' }, children: [_jsxs("div", { children: ["\u63D2\u4EF6\uFF08", phase.archive.combo.plugins.length, "\uFF09"] }), phase.archive.combo.plugins.map(plugin => {
|
|
351
|
+
const line = signatureText(plugin.signature, phase.viaUrl);
|
|
352
|
+
const action = plugin.action === 'install' ? '安装' : plugin.action === 'update' ? '更新' : '保留';
|
|
353
|
+
return (_jsxs("div", { style: { color: line.warning ? 'var(--snap-color-warning)' : undefined }, children: [plugin.title ?? plugin.name, " ", plugin.version, " \u00B7 ", action, line.warning ? ' · ⚠ 未验证' : ''] }, plugin.name));
|
|
354
|
+
})] }), phase.archive.combo.missing.length > 0 && (_jsxs("div", { style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: ["\u7F3A\u5C11\u4F9D\u8D56\uFF1A", phase.archive.combo.missing.join('、')] }))] })), phase.kind === 'confirm' && phase.archive.kind === 'plugin' && (_jsxs(Stack, { gap: "sm", children: [phase.risk ? (_jsx("div", { "data-plugins-risk": true, style: { color: 'var(--snap-color-warning)', fontWeight: 600 }, children: "\u26A0 \u6B64\u63D2\u4EF6\u672A\u7ECF\u53D1\u5E03\u8005\u9A8C\u8BC1" })) : undefined, !phase.risk && (_jsxs(Stack, { gap: "sm", children: [phase.archive.plugin.title !== undefined && _jsxs("div", { children: ["\u540D\u79F0\uFF1A", phase.archive.plugin.title] }), _jsxs("div", { children: ["\u5305\u540D\uFF1A", phase.archive.plugin.name] }), phase.archive.plugin.action === 'update'
|
|
355
|
+
? (_jsxs(_Fragment, { children: [_jsxs("div", { children: ["\u5DF2\u5B89\u88C5\u7248\u672C\uFF1A", phase.archive.plugin.installed?.version] }), _jsxs("div", { children: ["\u5C06\u66F4\u65B0\u81F3\uFF1A", phase.archive.plugin.version] })] }))
|
|
356
|
+
: _jsxs("div", { children: ["\u7248\u672C\uFF1A", phase.archive.plugin.version] })] })), (() => {
|
|
357
|
+
const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
|
|
358
|
+
return (_jsxs("div", { "data-plugins-signature": phase.archive.plugin.signature.state, style: { color: line.warning ? 'var(--snap-color-warning)' : undefined }, children: ["\u7B7E\u540D\uFF1A", line.text] }));
|
|
359
|
+
})(), !phase.risk && (_jsxs(Stack, { gap: "sm", children: [_jsxs("div", { children: ["\u6743\u9650\uFF1A", phase.archive.plugin.permissions.length === 0 ? '无' : phase.archive.plugin.permissions.join('、')] }), phase.archive.plugin.missing.length > 0 && (_jsxs("div", { style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: ["\u7F3A\u5C11\u4F9D\u8D56\uFF1A", phase.archive.plugin.missing.join('、')] })), phase.archive.plugin.action === 'blocked' && (_jsxs("div", { style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: ["\u5DF2\u5B89\u88C5 v", phase.archive.plugin.installed?.version, "\uFF0C\u5B89\u88C5\u5305 v", phase.archive.plugin.version, " \u4E0D\u9AD8\u4E8E\u5DF2\u88C5\u7248\u672C\uFF0C\u65E0\u6CD5\u8986\u76D6\u3002"] }))] })), phase.risk && (_jsx("div", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: phase.archive.plugin.signature.keyId !== undefined
|
|
360
|
+
? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。`
|
|
361
|
+
: '这个包没有携带任何签名,也没有任何完整性校验。' }))] }))] }), _jsxs(DialogFooter, { children: [phase.kind === 'error' && (_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => setPhase({ kind: 'idle' }), children: "\u8FD4\u56DE" })), phase.kind === 'confirm' && (_jsxs(_Fragment, { children: [_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => setPhase({ kind: 'idle' }), children: "\u53D6\u6D88" }), phase.risk
|
|
362
|
+
? (_jsx(Button, { intent: "primary", "data-plugins-risk-confirm": true, onClick: () => runInstall(phase.zipPath, phase.archive), children: "\u6211\u77E5\u6653\u98CE\u9669\uFF0C\u4ECD\u8981\u5B89\u88C5" }))
|
|
363
|
+
: (_jsx(Button, { intent: "primary", "data-plugins-install-confirm": true, disabled: phase.archive.kind === 'plugin' && phase.archive.plugin.action === 'blocked', onClick: () => {
|
|
364
|
+
if (phase.archive.kind === 'plugin' && phase.archive.plugin.signature.state === 'unverified') {
|
|
365
|
+
setPhase({ ...phase, risk: true });
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
runInstall(phase.zipPath, phase.archive);
|
|
369
|
+
}, children: phase.archive.kind === 'combo' ? '安装组合' : phase.archive.plugin.action === 'update' ? '更新' : '安装' }))] })), phase.kind === 'installing' && _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u6B63\u5728\u5B89\u88C5\u2026" })] })] }) }), _jsx(Dialog, { open: keyChange !== undefined, onOpenChange: next => { if (!next)
|
|
370
|
+
setKeyChange(undefined); }, children: _jsxs(DialogContent, { presentation: "modal", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "\u53D1\u5E03\u8005\u5BC6\u94A5\u5DF2\u53D8\u66F4" }), _jsxs(DialogDescription, { children: [keyChange?.name, " \u7684\u65B0\u7248\u672C\u7531\u4E0D\u540C\u7684\u5BC6\u94A5\u7B7E\u540D\u3002"] })] }), _jsx(DialogBody, { children: keyChange !== undefined && (_jsxs("div", { style: { fontSize: 'var(--snap-text-sm)' }, children: ["\u5DF2\u5B89\u88C5 v", keyChange.installedVersion, " \u2192 \u6E90\u4E0A v", keyChange.feedVersion, "\u3002"] })) }), _jsxs(DialogFooter, { children: [_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => setKeyChange(undefined), children: "\u53D6\u6D88" }), _jsx(Button, { intent: "primary", "data-plugins-keychange-confirm": true, onClick: () => keyChange !== undefined && updateNow(keyChange.name), children: "\u4ECD\u8981\u66F4\u65B0" })] })] }) })] }));
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in settings feature: a page registry plus the open/close state,
|
|
3
|
+
* the default trigger contribution, and the default settings surface. The
|
|
4
|
+
* shell is a semantic composition; a skin styles it, and any plugin may
|
|
5
|
+
* replace the entry or surface through the region slots.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/settings
|
|
8
|
+
*/
|
|
9
|
+
import { Context, type Plugin } from '@snap-rail/cordis';
|
|
10
|
+
import { type ReactNode } from 'react';
|
|
11
|
+
import { type SettingsPageInfo } from './contract.ts';
|
|
12
|
+
/** What one plugin contributes to the settings surface. */
|
|
13
|
+
export interface SettingsPageDefinition {
|
|
14
|
+
id: string;
|
|
15
|
+
title: string;
|
|
16
|
+
group?: string | undefined;
|
|
17
|
+
icon?: ReactNode;
|
|
18
|
+
order: number;
|
|
19
|
+
keywords?: readonly string[] | undefined;
|
|
20
|
+
render(): ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/** The settings registry and surface state exposed as `ctx.settings`. */
|
|
23
|
+
export interface SettingsService {
|
|
24
|
+
registerPage(caller: Context, page: SettingsPageDefinition): () => void;
|
|
25
|
+
listPages(): readonly SettingsPageDefinition[];
|
|
26
|
+
open(pageId?: string): void;
|
|
27
|
+
close(): void;
|
|
28
|
+
toggle(): void;
|
|
29
|
+
isOpen(): boolean;
|
|
30
|
+
activePage(): string | undefined;
|
|
31
|
+
subscribe(listener: () => void): () => void;
|
|
32
|
+
version(): number;
|
|
33
|
+
}
|
|
34
|
+
declare module '@snap-rail/cordis' {
|
|
35
|
+
interface Context {
|
|
36
|
+
settings: SettingsService;
|
|
37
|
+
}
|
|
38
|
+
interface Events {
|
|
39
|
+
'settings/pages-changed'(): void;
|
|
40
|
+
'settings/open-changed'(): void;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The default settings trigger; the layout decides placement/presentation. */
|
|
44
|
+
export declare function SettingsEntry(props: {
|
|
45
|
+
presentation: 'icon' | 'label';
|
|
46
|
+
open(): void;
|
|
47
|
+
isOpen: boolean;
|
|
48
|
+
}): ReactNode;
|
|
49
|
+
/** The default settings surface. */
|
|
50
|
+
export declare function SettingsSurface(props: {
|
|
51
|
+
service: SettingsService;
|
|
52
|
+
ctx: Context;
|
|
53
|
+
}): ReactNode;
|
|
54
|
+
/** Mount the settings registry and its default slot contributions. */
|
|
55
|
+
declare const settingsPlugin: Plugin.Object<void>;
|
|
56
|
+
/** The settings page info the slot context exposes. */
|
|
57
|
+
export declare function settingsPageInfo(page: SettingsPageDefinition): SettingsPageInfo;
|
|
58
|
+
export default settingsPlugin;
|
|
59
|
+
//# sourceMappingURL=settings.d.ts.map
|