feat(ui): bring the remaining pages into the themed kit

Port tables, forms, dialogs, tabs and detail cards to the themed pages. Align node tiles, palette labels and control spacing across the pages.
This commit is contained in:
Zakk committed 2026-09-15 05:44:31 +10:00
1 parent e321e06150
commit f3324371ec
14 files changed
+624 -24

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
// "Add rule" dialog shared by connections, clients and rules, on the Rosé Pine kit.
import {useState, type ReactElement} from 'react';
import {groups, runtime} from '../app/mock';
import {Button, LabeledSelect, ModalDialog, Switch, TextField, toast} from './ui';
export type Preset = {label: string, cond: string};
export function RuleDialog({trigger, presets}: {trigger: ReactElement, presets: Preset[]}) {
const [i, setI] = useState('0');
const [cond, setCond] = useState(presets[0].cond);
const [target, setTarget] = useState('direct');
const [pos, setPos] = useState('before-fallback');
const [must, setMust] = useState(false);
const targets = ['direct', 'block', ...groups.map(g => g.name)].map(t => ({id: t, label: t}));
return (
<ModalDialog trigger={trigger} title="加規則" narrow footer={close => <><Button onPress={close}>取消</Button><Button accent onPress={() => { close(); toast('positive', '已加入規則,reload 完成(r' + (runtime.diskRevision + 1) + ')'); }}>加入並 reload</Button></>}>
<div className="rp-form">
{presets.length > 1 && <LabeledSelect label="依據" value={i} onChange={k => { setI(k); setCond(presets[Number(k)].cond); }} items={presets.map((p, j) => ({id: String(j), label: p.label}))} />}
<TextField label="規則" value={cond} onChange={setCond} />
<LabeledSelect label="目標" value={target} onChange={setTarget} items={targets} />
<LabeledSelect label="位置" value={pos} onChange={setPos} items={[{id: 'before-fallback', label: 'fallback 之前(config.dae:44)'}, {id: 'before-hit', label: '命中的規則之前'}, {id: 'rules-end', label: 'rules.dae 結尾'}]} />
<Switch isSelected={must} onChange={setMust}>must,全域與直連模式下仍然生效</Switch>
</div>
</ModalDialog>
);
}
+19 -11
View File
@@ -1,5 +1,5 @@
// Rosé Pine shell: same frame as the S2 panel (top bar, side nav, rounded main), plain CSS and react-aria-components.
import {useEffect, useState} from 'react';
import {useEffect, useState, type ReactElement} from 'react';
import {Button as RButton, Dialog, Modal, ModalOverlay, SearchField, Input, ListBox, ListBoxItem, ListBoxSection, Header} from 'react-aria-components';
import Search from '@react-spectrum/s2/icons/Search';
import Refresh from '@react-spectrum/s2/icons/Refresh';
@@ -22,18 +22,26 @@ import {LangContext, LANGS, readLang, useT, type Lang} from '../app/i18n';
import {conns, groups, rules} from '../app/mock';
import {Button, MenuButton} from './ui';
import {Activity} from './Activity';
import {Provider} from '@react-spectrum/s2';
import {ToastContainer} from '@react-spectrum/s2/Toast';
import Color from '@react-spectrum/s2/icons/Color';
import {S2_LOCALE} from '../app/i18n';
import {PAGES} from '../app/Shell';
import {Overview} from './pages/Overview';
import {Connections} from './pages/Connections';
import {Clients} from './pages/Clients';
import {Policies} from './pages/Policies';
import {Rules} from './pages/Rules';
import {Dns} from './pages/Dns';
import {Resources} from './pages/Resources';
import {ConfigPage} from './pages/ConfigPage';
import {Events} from './pages/Events';
import {Toasts} from './ui';
import type {PageProps} from './pages/types';
const PAGES: Record<string, (p: PageProps) => ReactElement> = {overview: Overview, connections: Connections, clients: Clients, policies: Policies, rules: Rules, dns: Dns, resources: Resources, config: ConfigPage, events: Events};
type Scheme = 'system' | 'light' | 'dark';
// A palette is a family plus its dark flavour; the light flavour is fixed per family (Dawn, Latte, Nord light).
type PaletteId = 'rose-pine/main' | 'rose-pine/moon' | 'catppuccin/frappe' | 'catppuccin/macchiato' | 'catppuccin/mocha' | 'nord/nord';
const PALETTES: Array<{title: string, items: Array<{id: PaletteId, label: string, desc?: string}>}> = [
{title: 'Rosé Pine', items: [{id: 'rose-pine/main', label: 'Rosé Pine', desc: 'Dawn'}, {id: 'rose-pine/moon', label: 'Moon', desc: 'Dawn'}]},
{title: 'Catppuccin', items: [{id: 'catppuccin/frappe', label: 'Frappé', desc: 'Latte'}, {id: 'catppuccin/macchiato', label: 'Macchiato', desc: 'Latte'}, {id: 'catppuccin/mocha', label: 'Mocha', desc: 'Latte'}]},
{title: 'Rosé Pine', items: [{id: 'rose-pine/moon', label: 'Moon', desc: '暗版較柔'}, {id: 'rose-pine/main', label: 'Main', desc: '暗版最深'}]},
{title: 'Catppuccin', items: [{id: 'catppuccin/frappe', label: 'Frappé', desc: '暗版最淺'}, {id: 'catppuccin/macchiato', label: 'Macchiato', desc: '暗版'}, {id: 'catppuccin/mocha', label: 'Mocha', desc: '暗版最深'}]},
{title: 'Nord', items: [{id: 'nord/nord', label: 'Nord'}]}
];
const NAV: Array<[string, Array<[string, string, typeof Home]>]> = [
@@ -92,21 +100,21 @@ export function Shell() {
const [searchOpen, setSearchOpen] = useState(false);
useEffect(() => { const on = () => setRoute(location.hash.replace(/^#\/?/, '').split('?')[0] || 'activity'); addEventListener('hashchange', on); return () => removeEventListener('hashchange', on); }, []);
useEffect(() => { const on = (e: KeyboardEvent) => { if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); setSearchOpen(true); } }; addEventListener('keydown', on); return () => removeEventListener('keydown', on); }, []);
const go = (p: string) => { location.hash = '#/' + p; };
const go = (p: string, q?: string) => { location.hash = '#/' + p + (q ? '?' + q : ''); };
const pickLang = (l: Lang) => { setLang(l); try { localStorage.setItem('doona-lang', l); } catch { /* private mode */ } };
const mac = navigator.platform.startsWith('Mac');
return (
<LangContext.Provider value={lang}>
<Frame lang={lang} pickLang={pickLang} ap={ap} route={route} go={go} openSearch={() => setSearchOpen(true)} mac={mac} />
<SearchDialog open={searchOpen} onClose={() => setSearchOpen(false)} go={go} />
<Toasts />
</LangContext.Provider>
);
}
function Frame({lang, pickLang, ap, route, go, openSearch, mac}: {lang: Lang, pickLang: (l: Lang) => void, ap: ReturnType<typeof useAppearance>, route: string, go: (p: string) => void, openSearch: () => void, mac: boolean}) {
const t = useT();
const s2Page = PAGES[route];
const S2Page = route === 'activity' ? null : s2Page?.[1];
const Page = route === 'activity' ? null : PAGES[route];
const titleKey = NAV.flatMap(([, items]) => items).find(([k]) => k === route)?.[1] ?? 'nav.activity';
return (
<div className="rp-shell">
@@ -135,7 +143,7 @@ function Frame({lang, pickLang, ap, route, go, openSearch, mac}: {lang: Lang, pi
<main className="rp-main">
<div className="rp-content">
<h1 className="rp-h1">{t(titleKey as 'nav.activity')}</h1>
{S2Page ? <div className="rp-s2host"><Provider locale={S2_LOCALE[lang]} colorScheme={ap.dark ? 'dark' : 'light'} background="base" router={{navigate: (h: string) => { location.hash = h; }}}><ToastContainer /><S2Page go={go as never} query={location.hash.split('?')[1] ?? ''} /></Provider></div> : <Activity go={go} />}
{Page ? <Page go={go} query={location.hash.split('?')[1] ?? ''} /> : <Activity go={go} />}
</div>
</main>
</div>
+18
View File
@@ -0,0 +1,18 @@
import Add from '@react-spectrum/s2/icons/Add';
import LinkIcon from '@react-spectrum/s2/icons/Link';
import {clients, runtime} from '../../app/mock';
import {Button, DataTable} from '../ui';
import {RuleDialog} from '../RuleDialog';
import type {PageProps} from './types';
export function Clients({go}: PageProps) {
return (
<div className="rp-page">
<p className="rp-note">從可見連線聚合,只列本次觀察({runtime.window})裡有連線的來源 IP,不持久;MAC 只在 eBPF 看得到時才有。不做 DHCP 清單、命名與累計流量。</p>
<DataTable label="客戶端" height={244} rows={clients.map(c => ({...c, id: c.ip}))}
cols={[{id: 'ip', label: '來源 IP', width: 140, isRowHeader: true}, {id: 'mac', label: 'MAC', width: 190}, {id: 'active', label: '活動連線', width: 100}, {id: 'sampled', label: '採樣位元組', width: 120}, {id: 'first', label: '首次看到'}, {id: 'act', label: '操作', width: 230}]}
render={c => [<span className="rp-code">{c.ip}</span>, c.mac ? <span className="rp-code">{c.mac}</span> : '未知', c.active, c.sampled, c.firstSeen,
<span className="rp-group-btns"><Button small onPress={() => go('connections', 'src=' + c.ip)}><LinkIcon />連線</Button><RuleDialog trigger={<Button small><Add />加規則</Button>} presets={[{label: '來源 ' + c.ip, cond: 'sip(' + c.ip + ')'}, ...(c.mac ? [{label: 'MAC ' + c.mac, cond: 'mac(' + c.mac + ')'}] : [])]} /></span>]} />
</div>
);
}
+56
View File
@@ -0,0 +1,56 @@
import {useState} from 'react';
import {sources, diagnostics, restartItems, runtime} from '../../app/mock';
import {Badge, Button, DaeLine, Frame, LabeledSelect, Line, Switch, TextArea, toast} from '../ui';
import type {PageProps} from './types';
export function ConfigPage({query}: PageProps) {
const q = new URLSearchParams(query);
const wanted = sources.find(s => s.path.endsWith(q.get('src') || '#'));
const [srcId, setSrcId] = useState(wanted ? wanted.id : 'main');
const [edit, setEdit] = useState(false);
const [text, setText] = useState('');
const [dirty, setDirty] = useState(false);
const src = sources.find(s => s.id === srcId)!;
const errs = diagnostics.filter(d => d.source === src.id);
const startEdit = (on: boolean) => { setEdit(on); if (on) setText(src.lines.join('\n')); };
return (
<div className="rp-page">
<div className="rp-split">
<div className="rp-col">
<div className="rp-between">
<div className="rp-cluster">
<LabeledSelect label="來源" side value={srcId} onChange={k => { setSrcId(k); setEdit(false); setDirty(false); }} items={sources.map(s => ({id: s.id, label: s.path}))} />
<Badge>磁碟 r{runtime.diskRevision}</Badge>
<Badge>執行中 r{runtime.activeRevision}</Badge>
{dirty && <Badge tone="warn">未儲存</Badge>}
</div>
<div className="rp-group-btns">
<Button onPress={() => toast(errs.length ? 'negative' : 'positive', errs.length ? '校驗失敗,第 ' + errs[0].line + ' 行' : '校驗通過')}>校驗</Button>
<Button primary onPress={() => toast('neutral', 'reload 完成(r' + runtime.diskRevision + ')')}>reload</Button>
<Button accent isDisabled={!dirty} onPress={() => { setDirty(false); toast('positive', '已應用並 reload(r' + (runtime.diskRevision + 1) + ')'); }}>應用並 reload</Button>
</div>
</div>
{errs.map(e => <div key={e.line} className="rp-alert"><span className="h">第 {e.line} 行:{e.msg.split(';')[0]}</span><span className="b">{e.msg.split(';')[1]}</span></div>)}
{edit
? <TextArea label="來源" value={text} onChange={v => { setText(v); setDirty(true); }} />
: <Frame title={src.path} actions={<span>{src.lines.length} 行,{src.editable ? '可編輯' : '唯讀'}</span>}>{src.lines.map((l, i) => <Line key={i} n={i + 1} err={errs.some(e => e.line === i + 1)}><DaeLine text={l} /></Line>)}</Frame>}
</div>
<div className="rp-col">
<div className="rp-card">
<Switch isSelected={edit} onChange={startEdit} isDisabled={!src.editable}>無損編輯</Switch>
<span className="rp-label">唯讀檢視預設遮罩機密(訂閱網址、密碼),遮罩文字永不寫回。開啟編輯才讀取原文(control 權限、no-store)。</span>
</div>
<div className="rp-card">
<h3 className="rp-h3">需重啟的項</h3>
<div className="rp-list">{restartItems.map(k => <span key={k} className="rp-code">{k}</span>)}</div>
<span className="rp-label">監聽器、NFQUEUE、TProxy、DNS 綁定在啟動期決定;改這些 reload 不生效。</span>
</div>
<div className="rp-card">
<h3 className="rp-h3">外部改動</h3>
<span className="rp-label">應用時用 If-Match r{runtime.diskRevision};磁碟被別人改過就顯示衝突,不覆蓋。沒有自動 reload 開關。</span>
</div>
</div>
</div>
</div>
);
}
+55
View File
@@ -0,0 +1,55 @@
import {useMemo, useState} from 'react';
import {SearchField, Input} from 'react-aria-components';
import Search from '@react-spectrum/s2/icons/Search';
import ListBulleted from '@react-spectrum/s2/icons/ListBulleted';
import DeviceAll from '@react-spectrum/s2/icons/DeviceAll';
import {conns, groups, type Conn} from '../../app/mock';
import {Button, DataTable, Kv, LabeledSelect, Light, Segmented, toast} from '../ui';
import {RuleDialog} from '../RuleDialog';
import type {PageProps} from './types';
export function Connections({go, query}: PageProps) {
const q = new URLSearchParams(query);
const [text, setText] = useState(q.get('q') || q.get('src') || '');
const [plane, setPlane] = useState(q.get('plane') || 'all');
const [out, setOut] = useState('all');
const [sel, setSel] = useState<string | null>('2');
const shown = useMemo(() => conns.filter(c => (plane === 'all' || c.plane === plane) && (out === 'all' || c.out === out) && (!text || [c.dst, c.host, c.src, c.mac, c.out].join(' ').includes(text))), [text, plane, out]);
const cur: Conn | undefined = conns.find(c => c.id === sel);
const proxy = groups[0];
return (
<div className="rp-page">
<div className="rp-toolbar">
<SearchField aria-label="過濾" value={text} onChange={setText} className="rp-input" style={{width: 280}}><Search /><Input placeholder="域名、IP、來源、MAC" /></SearchField>
<Segmented label="平面" value={plane} onChange={setPlane} items={[['all', '全部 ' + conns.length], ['內核', '內核'], ['userspace', 'userspace'], ['拒絕', '拒絕']]} />
<LabeledSelect label="出站" side value={out} onChange={setOut} items={[{id: 'all', label: '所有出站'}, {id: 'direct', label: 'direct'}, {id: 'block', label: 'block'}, ...groups.map(g => ({id: g.name, label: g.name}))]} />
<Button onPress={() => { setText(''); setPlane('all'); setOut('all'); }}>清除過濾</Button>
</div>
<div className="rp-split">
<DataTable label="連線" rows={shown} selected={sel} onSelect={setSel} empty="沒有符合的連線"
cols={[{id: 'dst', label: '目標', isRowHeader: true}, {id: 'src', label: '來源', width: 112}, {id: 'out', label: '出站', width: 136}, {id: 'plane', label: '平面', width: 100}, {id: 'down', label: '下載', width: 80}, {id: 'age', label: '時長', width: 80}]}
render={c => [c.host ? c.host + c.dst.slice(c.dst.lastIndexOf(':')) : c.dst, <span className="rp-code">{c.src}</span>, c.chain.join(' → '), c.plane, c.down, c.age]} />
{cur ? (
<div className="rp-card">
<h3 className="rp-h3">{cur.host || cur.dst}</h3>
<Light tone={cur.plane === '拒絕' ? 'err' : 'ok'}>{cur.plane === '拒絕' ? '已拒絕' : cur.plane + '轉發'},{cur.proto.toUpperCase()}{cur.host ? ',' + cur.dst : ''}</Light>
<Kv items={[['來源', cur.src], ['MAC', cur.mac || '未知'], ['規則', cur.rule], ['引用', cur.ruleRef || '無'], ['選擇鏈', cur.chain.join(' → ')], ['流量', '上傳 ' + cur.up + ',下載 ' + cur.down], ['追蹤', cur.age]]} />
<div className="rp-group-btns">
<Button small onPress={() => go('rules')}><ListBulleted />規則</Button>
<Button small onPress={() => go('clients')}><DeviceAll />客戶端</Button>
</div>
<div className="rp-col">
<RuleDialog trigger={<Button accent>加規則</Button>} presets={[
...(cur.host ? [{label: '域名 ' + cur.host, cond: 'domain(full: ' + cur.host + ')'}] : []),
{label: '目標 IP', cond: 'dip(' + cur.dst.replace(/:\d+$/, '') + ')'},
{label: '來源 ' + cur.src, cond: 'sip(' + cur.src + ')'},
...(cur.mac ? [{label: 'MAC ' + cur.mac, cond: 'mac(' + cur.mac + ')'}] : [])]} />
{cur.chain[0] === proxy.name && <LabeledSelect label={proxy.name + ' 的選擇(只影響後續撥號)'} value={proxy.selected ?? proxy.members[0]} onChange={k => toast('positive', proxy.name + ' 改選 ' + k + ',已持久化')} items={proxy.members.map(m => ({id: m, label: m}))} />}
<Button negative isDisabled={!cur.canTerminate} tip={cur.canTerminate ? undefined : cur.plane === '拒絕' ? '沒有連線可中止' : '這條流在內核轉發,honk 不能中止它'} onPress={() => toast('positive', '已中止 ' + (cur.host || cur.dst))}>中止這條連線</Button>
</div>
</div>
) : <div className="rp-card"><span className="rp-label">選一條連線,右側列它的路由結果與能做的事。</span></div>}
</div>
</div>
);
}
+42
View File
@@ -0,0 +1,42 @@
import {useState} from 'react';
import Delete from '@react-spectrum/s2/icons/Delete';
import {dnsCache} from '../../app/mock';
import {Button, DataTable, Kv, LabeledSelect, TextField, toast} from '../ui';
import type {PageProps} from './types';
export function Dns(_: PageProps) {
const [qname, setQname] = useState('cdn.bilibili.com');
const [qtype, setQtype] = useState('A');
const [asked, setAsked] = useState<{qname: string, qtype: string} | null>({qname: 'cdn.bilibili.com', qtype: 'A'});
const [scope, setScope] = useState('all');
return (
<div className="rp-page">
<div className="rp-split">
<div className="rp-col">
<div className="rp-card">
<div className="rp-toolbar" style={{alignItems: 'flex-end'}}>
<TextField label="qname" value={qname} onChange={setQname} width={280} />
<LabeledSelect label="qtype" value={qtype} onChange={setQtype} items={['A', 'AAAA', 'HTTPS', 'TXT', 'MX'].map(t => ({id: t, label: t}))} />
<Button accent onPress={() => setAsked({qname, qtype})}>查詢</Button>
</div>
{asked && (<>
<h3 className="rp-h3">{asked.qname} {asked.qtype}</h3>
<Kv items={[['狀態', 'NOERROR,1 筆'], ['路由', 'qname(geosite: cn) -> alidns'], ['上游', 'udp://223.5.5.5'], ['快取', '命中,剩 58 秒'], ['回應', '120.92.78.14'], ['時序', '路由 0.1 ms,上游 8.4 ms,回應 0.3 ms']]} />
</>)}
</div>
<DataTable label="快取" height={292} rows={dnsCache}
cols={[{id: 'q', label: 'qname', isRowHeader: true}, {id: 't', label: 'qtype', width: 88}, {id: 'k', label: '正負', width: 80}, {id: 'u', label: '上游', width: 170}, {id: 'e', label: '過期', width: 100}, {id: 'a', label: '刪除', width: 64}]}
render={c => [<span className="rp-code">{c.qname}</span>, c.qtype, c.kind, c.upstream, c.expires, <Button quiet icon small label="刪這條快取" onPress={() => toast('positive', '已刪 ' + c.qname + ' ' + c.qtype)}><Delete /></Button>]} />
</div>
<div className="rp-card">
<h3 className="rp-h3">flush</h3>
<LabeledSelect label="範圍" value={scope} onChange={setScope} items={[{id: 'all', label: '全部'}, {id: 'neg', label: '只清負快取'}, {id: 'expired', label: '只清已過期'}, {id: 'suffix', label: 'qname 後綴'}]} />
{scope === 'suffix' && <TextField label="後綴" defaultValue="bilibili.com" />}
<span className="rp-label">{dnsCache.length} 條,正 3,負 2</span>
<Button negative onPress={() => toast('positive', 'flush 完成,清除 ' + (scope === 'all' ? dnsCache.length : 2) + ' 條')}>flush</Button>
<span className="rp-label">列表與單刪要引擎補 GET / DELETE;現在只有整體 flush。查詢用 qname,不用 domain。</span>
</div>
</div>
</div>
);
}
+32
View File
@@ -0,0 +1,32 @@
import {useState} from 'react';
import OpenIn from '@react-spectrum/s2/icons/OpenIn';
import {events, clashLog} from '../../app/mock';
import {useT} from '../../app/i18n';
import {Button, DataTable, Frame, LabeledSelect, Light, Line, LogLine, Segmented, Tabs} from '../ui';
import type {PageProps} from './types';
const TONE = {info: 'info', warn: 'warn', error: 'err'} as const;
export function Events({go}: PageProps) {
const t = useT();
const [kind, setKind] = useState('all');
const [level, setLevel] = useState('all');
const shown = events.filter(e => (kind === 'all' || e.kind === kind) && (level === 'all' || (level === 'warn' ? e.level !== 'info' : e.level === 'error')));
return (
<div className="rp-page">
<Tabs tabs={[['events', '事件'], ['clash', 'Clash 日誌']]}>{id => id === 'events' ? (
<div className="rp-page">
<div className="rp-toolbar">
<LabeledSelect label="種類" side value={kind} onChange={setKind} items={[{id: 'all', label: '所有種類'}, {id: 'reload', label: 'reload'}, {id: '訂閱', label: '訂閱'}, {id: '探測', label: '探測'}, {id: 'datapath', label: 'datapath'}, {id: 'operation', label: 'operation'}]} />
<Segmented label="等級" value={level} onChange={setLevel} items={[['all', '全部'], ['warn', '警告以上'], ['error', '只看錯誤']]} />
<span className="rp-label">重放範圍:行程內最近 200 條,有 gap 會標出;過濾不改 global.log_level。</span>
</div>
<DataTable label="事件" height={342} rows={shown} empty="沒有符合的事件"
cols={[{id: 't', label: '時間', width: 100}, {id: 'k', label: '種類', width: 110}, {id: 'l', label: '等級', width: 96}, {id: 'm', label: '訊息', isRowHeader: true}, {id: 'r', label: '引用', width: 96}]}
render={e => [<span className="rp-code">{e.t}</span>, e.kind, <Light tone={TONE[e.level]}>{e.level}</Light>, t(`ev.${e.id}` as 'ev.e1'), e.ref ? <Button quiet small onPress={() => go(e.ref!.replace('#/', ''))}><OpenIn />打開</Button> : '']} />
</div>
) : (
<Frame title="Clash 日誌,最近 4 條" actions={<span>info 級,跟隨 global.log_level</span>}>{clashLog.map((l, i) => <Line key={i} n={i + 1}><LogLine text={l} /></Line>)}</Frame>
)}</Tabs>
</div>
);
}
+48
View File
@@ -0,0 +1,48 @@
import {useState} from 'react';
import Refresh from '@react-spectrum/s2/icons/Refresh';
import FileText from '@react-spectrum/s2/icons/FileText';
import OpenIn from '@react-spectrum/s2/icons/OpenIn';
import {checks} from '../../app/mock';
import {useT} from '../../app/i18n';
import {Badge, Button, Kv, Light, Switch, toast} from '../ui';
import type {Go} from './types';
export function Overview({go}: {go: Go}) {
const t = useT();
const [onlyBad, setOnlyBad] = useState(false);
const shown = onlyBad ? checks.filter(c => !c.ready) : checks;
return (
<div className="rp-page">
<div className="rp-between">
<Kv inline items={[['上次診斷', 'op-1183,13:40,7 項,2 項失敗'], ['需重啟', '1 項']]} />
<div className="rp-cluster">
<Switch isSelected={onlyBad} onChange={setOnlyBad}>只看未就緒</Switch>
<Button primary onPress={() => toast('info', '診斷 op-1184 已排程')}><Refresh />重新執行診斷</Button>
</div>
</div>
<p className="rp-note">每項列出設定值、實際值與就緒狀態。監聽器、NFQUEUE、TProxy、DNS 綁定在啟動期決定,改了要重啟;這裡不做開關,也不自動修復。</p>
<div className="rp-list">
{shown.map(c => (
<div key={c.id} className="rp-card">
<div className="rp-check">
<h3 className="rp-h3">{t(`check.${c.id}` as 'check.ebpf')}</h3>
<div className="rp-pair"><Kv items={[['設定', c.requested]]} /><Kv items={[['實際', c.effective]]} /></div>
<div className="rp-cluster">{c.restart && <Badge tone="warn">需重啟</Badge>}<Light tone={c.ready ? 'ok' : 'err'}>{c.ready ? '就緒' : '未就緒'}</Light></div>
</div>
{c.ready ? <span className="rp-label">{c.detail}</span> : (
<div className="rp-fail">
<span>{c.detail}</span>
{c.fix && <span className="rp-label">處理:{c.fix}</span>}
<div className="rp-group-btns">
<Button small onPress={() => toast('info', c.name + ' 檢查已排程')}><Refresh />重新檢查</Button>
<Button small onPress={() => go('config', 'key=' + c.id)}><FileText />配置項</Button>
{c.manual && <Button small onPress={() => window.open(c.manual, '_blank')}><OpenIn />手冊</Button>}
</div>
</div>
)}
</div>
))}
</div>
</div>
);
}
+41
View File
@@ -0,0 +1,41 @@
import {useState} from 'react';
import Refresh from '@react-spectrum/s2/icons/Refresh';
import Data from '@react-spectrum/s2/icons/Data';
import {groups, runtime, type Node} from '../../app/mock';
import {Button, LabeledSelect, Light, Segmented, ToggleTile, toast} from '../ui';
import type {PageProps} from './types';
const health = (n: Node) => n.alive ? 'TCP ' + n.tcp + ' ms,UDP ' + n.udp + ' ms' + (n.v6 ? ',v6' : '') : '逾時';
export function Policies({go}: PageProps) {
const [mode, setMode] = useState<string>(runtime.mode);
const [target, setTarget] = useState(runtime.globalTarget);
const [sel, setSel] = useState<Record<string, string>>({proxy: 'hk-01'});
return (
<div className="rp-page">
<div className="rp-toolbar">
<Segmented label="出站模式" value={mode} onChange={k => { setMode(k); toast('positive', '出站模式已改為 ' + k); }} items={[['rule', '規則'], ['global', '全域'], ['direct', '直連']]} />
<LabeledSelect label="Global 目標" side value={target} onChange={setTarget} isDisabled={mode !== 'global'} items={groups.map(g => ({id: g.name, label: g.name}))} />
<Button onPress={() => go('resources')}><Data />訂閱來源</Button>
</div>
<p className="rp-note">{mode === 'rule' ? '規則由上至下逐條測試,第一條命中的決定出站。' : 'must 與 block 規則在全域、直連下仍然終結。'}只有 selector 組能手選,其他組由策略自動決定。</p>
<div className="rp-list">
{groups.map(g => (
<div key={g.name} className="rp-card">
<div className="rp-row">
<span className="rp-cluster"><h3 className="rp-h3">{g.name}</h3><span className="rp-label">{g.policy}</span><Light tone="ok">解析到 {g.policy === 'selector' ? sel[g.name] || g.leaf : g.leaf}</Light></span>
<Button small onPress={() => toast('positive', g.name + ' 測試完成,' + g.nodes.filter(n => !n.alive).map(n => n.name + ' 逾時').join(','))}><Refresh />測試全部</Button>
</div>
<div className="rp-nodes">
{g.members.map(m => {
const n = g.nodes.find(x => x.name === m);
const sub = n ? health(n) : '巢狀組';
if (g.policy !== 'selector') return <div key={m} className={'rp-member' + (g.leaf === m ? ' cur' : '')}><span className="n">{m}</span><span className="s">{sub}</span></div>;
return <ToggleTile key={m} selected={sel[g.name] === m} onPress={() => { setSel({...sel, [g.name]: m}); toast('positive', g.name + ' 改選 ' + m + ',已持久化'); }} name={m} sub={sub} />;
})}
</div>
</div>
))}
</div>
</div>
);
}
+33
View File
@@ -0,0 +1,33 @@
import {useState} from 'react';
import Refresh from '@react-spectrum/s2/icons/Refresh';
import {subs, geo} from '../../app/mock';
import {Button, DataTable, Kv, Light, Switch, toast} from '../ui';
import type {PageProps} from './types';
export function Resources(_: PageProps) {
const [onlyBad, setOnlyBad] = useState(false);
const shown = onlyBad ? subs.filter(s => !s.ready) : subs;
const refreshable = subs.filter(s => s.refreshable);
return (
<div className="rp-page">
<div className="rp-between">
<Switch isSelected={onlyBad} onChange={setOnlyBad}>只看未就緒</Switch>
<Button primary onPress={() => toast('negative', '刷新完成,sub-b 失敗(HTTP 503)')}><Refresh />刷新全部可刷新的({refreshable.length})</Button>
</div>
<DataTable label="訂閱" height={192} rows={shown} empty="全部就緒"
cols={[{id: 'n', label: '名稱', width: 120, isRowHeader: true}, {id: 'src', label: '來源'}, {id: 'st', label: '狀態', width: 130}, {id: 'try', label: '最後嘗試', width: 110}, {id: 'ok', label: '最後成功', width: 110}, {id: 'pub', label: '發布', width: 80}, {id: 'nodes', label: '節點', width: 72}, {id: 'act', label: '刷新', width: 72}]}
render={s => [s.name, <span className="rp-code">{s.source}</span>, <Light tone={s.ready ? 'ok' : 'err'}>{s.ready ? '就緒' : s.error || '未就緒'}</Light>, s.lastTry, s.lastOk, s.published, s.nodes ?? '',
<Button quiet icon small label={s.refreshable ? '刷新這個訂閱' : '本機檔案,外部替換後手動 reload'} isDisabled={!s.refreshable} onPress={() => toast(s.ready ? 'positive' : 'negative', s.ready ? s.name + ' 已刷新,' + s.nodes + ' 個節點' : s.name + ' 刷新失敗(HTTP 503)')}><Refresh /></Button>]} />
<div className="rp-cards">
{geo.map(g => (
<div key={g.name} className="rp-card">
<div className="rp-between"><h3 className="rp-h3">{g.name}</h3><Light tone={g.ready ? 'ok' : 'err'}>就緒</Light></div>
<Kv items={[['路徑', g.path]]} />
<Kv items={[['大小', g.size], ['修改', g.mtime]]} />
<span className="rp-label">唯讀。外部替換檔案後手動 reload;不做配額與到期。</span>
</div>
))}
</div>
</div>
);
}
+41
View File
@@ -0,0 +1,41 @@
import {useState} from 'react';
import {rules, fallbackRule, runtime, type Rule} from '../../app/mock';
import {Button, DataTable, Kv, ModalDialog, toast} from '../ui';
import {RuleDialog} from '../RuleDialog';
import type {PageProps} from './types';
export function Rules({go}: PageProps) {
const [sel, setSel] = useState<string | null>('r4');
const cur: Rule | undefined = rules.find(r => r.id === sel);
return (
<div className="rp-page">
<div className="rp-split">
<div className="rp-list">
<DataTable label="規則" rows={rules} selected={sel} onSelect={setSel}
cols={[{id: 'n', label: '#', width: 48}, {id: 'c', label: '條件', isRowHeader: true}, {id: 'o', label: '目標', width: 88}, {id: 'm', label: 'must', width: 80}, {id: 's', label: '來源', width: 130}, {id: 'x', label: '注釋', width: 80}]}
render={r => [r.n, <span className="rp-code">{r.cond}</span>, r.target, r.must ? 'must' : '', r.generated ? '生成' : r.source, r.note]} />
<div className="rp-fb"><span className="rp-kw">fallback</span>: <span className="rp-out">{fallbackRule.target}</span><span className="rp-label">{fallbackRule.source},在來源編輯器改</span></div>
</div>
<div className="rp-card">
{cur ? (
<>
<h3 className="rp-h3">#{cur.n} {cur.target}{cur.must ? '(must)' : ''}</h3>
<span className="rp-code">{cur.cond}</span>
<Kv items={[['來源', cur.generated ? '生成,subscription policy' : cur.source], ['狀態', cur.editable ? '可編輯' : '唯讀'], ['修訂', 'r' + runtime.diskRevision]]} />
<div className="rp-col">
<div className="rp-group-btns">
<Button onPress={() => go('config', 'src=' + cur.source.split(':')[0] + '&line=' + cur.source.split(':')[1])} isDisabled={!cur.editable}>打開來源</Button>
<ModalDialog trigger={<Button negative isDisabled={!cur.editable}>刪除</Button>} title={'刪除 #' + cur.n} narrow footer={close => <><Button onPress={close}>取消</Button><Button negative onPress={() => { close(); toast('positive', '已刪除 #' + cur.n + ',reload 完成(r' + (runtime.diskRevision + 1) + ')'); }}>刪除並 reload</Button></>}>
<p className="rp-note">從 {cur.source} 刪掉「{cur.cond} -&gt; {cur.target}」,If-Match r{runtime.diskRevision},校驗通過後 reload。注釋與其他行原樣保留。</p>
</ModalDialog>
</div>
<RuleDialog trigger={<Button accent>加規則</Button>} presets={[{label: '自訂', cond: 'domain(suffix: example.com)'}]} />
</div>
</>
) : <span className="rp-label">選一條規則。</span>}
<span className="rp-label">沒有命中計數與重設;複雜條件與 fallback 在來源編輯器改。</span>
</div>
</div>
</div>
);
}
+2
View File
@@ -0,0 +1,2 @@
export type Go = (page: string, query?: string) => void;
export type PageProps = {go: Go, query: string};
+102 -10
View File
@@ -5,7 +5,7 @@
:root, :root[data-family='rose-pine'] {
--rp-base: #faf4ed; --rp-surface: #fffaf3; --rp-overlay: #f2e9e1;
--rp-muted: #9893a5; --rp-subtle: #797593; --rp-text: #575279;
--rp-muted: #9893a5; --rp-subtle: #797593; --rp-text: #464261;
--rp-love: #b4637a; --rp-gold: #ea9d34; --rp-rose: #d7827e; --rp-pine: #286983; --rp-foam: #56949f; --rp-iris: #907aa9;
--rp-hl-low: #f4ede8; --rp-hl-med: #dfdad9; --rp-hl-high: #cecacd;
--rp-shadow: 0 1px 2px rgba(87, 82, 121, 0.08);
@@ -32,17 +32,18 @@
--rp-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
:root[data-family='nord'] {
/* Nord ships no light theme: Snow Storm as surfaces, Polar Night as text; mixed steps are blends of official colours. */
--rp-base: #e5e9f0; --rp-surface: #eceff4; --rp-overlay: #d8dee9;
--rp-muted: #7b88a1; --rp-subtle: #4c566a; --rp-text: #2e3440;
--rp-muted: #4c566a; --rp-subtle: #3b4252; --rp-text: #2e3440;
--rp-love: #bf616a; --rp-gold: #d08770; --rp-rose: #b48ead; --rp-pine: #5e81ac; --rp-foam: #8fbcbb; --rp-iris: #81a1c1;
--rp-hl-low: #e5e9f0; --rp-hl-med: #d8dee9; --rp-hl-high: #c2c9d6;
--rp-hl-low: #e5e9f0; --rp-hl-med: #d8dee9; --rp-hl-high: color-mix(in srgb, #4c566a 25%, #e5e9f0);
--rp-shadow: 0 1px 2px rgba(46, 52, 64, 0.1);
}
:root[data-family='nord'][data-scheme='dark'] {
--rp-base: #2e3440; --rp-surface: #3b4252; --rp-overlay: #434c5e;
--rp-muted: #7b88a1; --rp-subtle: #d8dee9; --rp-text: #eceff4;
--rp-muted: #4c566a; --rp-subtle: #d8dee9; --rp-text: #eceff4;
--rp-love: #bf616a; --rp-gold: #ebcb8b; --rp-rose: #d08770; --rp-pine: #81a1c1; --rp-foam: #8fbcbb; --rp-iris: #b48ead;
--rp-hl-low: #434c5e; --rp-hl-med: #4c566a; --rp-hl-high: #5b6678;
--rp-hl-low: #3b4252; --rp-hl-med: #434c5e; --rp-hl-high: #4c566a;
--rp-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
:root[data-flavour='main'][data-scheme='dark'] {
@@ -98,15 +99,15 @@ button, input { font: inherit; color: inherit; }
.rp-side > div + div { margin-top: 16px; }
.rp-nav { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 8px; color: var(--rp-subtle); text-decoration: none; position: relative; }
.rp-nav:hover { background: var(--rp-hl-low); color: var(--rp-text); }
.rp-nav[aria-current='page'] { color: var(--rp-text); font-weight: 600; }
.rp-nav[aria-current='page']::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 2px; border-radius: 1px; background: var(--rp-text); }
.rp-nav[aria-current='page'] { color: var(--rp-pine); font-weight: 600; }
.rp-nav[aria-current='page']::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 2px; border-radius: 1px; background: var(--rp-pine); }
.rp-version { display: inline-flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px; border-radius: 8px; color: var(--rp-subtle); background: transparent; border: 0; cursor: pointer; font-size: 13px; line-height: 20px; }
.rp-version:hover { background: var(--rp-hl-low); }
.rp-main { margin-right: 0; padding: 32px 40px 48px; background: var(--rp-surface); border-radius: 16px 16px 0 0; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
@media (min-width: 1024px) { .rp-main { margin-right: 16px; } }
.rp-content { width: 100%; max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.rp-h1 { font-size: 28px; font-weight: 800; margin: 0; line-height: 36px; }
.rp-card { background: var(--rp-base); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; overflow: hidden; }
.rp-h1 { font-size: 28px; font-weight: 800; margin: 0; line-height: 36px; color: var(--rp-text); }
.rp-card { background: var(--rp-base); border: 1px solid color-mix(in srgb, var(--rp-hl-med) 70%, transparent); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; overflow: hidden; }
.rp-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; flex-wrap: wrap; min-width: 0; }
.rp-row > * { min-width: 0; max-width: 100%; }
.rp-cluster { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
@@ -144,7 +145,7 @@ button, input { font: inherit; color: inherit; }
.rp-seg .rp-btn { flex: 0 1 auto; min-width: 0; padding: 0 10px; }
.rp-seg .rp-btn { height: 28px; background: transparent; color: var(--rp-subtle); border-radius: 6px; }
.rp-seg .rp-btn:hover { color: var(--rp-text); }
.rp-seg .rp-btn[data-selected] { background: var(--rp-surface); color: var(--rp-text); box-shadow: var(--rp-shadow); }
.rp-seg .rp-btn[data-selected] { background: var(--rp-surface); color: var(--rp-pine); box-shadow: var(--rp-shadow); }
.rp-sec-h { font-size: 12px; color: var(--rp-muted); padding: 8px 10px 2px; }
.rp-popover { background: var(--rp-surface); border: 1px solid var(--rp-hl-med); border-radius: 10px; padding: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); min-width: 160px; }
.rp-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 10px; border-radius: 6px; cursor: default; outline: none; color: var(--rp-text); }
@@ -193,3 +194,94 @@ button, input { font: inherit; color: inherit; }
.rp-results { max-height: 420px; overflow: auto; scrollbar-width: thin; padding-right: 12px; }
.rp-section-h { font-size: 12px; color: var(--rp-muted); padding: 8px 10px 4px; }
.rp-placeholder { color: var(--rp-subtle); }
/* Kit additions for the remaining pages */
.rp-page { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.rp-note { margin: 0; font-size: 13px; line-height: 20px; color: var(--rp-subtle); }
.rp-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rp-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.rp-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.rp-col > .rp-btn, .rp-card > .rp-btn { align-self: flex-start; }
.rp-split { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 1280px) { .rp-split { grid-template-columns: minmax(0, 1fr) 320px; } }
.rp-h3 { margin: 0; font-size: 15px; line-height: 20px; font-weight: 600; }
.rp-code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; }
.rp-kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 16px; }
.rp-kv .k { display: block; font-size: 12px; line-height: 16px; color: var(--rp-muted); }
.rp-kv .v { display: block; line-height: 20px; overflow-wrap: anywhere; }
.rp-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 6px; font-size: 12px; line-height: 16px; font-weight: 500; border: 1px solid var(--rp-hl-high); color: var(--rp-subtle); }
.rp-badge.warn { border-color: transparent; background: var(--rp-gold); color: var(--rp-base); }
.rp-btn.negative { background: transparent; border-color: var(--rp-love); color: var(--rp-love); }
.rp-btn.negative:hover { background: color-mix(in srgb, var(--rp-love) 12%, transparent); }
.rp-btn.primary { background: var(--rp-pine); color: var(--rp-surface); }
.rp-btn.primary:hover { filter: brightness(1.08); }
.rp-btn[data-disabled] { opacity: 0.4; cursor: default; pointer-events: none; }
.rp-btn.xl { height: 56px; padding: 8px 12px; flex-direction: column; justify-content: center; gap: 2px; border: 1px solid transparent; background: var(--rp-overlay); width: 100%; min-width: 0; }
.rp-btn.xl[data-selected] { background: var(--rp-pine); color: var(--rp-surface); }
.rp-btn.xl .n { font-weight: 600; }
.rp-btn.xl .n, .rp-btn.xl .s, .rp-member .n, .rp-member .s { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-btn.xl .s { font-size: 13px; line-height: 16px; font-weight: 400; }
.rp-btn.xl:not([data-selected]) .s { color: var(--rp-subtle); }
.rp-btn.xl[data-selected] .s { opacity: 0.9; }
.rp-member { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 56px; padding: 8px 12px; border-radius: 8px; background: var(--rp-overlay); text-align: center; min-width: 0; }
.rp-member.cur { background: color-mix(in srgb, var(--rp-pine) 14%, transparent); color: var(--rp-pine); }
.rp-member .n { font-weight: 600; }
.rp-member .s { font-size: 13px; line-height: 16px; color: var(--rp-subtle); }
.rp-member.cur .s { color: inherit; opacity: 0.9; }
.rp-nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.rp-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.rp-switch .track { width: 32px; height: 18px; border-radius: 9px; background: var(--rp-hl-high); position: relative; transition: background 150ms; flex-shrink: 0; }
.rp-switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--rp-surface); transition: transform 150ms; }
.rp-switch[data-selected] .track { background: var(--rp-pine); }
.rp-switch[data-selected] .track::after { transform: translateX(14px); }
.rp-switch[data-disabled] { opacity: 0.4; cursor: default; }
.rp-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rp-field > label, .rp-field .lbl { font-size: 12px; line-height: 16px; color: var(--rp-subtle); }
.rp-field .rp-input { height: 32px; }
.rp-field textarea { width: 100%; min-height: 320px; padding: 12px; border: 1px solid var(--rp-hl-high); border-radius: 10px; background: var(--rp-base); color: var(--rp-text); font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; line-height: 20px; resize: vertical; box-sizing: border-box; }
.rp-selectbtn { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; height: 32px; padding: 0 8px 0 12px; border-radius: 8px; background: var(--rp-overlay); border: 0; color: var(--rp-text); cursor: pointer; min-width: 120px; }
.rp-selectbtn:hover { background: var(--rp-hl-med); }
.rp-selectbtn[data-disabled] { opacity: 0.4; cursor: default; }
.rp-table { width: 100%; border: 1px solid var(--rp-hl-med); border-radius: 10px; background: var(--rp-surface); overflow: auto; scrollbar-width: thin; outline: none; }
.rp-table table, .rp-table [role='grid'] { width: 100%; border-collapse: collapse; table-layout: fixed; }
.rp-table [role='columnheader'] { text-align: start; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--rp-pine); padding: 8px 12px; background: var(--rp-base); border-bottom: 1px solid var(--rp-hl-med); white-space: nowrap; position: sticky; top: 0; outline: none; }
.rp-table [role='row'][data-selected] { background: color-mix(in srgb, var(--rp-pine) 12%, transparent); }
.rp-table [role='row'][data-hovered]:not([data-selected]) { background: var(--rp-hl-low); }
.rp-table [role='row'][data-focus-visible] { outline: 2px solid var(--rp-pine); outline-offset: -2px; }
.rp-table [role='rowheader'], .rp-table [role='gridcell'] { padding: 0 12px; height: 40px; border-bottom: 1px solid var(--rp-hl-low); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; outline: none; vertical-align: middle; }
.rp-table [role='row'][data-selection-mode='single'] { cursor: default; }
.rp-table .empty { padding: 24px; text-align: center; color: var(--rp-subtle); }
.rp-frame { border: 1px solid var(--rp-hl-med); border-radius: 10px; overflow: hidden; background: var(--rp-surface); }
.rp-frame .head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; padding: 0 16px; border-bottom: 1px solid var(--rp-hl-med); font-size: 12px; line-height: 16px; color: var(--rp-subtle); }
.rp-frame .body { overflow: auto; padding: 12px 0; scrollbar-width: thin; }
.rp-line { display: grid; grid-template-columns: 56px max-content; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; line-height: 24px; white-space: pre; padding-right: 16px; }
.rp-line .n { text-align: end; padding-right: 16px; color: var(--rp-muted); user-select: none; }
.rp-line.err { background: color-mix(in srgb, var(--rp-love) 16%, transparent); }
.rp-kw { color: var(--rp-love); } .rp-arg { color: var(--rp-pine); } .rp-str { color: var(--rp-gold); } .rp-cmt { color: var(--rp-muted); } .rp-out { color: var(--rp-pine); font-weight: 600; }
.rp-lv { display: inline-block; width: 6ch; font-weight: 600; } .rp-lv-info { color: var(--rp-foam); } .rp-lv-warn { color: var(--rp-gold); } .rp-lv-err { color: var(--rp-love); }
.rp-alert { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--rp-love); }
.rp-alert .h { font-weight: 600; }
.rp-alert .b { font-size: 13px; line-height: 20px; color: var(--rp-subtle); }
.rp-tabs { display: flex; flex-direction: column; gap: 24px; }
.rp-tablist { display: flex; gap: 24px; border-bottom: 1px solid var(--rp-hl-med); }
.rp-tab { padding: 8px 0; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--rp-subtle); cursor: pointer; outline: none; font-weight: 500; }
.rp-tab[data-selected] { color: var(--rp-pine); border-bottom-color: var(--rp-pine); }
.rp-tab[data-hovered] { color: var(--rp-text); }
.rp-dialog .foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }
.rp-dialog h2 { margin: 0; font-size: 18px; line-height: 24px; font-weight: 700; }
.rp-dialog.narrow { width: min(480px, 90vw); }
.rp-form { display: flex; flex-direction: column; gap: 12px; }
.rp-toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.rp-toast { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 10px; background: var(--rp-text); color: var(--rp-surface); font-size: 13px; line-height: 20px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.rp-toast.negative { background: var(--rp-love); } .rp-toast.positive { background: var(--rp-pine); }
.rp-fb { display: flex; align-items: center; gap: 16px; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; padding: 0 16px; min-height: 40px; background: var(--rp-base); border-radius: 8px; }
.rp-cards { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1280px) { .rp-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.rp-check { display: grid; grid-template-columns: 1fr; align-items: center; gap: 16px; }
@media (min-width: 1024px) { .rp-check { grid-template-columns: 200px minmax(0, 1fr) auto; } }
.rp-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.rp-fail { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px solid var(--rp-hl-med); }
.rp-group-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.rp-table .rp-group-btns { flex-wrap: nowrap; }
.rp-table [role='gridcell']:has(.rp-group-btns) { overflow: visible; }
.rp-kv.inline { display: flex; gap: 24px; flex-wrap: wrap; }
+110 -3
View File
@@ -5,9 +5,10 @@ import ChevronDown from '@react-spectrum/s2/icons/ChevronDown';
const cx = (...c: Array<string | false | undefined>) => c.filter(Boolean).join(' ');
export function Button({children, onPress, quiet, small, icon, accent, label}: {children?: ReactNode, onPress?: () => void, quiet?: boolean, small?: boolean, icon?: boolean, accent?: boolean, label?: string}) {
const btn = <RButton className={cx('rp-btn', quiet && 'quiet', small && 'sm', icon && 'icon', accent && 'accent')} onPress={onPress} aria-label={label}>{children}</RButton>;
return label ? <TooltipTrigger delay={400}><Tip>{label}</Tip>{btn}</TooltipTrigger> : btn;
export function Button({children, onPress, quiet, small, icon, accent, primary, negative, label, isDisabled, tip}: {children?: ReactNode, onPress?: () => void, quiet?: boolean, small?: boolean, icon?: boolean, accent?: boolean, primary?: boolean, negative?: boolean, label?: string, isDisabled?: boolean, tip?: string}) {
const btn = <RButton className={cx('rp-btn', quiet && 'quiet', small && 'sm', icon && 'icon', accent && 'accent', primary && 'primary', negative && 'negative')} onPress={onPress} aria-label={label} isDisabled={isDisabled}>{children}</RButton>;
const text = label ?? tip;
return text ? <TooltipTrigger delay={400}><Tip>{text}</Tip>{btn}</TooltipTrigger> : btn;
}
function Tip({children}: {children: ReactNode}) {
return <Tooltip className="rp-tip" offset={6}><OverlayArrow /> {children}</Tooltip>;
@@ -49,3 +50,109 @@ export function Light({tone, children}: {tone: 'ok' | 'warn' | 'err' | 'info', c
export function Bar({label, value, pct, color}: {label: string, value: string, pct: number, color: string}) {
return <div className="rp-bar"><div className="top"><span className="l">{label}</span><span className="v">{value}</span></div><div className="track"><div className="fill" style={{width: `${Math.max(0, Math.min(100, pct))}%`, background: color}} /></div></div>;
}
// ---- Additions for the remaining pages ----
import {useEffect, useState, type ReactElement} from 'react';
import {Switch as RSwitch, TextField as RTextField, TextArea as RTextArea, Label, Input as RInput, Table, TableHeader, Column, TableBody, Row, Cell, DialogTrigger, Modal, ModalOverlay, Dialog, Heading, Tabs as RTabs, TabList as RTabList, Tab as RTab, TabPanel as RTabPanel, type Selection, type SortDescriptor} from 'react-aria-components';
export function Switch({children, isSelected, onChange, isDisabled}: {children: ReactNode, isSelected: boolean, onChange: (v: boolean) => void, isDisabled?: boolean}) {
return <RSwitch className="rp-switch" isSelected={isSelected} onChange={onChange} isDisabled={isDisabled}><span className="track" />{children}</RSwitch>;
}
export function TextField({label, value, onChange, defaultValue, width}: {label: string, value?: string, onChange?: (v: string) => void, defaultValue?: string, width?: number}) {
return <RTextField className="rp-field" value={value} onChange={onChange} defaultValue={defaultValue} style={width ? {width} : undefined}><Label>{label}</Label><span className="rp-input"><RInput /></span></RTextField>;
}
export function TextArea({label, value, onChange}: {label: string, value: string, onChange: (v: string) => void}) {
return <RTextField className="rp-field" value={value} onChange={onChange} aria-label={label}><RTextArea /></RTextField>;
}
export function LabeledSelect({label, items, value, onChange, isDisabled, side}: {label: string, items: Item[], value: string, onChange: (k: string) => void, isDisabled?: boolean, side?: boolean}) {
const sel = (
<Select aria-label={label} selectedKey={value} onSelectionChange={(k: Key | null) => { if (k != null) onChange(String(k)); }} isDisabled={isDisabled}>
<RButton className="rp-selectbtn"><SelectValue>{({selectedItem}) => (selectedItem as Item | null)?.label ?? value}</SelectValue><ChevronDown /></RButton>
<Popover className="rp-popover" placement="bottom start"><ListBox items={items}>{i => <ListBoxItem id={i.id} className="rp-item" textValue={i.label}><span>{i.label}</span>{i.desc && <span className="desc">{i.desc}</span>}</ListBoxItem>}</ListBox></Popover>
</Select>
);
if (side) return <span className="rp-cluster"><span className="rp-label">{label}</span>{sel}</span>;
return <div className="rp-field"><span className="lbl">{label}</span>{sel}</div>;
}
export function Badge({children, tone}: {children: ReactNode, tone?: 'warn'}) {
return <span className={cx('rp-badge', tone)}>{children}</span>;
}
export function Kv({items, inline}: {items: Array<[string, string]>, inline?: boolean}) {
return <div className={cx('rp-kv', inline && 'inline')}>{items.map(([k, v]) => <div key={k}><span className="k">{k}</span><span className="v">{v}</span></div>)}</div>;
}
export function ToggleTile({selected, onPress, name, sub}: {selected: boolean, onPress: () => void, name: string, sub: string}) {
return <ToggleButton className="rp-btn xl" isSelected={selected} onChange={onPress}><span className="n">{name}</span><span className="s">{sub}</span></ToggleButton>;
}
// Table: fixed height, scrolls, optional single selection.
export type Col = {id: string, label: string, width?: number, isRowHeader?: boolean};
export function DataTable<T extends {id: string}>({label, cols, rows, render, height = 442, selected, onSelect, empty}: {label: string, cols: Col[], rows: T[], render: (r: T) => ReactNode[], height?: number, selected?: string | null, onSelect?: (id: string | null) => void, empty?: string}) {
const keys: Selection = selected ? new Set([selected]) : new Set();
return (
<div className="rp-table" style={{height}}>
<Table aria-label={label} selectionMode={onSelect ? 'single' : 'none'} selectedKeys={keys} onSelectionChange={k => onSelect && onSelect(k === 'all' ? null : (k.size ? String([...k][0]) : null))} disallowEmptySelection={!!onSelect}>
<TableHeader>{cols.map(c => <Column key={c.id} id={c.id} isRowHeader={c.isRowHeader} style={c.width ? {width: c.width} : undefined}>{c.label}</Column>)}</TableHeader>
<TableBody items={rows} renderEmptyState={() => <div className="empty">{empty ?? ''}</div>}>
{r => <Row id={r.id}>{render(r).map((cell, i) => <Cell key={cols[i].id}>{cell}</Cell>)}</Row>}
</TableBody>
</Table>
</div>
);
}
// Dialogs
export function ModalDialog({trigger, title, children, footer, narrow}: {trigger: ReactElement, title: string, children: ReactNode | ((close: () => void) => ReactNode), footer?: (close: () => void) => ReactNode, narrow?: boolean}) {
return (
<DialogTrigger>
{trigger}
<ModalOverlay className="rp-underlay" isDismissable><Modal><Dialog className={cx('rp-dialog', narrow && 'narrow')}>
{({close}) => <><Heading slot="title">{title}</Heading>{typeof children === 'function' ? children(close) : children}{footer && <div className="foot">{footer(close)}</div>}</>}
</Dialog></Modal></ModalOverlay>
</DialogTrigger>
);
}
export function Tabs({tabs, children}: {tabs: Array<[string, string]>, children: (id: string) => ReactNode}) {
return (
<RTabs className="rp-tabs">
<RTabList className="rp-tablist">{tabs.map(([id, l]) => <RTab key={id} id={id} className="rp-tab">{l}</RTab>)}</RTabList>
{tabs.map(([id]) => <RTabPanel key={id} id={id}>{children(id)}</RTabPanel>)}
</RTabs>
);
}
// Code and log frames
export function Frame({title, actions, children}: {title: ReactNode, actions?: ReactNode, children: ReactNode}) {
return <div className="rp-frame"><div className="head"><span>{title}</span>{actions}</div><div className="body">{children}</div></div>;
}
export function Line({n, err, children}: {n: number, err?: boolean, children: ReactNode}) {
return <div className={cx('rp-line', err && 'err')}><span className="n">{n}</span>{children}</div>;
}
export function DaeLine({text}: {text: string}) {
if (/^\s*#/.test(text)) return <span className="rp-cmt">{text}</span>;
const sec = text.match(/^(\s*)(global|dns|upstream|routing|request|response|subscription|group|include|fallback)(\b.*)$/);
if (sec && sec[2] === 'fallback') { const t = sec[3].match(/^: (\w+)$/); return <span>{sec[1]}<span className="rp-kw">fallback</span>: <span className="rp-out">{t?.[1]}</span></span>; }
if (sec) return <span>{sec[1]}<span className="rp-kw">{sec[2]}</span>{sec[3]}</span>;
const r = text.match(/^(\s*)(.+?) -> (\w+)(\(must\))?$/);
if (r) return <span>{r[1]}<span className="rp-arg">{r[2]}</span> -&gt; <span className="rp-out">{r[3]}{r[4]}</span></span>;
const s = text.match(/^(\s*)([\w-]+): ('.*')$/);
if (s) return <span>{s[1]}{s[2]}: <span className="rp-str">{s[3]}</span></span>;
return <span>{text}</span>;
}
export function LogLine({text}: {text: string}) {
const m = text.match(/^\[(\w+)\]\s?(.*)$/);
if (!m) return <span>{text}</span>;
const cls = m[1] === 'WARN' ? 'rp-lv-warn' : m[1] === 'ERROR' ? 'rp-lv-err' : 'rp-lv-info';
return <span><span className={'rp-lv ' + cls}>{m[1]}</span>{m[2]}</span>;
}
// Toasts: a tiny queue, rendered once by the shell.
type ToastKind = 'positive' | 'negative' | 'neutral' | 'info';
let listeners: Array<(t: {id: number, kind: ToastKind, msg: string}[]) => void> = [];
let queue: {id: number, kind: ToastKind, msg: string}[] = []; let seq = 0;
export const toast = (kind: ToastKind, msg: string) => { const id = ++seq; queue = [...queue, {id, kind, msg}]; listeners.forEach(l => l(queue)); setTimeout(() => { queue = queue.filter(t => t.id !== id); listeners.forEach(l => l(queue)); }, 5000); };
export function Toasts() {
const [items, setItems] = useState(queue);
useEffect(() => { listeners.push(setItems); return () => { listeners = listeners.filter(l => l !== setItems); }; }, []);
return <div className="rp-toasts">{items.map(t => <div key={t.id} className={cx('rp-toast', t.kind)}>{t.msg}</div>)}</div>;
}
export type {SortDescriptor};