mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
feat(settings): add searchable settings navigation
This commit is contained in:
@@ -11,13 +11,7 @@ import {
|
||||
Select,
|
||||
MenuItem,
|
||||
} from '@mui/material'
|
||||
import {
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { forwardRef, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { BaseDialog } from '@/components/base'
|
||||
@@ -40,6 +34,8 @@ import {
|
||||
normalizeListenHost,
|
||||
} from '@/utils/network'
|
||||
|
||||
import { useSettingDialog } from '../settings-search-context'
|
||||
|
||||
interface TunnelsViewerRef {
|
||||
open: () => void
|
||||
close: () => void
|
||||
@@ -93,7 +89,7 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
const [values, setValues] = useState<TunnelFormValues>(buildInitialValues)
|
||||
const [draftTunnels, setDraftTunnels] = useState<TunnelEntry[]>([])
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
useSettingDialog(ref, 'tunnels-viewer', open, () => ({
|
||||
open: () => {
|
||||
setValues(buildInitialValues())
|
||||
setDraftTunnels(() => clash?.tunnels ?? [])
|
||||
@@ -301,10 +297,14 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
}}
|
||||
onOk={handleSave}
|
||||
>
|
||||
<span data-settings-dialog="tunnels-viewer" />
|
||||
<List>
|
||||
{draftTunnels.length > 0 && (
|
||||
<>
|
||||
<ListItem sx={{ padding: '4px 0', opacity: 0.6 }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.existing"
|
||||
sx={{ padding: '4px 0', opacity: 0.6 }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={t(
|
||||
'settings.sections.clash.form.fields.tunnels.existing',
|
||||
@@ -314,6 +314,7 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
<List component="nav">
|
||||
{tunnelEntries.map((item) => (
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.default"
|
||||
key={`${item.key}`}
|
||||
sx={{ padding: '4px 0' }}
|
||||
secondaryAction={
|
||||
@@ -342,6 +343,7 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
)}
|
||||
<ListItemButton
|
||||
sx={{ padding: '4px 0', opacity: 0.8 }}
|
||||
data-setting-target="tunnels-expand"
|
||||
onClick={() => setExpanded((v) => !v)}
|
||||
>
|
||||
<ListItemText
|
||||
@@ -352,7 +354,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
{expanded ? <ExpandLess /> : <ExpandMore />}
|
||||
</ListItemButton>
|
||||
{expanded && (
|
||||
<ListItem sx={{ padding: '8px 0' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.protocols"
|
||||
sx={{ padding: '8px 0' }}
|
||||
>
|
||||
<div style={{ width: '100%' }}>
|
||||
{/* 输入框区域 */}
|
||||
{/* 协议 */}
|
||||
@@ -380,7 +385,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
</ListItem>
|
||||
|
||||
{/* 本地监听地址 */}
|
||||
<ListItem sx={{ padding: '6px 2px' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.localAddr"
|
||||
sx={{ padding: '6px 2px' }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={t(
|
||||
'settings.sections.clash.form.fields.tunnels.localAddr',
|
||||
@@ -399,7 +407,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
</ListItem>
|
||||
|
||||
{/* 本地监听端口 */}
|
||||
<ListItem sx={{ padding: '6px 2px' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.localPort"
|
||||
sx={{ padding: '6px 2px' }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={t(
|
||||
'settings.sections.clash.form.fields.tunnels.localPort',
|
||||
@@ -419,7 +430,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
</ListItem>
|
||||
|
||||
{/* 目标服务器地址 */}
|
||||
<ListItem sx={{ padding: '6px 2px' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.targetAddr"
|
||||
sx={{ padding: '6px 2px' }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={t(
|
||||
'settings.sections.clash.form.fields.tunnels.targetAddr',
|
||||
@@ -438,7 +452,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
</ListItem>
|
||||
|
||||
{/* 目标服务器端口 */}
|
||||
<ListItem sx={{ padding: '6px 2px' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.targetPort"
|
||||
sx={{ padding: '6px 2px' }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={t(
|
||||
'settings.sections.clash.form.fields.tunnels.targetPort',
|
||||
@@ -458,7 +475,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
</ListItem>
|
||||
|
||||
{/* 代理组 */}
|
||||
<ListItem sx={{ padding: '6px 2px' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.proxyGroup"
|
||||
sx={{ padding: '6px 2px' }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={
|
||||
<>
|
||||
@@ -520,7 +540,10 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
</ListItem>
|
||||
|
||||
{/* 代理节点 */}
|
||||
<ListItem sx={{ padding: '6px 2px' }}>
|
||||
<ListItem
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.proxyNode"
|
||||
sx={{ padding: '6px 2px' }}
|
||||
>
|
||||
<ListItemText
|
||||
primary={
|
||||
<>
|
||||
@@ -581,6 +604,7 @@ export const TunnelsViewer = forwardRef<TunnelsViewerRef>((_, ref) => {
|
||||
|
||||
{/* 添加按钮 */}
|
||||
<Button
|
||||
data-setting-target="settings.sections.clash.form.fields.tunnels.actions.add"
|
||||
variant="contained"
|
||||
size="small"
|
||||
sx={{
|
||||
|
||||
Reference in New Issue
Block a user