feat(waf): 规则编辑器节点自定义命名与拖放添加

对齐后端 label 字段;属性栏可编辑显示名称;节点库改为拖到画布落点创建。
This commit is contained in:
ryan
2026-07-19 11:01:24 +08:00
parent 4166cc9861
commit b5e27fabde
10 changed files with 653 additions and 57 deletions
@@ -1,31 +1,39 @@
import { Ban, Fingerprint, Globe2, Plus, ShieldCheck } from 'lucide-react';
import { Ban, Fingerprint, Globe2, ShieldCheck } from 'lucide-react';
import { Button } from '@/components/ui/button';
import type { WAFRuleNode } from '@/lib/services/openflare';
type AddableType = Extract<
WAFRuleNode['type'],
'ip_match' | 'geo_match' | 'pow' | 'block'
>;
import {
NODE_TYPE_LABELS,
WAF_NODE_DRAG_MIME,
type AddableNodeType,
} from './node-factory';
const items = [
{ type: 'ip_match', label: 'IP 匹配', icon: Fingerprint },
{ type: 'geo_match', label: '地域匹配', icon: Globe2 },
{ type: 'pow', label: 'PoW 挑战', icon: ShieldCheck },
{ type: 'block', label: '阻止', icon: Ban },
] satisfies { type: AddableType; label: string; icon: typeof Plus }[];
{ type: 'ip_match' as const, icon: Fingerprint },
{ type: 'geo_match' as const, icon: Globe2 },
{ type: 'pow' as const, icon: ShieldCheck },
{ type: 'block' as const, icon: Ban },
] satisfies { type: AddableNodeType; icon: typeof Fingerprint }[];
export function NodeLibrary({ onAdd }: { onAdd: (type: AddableType) => void }) {
export function NodeLibrary() {
return (
<div className='flex items-center gap-2'>
{items.map(({ type, label, icon: Icon }) => (
{items.map(({ type, icon: Icon }) => (
<Button
key={type}
type='button'
variant='outline'
size='sm'
onClick={() => onAdd(type)}
draggable
className='cursor-grab active:cursor-grabbing'
onDragStart={(event) => {
event.dataTransfer.setData(WAF_NODE_DRAG_MIME, type);
event.dataTransfer.setData('text/plain', type);
event.dataTransfer.effectAllowed = 'copy';
}}
>
<Icon data-icon='inline-start' />
{label}
{NODE_TYPE_LABELS[type]}
</Button>
))}
</div>