mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
chore: add rule list search-box
This commit is contained in:
parent
b558202441
commit
86e43123b0
|
@ -9,6 +9,9 @@ import useRegularExpressionIcon from "@/assets/image/component/use_regular_expre
|
||||||
|
|
||||||
type SearchProps = {
|
type SearchProps = {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
matchCase?: boolean;
|
||||||
|
matchWholeWord?: boolean;
|
||||||
|
useRegularExpression?: boolean;
|
||||||
onSearch: (
|
onSearch: (
|
||||||
match: (content: string) => boolean,
|
match: (content: string) => boolean,
|
||||||
state: {
|
state: {
|
||||||
|
@ -23,9 +26,13 @@ type SearchProps = {
|
||||||
export const BaseSearchBox = styled((props: SearchProps) => {
|
export const BaseSearchBox = styled((props: SearchProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const [matchCase, setMatchCase] = useState(true);
|
const [matchCase, setMatchCase] = useState(props.matchCase ?? true);
|
||||||
const [matchWholeWord, setMatchWholeWord] = useState(false);
|
const [matchWholeWord, setMatchWholeWord] = useState(
|
||||||
const [useRegularExpression, setUseRegularExpression] = useState(false);
|
props.matchWholeWord ?? false
|
||||||
|
);
|
||||||
|
const [useRegularExpression, setUseRegularExpression] = useState(
|
||||||
|
props.useRegularExpression ?? false
|
||||||
|
);
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
||||||
const iconStyle = {
|
const iconStyle = {
|
||||||
|
|
|
@ -46,10 +46,14 @@ export const RuleItem = (props: Props) => {
|
||||||
primary={
|
primary={
|
||||||
<>
|
<>
|
||||||
<Typography
|
<Typography
|
||||||
sx={{ textDecoration: type === "delete" ? "line-through" : "" }}
|
sx={{
|
||||||
|
textDecoration: type === "delete" ? "line-through" : "",
|
||||||
|
overflow: "hidden",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
}}
|
||||||
variant="h6"
|
variant="h6"
|
||||||
component="span"
|
title={rule.length === 3 ? rule[1] : "-"}
|
||||||
noWrap
|
|
||||||
>
|
>
|
||||||
{rule.length === 3 ? rule[1] : "-"}
|
{rule.length === 3 ? rule[1] : "-"}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
|
@ -34,6 +34,7 @@ import { readProfileFile, saveProfileFile } from "@/services/cmds";
|
||||||
import { Notice, Switch } from "@/components/base";
|
import { Notice, Switch } from "@/components/base";
|
||||||
import getSystem from "@/utils/get-system";
|
import getSystem from "@/utils/get-system";
|
||||||
import { RuleItem } from "@/components/profile/rule-item";
|
import { RuleItem } from "@/components/profile/rule-item";
|
||||||
|
import { BaseSearchBox } from "../base/base-search-box";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
profileUid: string;
|
profileUid: string;
|
||||||
|
@ -230,6 +231,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const [prevData, setPrevData] = useState("");
|
const [prevData, setPrevData] = useState("");
|
||||||
|
const [match, setMatch] = useState(() => (_: string) => true);
|
||||||
|
|
||||||
const [ruleType, setRuleType] = useState<(typeof rules)[number]>(rules[0]);
|
const [ruleType, setRuleType] = useState<(typeof rules)[number]>(rules[0]);
|
||||||
const [ruleContent, setRuleContent] = useState("");
|
const [ruleContent, setRuleContent] = useState("");
|
||||||
|
@ -476,9 +478,16 @@ export const RulesEditorViewer = (props: Props) => {
|
||||||
width: "50%",
|
width: "50%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
overflowY: "auto",
|
overflowY: "auto",
|
||||||
marginLeft: "10px",
|
overflowX: "hidden",
|
||||||
|
padding: "0 10px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<div style={{ position: "sticky", top: 0, zIndex: 10 }}>
|
||||||
|
<BaseSearchBox
|
||||||
|
matchCase={false}
|
||||||
|
onSearch={(match) => setMatch(() => match)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{prependSeq.length > 0 && (
|
{prependSeq.length > 0 && (
|
||||||
<DndContext
|
<DndContext
|
||||||
sensors={sensors}
|
sensors={sensors}
|
||||||
|
@ -509,22 +518,24 @@ export const RulesEditorViewer = (props: Props) => {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<List>
|
<List>
|
||||||
{ruleList.map((item, index) => {
|
{ruleList
|
||||||
return (
|
.filter((item) => match(item))
|
||||||
<RuleItem
|
.map((item, index) => {
|
||||||
key={`${item}-${index}`}
|
return (
|
||||||
type={deleteSeq.includes(item) ? "delete" : "original"}
|
<RuleItem
|
||||||
ruleRaw={item}
|
key={`${item}-${index}`}
|
||||||
onDelete={() => {
|
type={deleteSeq.includes(item) ? "delete" : "original"}
|
||||||
if (deleteSeq.includes(item)) {
|
ruleRaw={item}
|
||||||
setDeleteSeq(deleteSeq.filter((v) => v !== item));
|
onDelete={() => {
|
||||||
} else {
|
if (deleteSeq.includes(item)) {
|
||||||
setDeleteSeq([...deleteSeq, item]);
|
setDeleteSeq(deleteSeq.filter((v) => v !== item));
|
||||||
}
|
} else {
|
||||||
}}
|
setDeleteSeq([...deleteSeq, item]);
|
||||||
/>
|
}
|
||||||
);
|
}}
|
||||||
})}
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
{appendSeq.length > 0 && (
|
{appendSeq.length > 0 && (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user