mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-15 09:06:07 +00:00
71aca2018a
* feat(a11y): label list, toolbar & dashboard actions for screen readers Phase 1 of #5486 (Android TalkBack support). Icon-only controls across the management surfaces previously announced only their untranslated icon name (e.g. "edit", "ellipsis") or nothing at all. - Add aria-label to icon-only row-action and toolbar buttons across inbounds, clients, groups, hosts, nodes and xray (outbounds/routing/dns/balancers) lists, plus the dashboard cards. - Make clickable bare icons and AntD Card actions keyboard-operable via role/tabIndex + Enter/Space (new activateOnKey helper); convert mobile dropdown triggers to buttons so they open from the keyboard. - Fix the sidebar hamburger's mislabeled aria-label (was the dashboard label) and translate previously-hardcoded outbound menu labels. New i18n keys in all 13 locales: sort, menu.openMenu, pages.xray.outbound.moveToTop. * feat(a11y): label modal, QR and copy/download controls for screen readers Phase 2 of #5486. Modal and overlay controls relied on tooltips (not a reliable accessible name) or were bare clickable icons with no keyboard or screen-reader support. - Add aria-label to copy/QR/download/info icon buttons in the inbound and client info modals, sub-links modal, QR panel, backup/log modals, and to the bare search/select inputs of the attach/detach client modals. - Make click-to-copy QR codes and the IP-log refresh/clear, geofile reload and log refresh icons keyboard-operable (role/tabIndex + Enter/Space) with translated labels. - Label the 2FA code input; drop the QrPanel download-image string fallback now that the key exists. New i18n key in all 13 locales: downloadImage. * feat(a11y): label form fields and shared form components for screen readers Phase 3 of #5486. Form controls and shared form widgets were largely unlabelled, and several remove controls were not keyboard-operable. - SettingListItem now ties its title to the control via aria-labelledby, giving accessible names to the ~90 settings-tab inputs at once. - InputAddon gains button semantics (role/tabIndex/Enter+Space) and an ariaLabel prop when used as an interactive remove control. - Sparkline charts expose a role="img" summary of their latest values. - Add aria-label to add/remove/regenerate icon buttons and bare inputs/selects across inbound, client and xray (dns/routing/balancer/ outbound) forms; make clickable remove icons keyboard-operable; mark decorative help/target icons aria-hidden; label the JSON editor, date-time clear button, header-map remove, notification select-all and remark token chips. New i18n keys in all 13 locales: regenerate, jsonEditor, pages.xray.balancer.{costMatch,costValue,costRegexp}. * chore(a11y): add eslint-plugin-jsx-a11y harness and fix flagged interactions Phase 4 of #5486. Adds eslint-plugin-jsx-a11y (recommended ruleset, scoped to .tsx) so screen-reader/keyboard regressions fail lint. - Make the mobile node-card header a proper keyboard disclosure (role=button, aria-expanded, Enter/Space activation that ignores clicks on the nested action buttons) and drop the now-redundant stop-propagation click handlers the linter flagged on card-action wrappers in the node, client and inbound mobile cards. - Disable jsx-a11y/no-autofocus: the autofocus on the login field and modal primary inputs is intentional focus management that helps screen-reader and keyboard users land on the right control. make lint passes with the a11y ruleset enforced. * feat(a11y): cover remaining deferred spots (settings tabs, sockopt, API docs) Completes the panel sweep for #5486 by labelling the spots previously left out of phases 1-4: - NotifyTimeField (Telegram notifications): the mode, interval, unit and custom-cron inputs now carry aria-labels. - The Sockopt toggle in transport options. - Settings category tabs in icons-only (mobile) mode now expose the tab name as the icon's aria-label instead of the raw icon name. - The Swagger API-docs view is wrapped in a labelled region landmark. New i18n keys in all 13 locales: pages.settings.notifyTime.{interval,unit}. * feat(a11y): label shared xray form components and remark field Code review surfaced frontend/src/lib/xray/forms/ — shared form components used by the host and inbound JSON forms — which the initial audit missed. - FinalMaskForm (TCP/UDP final-mask editor): label the icon-only add and regenerate buttons and make all six remove icons keyboard-operable (role/tabIndex/Enter+Space); adds useTranslation to its sub-components. - CustomSockoptList: the remove icon is now keyboard-operable. - SniffingFields: aria-label on the otherwise label-less destOverride select. - RemarkTemplateField: aria-label on the remark-variable picker button. New i18n key in all 13 locales: pages.inbounds.sniffingDestOverride. * feat(a11y): label client info modal and WireGuard config block After rebasing onto the WireGuard client-config feature, re-apply the ClientInfoModal copy/QR/IP-log aria-labels (the modal was restructured upstream, so the original labels did not carry over) and label the new ConfigBlock component's copy/download/QR actions. ConfigBlock's action wrapper keeps its stop-propagation handler (a non-interactive guard for the Collapse header) under a scoped jsx-a11y exception. * fix(frontend): let npm install jsx-a11y under ESLint 10 eslint-plugin-jsx-a11y@6.10.2 declares a peer range that stops at ESLint 9, but the panel is on ESLint 10, so `npm ci` aborts with ERESOLVE even though the plugin runs fine on ESLint 10 with flat config. Add an npm override so jsx-a11y accepts the project's ESLint version. This keeps normal peer resolution (recharts' react-is peer still auto-installs) — no global legacy-peer-deps and no manual react-is pin needed. * fix(a11y): size mobile row triggers and move node expand role to chevron Address automated review on #5652: - add size="small" to the inbound/client/node mobile-card "more" dropdown triggers so they match the adjacent small Switch and the established desktop RowActions pattern. - move the node card-head disclosure semantics (role/tabIndex/aria-expanded/ keyboard) onto the chevron affordance so the expand control is no longer a role="button" wrapping the Switch, info button and dropdown. Mouse click-anywhere-to-expand is preserved on the header div.
321 lines
11 KiB
TypeScript
321 lines
11 KiB
TypeScript
import { useEffect, useMemo, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button, Form, Input, Modal, Select, Space, Switch, Tooltip } from 'antd';
|
|
import { PlusOutlined, MinusOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
|
import { InputAddon } from '@/components/ui';
|
|
import { useInboundOptions } from '@/api/queries/useInboundOptions';
|
|
import { RuleFormSchema, type RuleFormValues } from '@/schemas/xray';
|
|
import { buildRemarkByTag, formatInboundTag, isApiRule } from './helpers';
|
|
|
|
export interface RoutingRule {
|
|
enabled?: boolean;
|
|
type?: string;
|
|
domain?: string | string[];
|
|
ip?: string | string[];
|
|
port?: string;
|
|
sourcePort?: string;
|
|
vlessRoute?: string;
|
|
network?: string;
|
|
sourceIP?: string | string[];
|
|
user?: string | string[];
|
|
inboundTag?: string[];
|
|
protocol?: string[];
|
|
attrs?: Record<string, string>;
|
|
outboundTag?: string;
|
|
balancerTag?: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface RuleFormModalProps {
|
|
open: boolean;
|
|
rule: RoutingRule | null;
|
|
inboundTags: string[];
|
|
outboundTags: string[];
|
|
balancerTags: string[];
|
|
onClose: () => void;
|
|
onConfirm: (rule: Record<string, unknown>) => void;
|
|
}
|
|
|
|
type FormState = RuleFormValues;
|
|
|
|
const initialForm = (): FormState => ({
|
|
enabled: true,
|
|
domain: '',
|
|
ip: '',
|
|
port: '',
|
|
sourcePort: '',
|
|
vlessRoute: '',
|
|
network: '',
|
|
sourceIP: '',
|
|
user: '',
|
|
inboundTag: [],
|
|
protocol: [],
|
|
attrs: [],
|
|
outboundTag: '',
|
|
balancerTag: '',
|
|
});
|
|
|
|
const NETWORKS = ['', 'tcp', 'udp', 'tcp,udp'];
|
|
const PROTOCOLS = ['http', 'tls', 'bittorrent', 'quic'];
|
|
|
|
function csv(value: string): string[] {
|
|
if (!value) return [];
|
|
return value.split(',').map((s) => s.trim()).filter(Boolean);
|
|
}
|
|
|
|
export default function RuleFormModal({
|
|
open,
|
|
rule,
|
|
inboundTags,
|
|
outboundTags,
|
|
balancerTags,
|
|
onClose,
|
|
onConfirm,
|
|
}: RuleFormModalProps) {
|
|
const { t } = useTranslation();
|
|
const [form, setForm] = useState<FormState>(initialForm);
|
|
const isEdit = rule != null;
|
|
|
|
const { data: inboundOptions } = useInboundOptions();
|
|
const remarkByTag = useMemo(() => buildRemarkByTag(inboundOptions || []), [inboundOptions]);
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
if (rule) {
|
|
setForm({
|
|
enabled: rule.enabled !== false,
|
|
domain: Array.isArray(rule.domain) ? rule.domain.join(',') : rule.domain || '',
|
|
ip: Array.isArray(rule.ip) ? rule.ip.join(',') : rule.ip || '',
|
|
port: rule.port || '',
|
|
sourcePort: rule.sourcePort || '',
|
|
vlessRoute: rule.vlessRoute || '',
|
|
network: rule.network || '',
|
|
sourceIP: Array.isArray(rule.sourceIP) ? rule.sourceIP.join(',') : rule.sourceIP || '',
|
|
user: Array.isArray(rule.user) ? rule.user.join(',') : rule.user || '',
|
|
inboundTag: rule.inboundTag || [],
|
|
protocol: rule.protocol || [],
|
|
attrs: rule.attrs ? Object.entries(rule.attrs) : [],
|
|
outboundTag: rule.outboundTag || '',
|
|
balancerTag: rule.balancerTag || '',
|
|
});
|
|
} else {
|
|
setForm(initialForm());
|
|
}
|
|
}, [open, rule]);
|
|
|
|
const update = <K extends keyof FormState>(key: K, value: FormState[K]) =>
|
|
setForm((prev) => ({ ...prev, [key]: value }));
|
|
|
|
function submit() {
|
|
const validated = RuleFormSchema.safeParse(form);
|
|
if (!validated.success) return;
|
|
const v = validated.data;
|
|
const built: Record<string, unknown> = {
|
|
type: 'field',
|
|
enabled: v.enabled,
|
|
domain: csv(v.domain),
|
|
ip: csv(v.ip),
|
|
port: v.port,
|
|
sourcePort: v.sourcePort,
|
|
vlessRoute: v.vlessRoute,
|
|
network: v.network,
|
|
sourceIP: csv(v.sourceIP),
|
|
user: csv(v.user),
|
|
inboundTag: v.inboundTag,
|
|
protocol: v.protocol,
|
|
attrs: Object.fromEntries(v.attrs.filter(([k]) => k)),
|
|
outboundTag: v.outboundTag === '' ? undefined : v.outboundTag,
|
|
balancerTag: v.balancerTag === '' ? undefined : v.balancerTag,
|
|
};
|
|
const out: Record<string, unknown> = {};
|
|
for (const [k, v] of Object.entries(built)) {
|
|
if (v == null) continue;
|
|
if (Array.isArray(v) && v.length === 0) continue;
|
|
if (typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) continue;
|
|
if (v === '') continue;
|
|
out[k] = v;
|
|
}
|
|
onConfirm(out);
|
|
}
|
|
|
|
const title = isEdit
|
|
? `${t('edit')} ${t('pages.xray.Routings')}`
|
|
: `+ ${t('pages.xray.Routings')}`;
|
|
const okText = isEdit ? t('pages.clients.submitEdit') : t('create');
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
title={title}
|
|
okText={okText}
|
|
cancelText={t('close')}
|
|
mask={{ closable: false }}
|
|
width={640}
|
|
onOk={submit}
|
|
onCancel={onClose}
|
|
>
|
|
<Form colon={false} labelCol={{ md: { span: 8 } }} wrapperCol={{ md: { span: 14 } }}>
|
|
<Form.Item label={t('enable')}>
|
|
<Switch
|
|
checked={form.enabled}
|
|
onChange={(checked) => update('enabled', checked)}
|
|
disabled={isApiRule(rule ?? {})}
|
|
/>
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
{t('pages.xray.ruleForm.sourceIps')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.sourceIP} onChange={(e) => update('sourceIP', e.target.value)} placeholder="0.0.0.0/8, fc00::/7, geoip:ir" />
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
{t('pages.xray.ruleForm.sourcePort')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.sourcePort} onChange={(e) => update('sourcePort', e.target.value)} placeholder="53,443,1000-2000" />
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
{t('pages.xray.ruleForm.vlessRoute')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.vlessRoute} onChange={(e) => update('vlessRoute', e.target.value)} placeholder="53,443,1000-2000" />
|
|
</Form.Item>
|
|
|
|
<Form.Item label={t('pages.inbounds.network')}>
|
|
<Select
|
|
value={form.network}
|
|
onChange={(v) => update('network', v)}
|
|
options={NETWORKS.map((n) => ({ value: n, label: n || '(any)' }))}
|
|
/>
|
|
</Form.Item>
|
|
|
|
<Form.Item label={t('pages.inbounds.protocol')}>
|
|
<Select
|
|
mode="multiple"
|
|
value={form.protocol}
|
|
onChange={(v) => update('protocol', v)}
|
|
options={PROTOCOLS.map((p) => ({ value: p, label: p }))}
|
|
/>
|
|
</Form.Item>
|
|
|
|
<Form.Item label={t('pages.xray.ruleForm.attributes')}>
|
|
<Button size="small" aria-label={t('add')} icon={<PlusOutlined />} onClick={() => update('attrs', [...form.attrs, ['', '']])} />
|
|
</Form.Item>
|
|
<Form.Item wrapperCol={{ span: 24 }}>
|
|
{form.attrs.map((attr, idx) => (
|
|
<Space.Compact key={idx} block className="mb-8">
|
|
<InputAddon>{`${idx + 1}`}</InputAddon>
|
|
<Input
|
|
value={attr[0]}
|
|
aria-label={t('pages.nodes.name')}
|
|
placeholder={t('pages.nodes.name')}
|
|
onChange={(e) => {
|
|
const next = form.attrs.map((a, i) => (i === idx ? ([e.target.value, a[1]] as [string, string]) : a));
|
|
update('attrs', next);
|
|
}}
|
|
/>
|
|
<Input
|
|
value={attr[1]}
|
|
aria-label={t('pages.xray.ruleForm.value')}
|
|
placeholder={t('pages.xray.ruleForm.value')}
|
|
onChange={(e) => {
|
|
const next = form.attrs.map((a, i) => (i === idx ? ([a[0], e.target.value] as [string, string]) : a));
|
|
update('attrs', next);
|
|
}}
|
|
/>
|
|
<Button
|
|
aria-label={t('remove')}
|
|
icon={<MinusOutlined />}
|
|
onClick={() => update('attrs', form.attrs.filter((_, i) => i !== idx))}
|
|
/>
|
|
</Space.Compact>
|
|
))}
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
IP <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.ip} onChange={(e) => update('ip', e.target.value)} placeholder="0.0.0.0/8, fc00::/7, geoip:ir" />
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
{t('domainName')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.domain} onChange={(e) => update('domain', e.target.value)} placeholder="google.com, geosite:cn" />
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
{t('pages.xray.ruleForm.user')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.user} onChange={(e) => update('user', e.target.value)} placeholder="email address" />
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.rules.useComma')}>
|
|
{t('pages.inbounds.port')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Input value={form.port} onChange={(e) => update('port', e.target.value)} placeholder="53,443,1000-2000" />
|
|
</Form.Item>
|
|
|
|
<Form.Item label={t('pages.xray.ruleForm.inboundTags')}>
|
|
<Select
|
|
mode="multiple"
|
|
value={form.inboundTag}
|
|
onChange={(v) => update('inboundTag', v)}
|
|
options={inboundTags.map((tag) => ({ value: tag, label: formatInboundTag(tag, remarkByTag) }))}
|
|
/>
|
|
</Form.Item>
|
|
|
|
<Form.Item label={t('pages.xray.ruleForm.outboundTag')}>
|
|
<Select
|
|
value={form.outboundTag}
|
|
onChange={(v) => update('outboundTag', v)}
|
|
options={outboundTags.map((tag) => ({ value: tag, label: tag || '(none)' }))}
|
|
/>
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
label={
|
|
<Tooltip title={t('pages.xray.ruleForm.balancerTagTooltip')}>
|
|
{t('pages.xray.ruleForm.balancerTag')} <QuestionCircleOutlined aria-hidden="true" />
|
|
</Tooltip>
|
|
}
|
|
>
|
|
<Select
|
|
value={form.balancerTag}
|
|
onChange={(v) => update('balancerTag', v)}
|
|
options={balancerTags.map((tag) => ({ value: tag, label: tag || '(none)' }))}
|
|
/>
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>
|
|
);
|
|
}
|