"use client"; import * as React from "react"; import { Plus, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { newKv, type KV } from "./types"; /** Editable key/value rows (headers, query params, cookies). */ export function KvRows({ rows, onChange, keyPlaceholder = "Name", valuePlaceholder = "Value", addLabel = "Add", label, secret, }: { rows: KV[]; onChange: (rows: KV[]) => void; keyPlaceholder?: string; valuePlaceholder?: string; addLabel?: string; /** Accessible label prefix for inputs. */ label: string; /** Mask values (e.g. cookies). */ secret?: boolean; }) { const update = (id: string, patch: Partial) => onChange(rows.map((r) => (r.id === id ? { ...r, ...patch } : r))); const remove = (id: string) => onChange(rows.filter((r) => r.id !== id)); const add = () => onChange([...rows, newKv()]); const lastKeyRef = React.useRef(null); const [focusNew, setFocusNew] = React.useState(false); React.useEffect(() => { if (focusNew && lastKeyRef.current) { lastKeyRef.current.focus(); setFocusNew(false); } }, [focusNew, rows.length]); return (
{rows.length === 0 ?

None.

: null} {rows.map((r, i) => (
update(r.id, { key: e.target.value })} placeholder={keyPlaceholder} aria-label={`${label} ${i + 1} name`} className="h-8 font-mono text-[12.5px]" autoCapitalize="off" autoCorrect="off" spellCheck={false} /> update(r.id, { value: e.target.value })} placeholder={valuePlaceholder} aria-label={`${label} ${i + 1} value`} className="h-8 font-mono text-[12.5px]" autoCapitalize="off" autoCorrect="off" spellCheck={false} onKeyDown={(e) => { if (e.key === "Enter" && i === rows.length - 1 && r.key.trim()) { e.preventDefault(); add(); setFocusNew(true); } }} />
))}
); }