Feat: 强制更新结构图,控制台打印结构图不包含的条目

This commit is contained in:
奇趣保罗 2025-11-04 21:42:58 +08:00
parent f0c9dbfd36
commit 61dee0b127
9 changed files with 213 additions and 17 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>my</title> <title>Translate It</title>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>

View File

@ -11,6 +11,7 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-dropdown-menu": "^2.1.16",
"@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-slot": "^1.2.3",
@ -18,11 +19,13 @@
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"lucide-react": "^0.552.0", "lucide-react": "^0.552.0",
"next-themes": "^0.4.6",
"openai": "^6.7.0", "openai": "^6.7.0",
"react": "^19.1.1", "react": "^19.1.1",
"react-dom": "^19.1.1", "react-dom": "^19.1.1",
"react-router": "^7.9.5", "react-router": "^7.9.5",
"react-virtuoso": "^4.7.11", "react-virtuoso": "^4.7.11",
"sonner": "^2.0.7",
"tailwind-merge": "^3.3.1", "tailwind-merge": "^3.3.1",
"tailwindcss": "^4.1.16" "tailwindcss": "^4.1.16"
}, },

View File

@ -8,6 +8,9 @@ importers:
.: .:
dependencies: dependencies:
'@radix-ui/react-checkbox':
specifier: ^1.3.3
version: 1.3.3(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
'@radix-ui/react-dialog': '@radix-ui/react-dialog':
specifier: ^1.1.15 specifier: ^1.1.15
version: 1.1.15(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0) version: 1.1.15(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
@ -29,6 +32,9 @@ importers:
lucide-react: lucide-react:
specifier: ^0.552.0 specifier: ^0.552.0
version: 0.552.0(react@19.2.0) version: 0.552.0(react@19.2.0)
next-themes:
specifier: ^0.4.6
version: 0.4.6(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
openai: openai:
specifier: ^6.7.0 specifier: ^6.7.0
version: 6.7.0 version: 6.7.0
@ -44,6 +50,9 @@ importers:
react-virtuoso: react-virtuoso:
specifier: ^4.7.11 specifier: ^4.7.11
version: 4.14.1(react-dom@19.2.0(react@19.2.0))(react@19.2.0) version: 4.14.1(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
sonner:
specifier: ^2.0.7
version: 2.0.7(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
tailwind-merge: tailwind-merge:
specifier: ^3.3.1 specifier: ^3.3.1
version: 3.3.1 version: 3.3.1
@ -445,6 +454,19 @@ packages:
'@types/react-dom': '@types/react-dom':
optional: true optional: true
'@radix-ui/react-checkbox@1.3.3':
resolution: {integrity: sha512-wBbpv+NQftHDdG86Qc0pIyXk5IR3tM8Vd0nWLKDcX8nNn4nXFOFwsKuqw2okA/1D/mpaAkmuyndrPJTYDNZtFw==}
peerDependencies:
'@types/react': '*'
'@types/react-dom': '*'
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
optional: true
'@types/react-dom':
optional: true
'@radix-ui/react-collection@1.1.7': '@radix-ui/react-collection@1.1.7':
resolution: {integrity: sha512-Fh9rGN0MoI4ZFUNyfFVNU4y9LUz93u9/0K+yLgA2bwRojxM8JU1DyvvMBabnZPBgMWREAJvU2jjVzq+LrFUglw==} resolution: {integrity: sha512-Fh9rGN0MoI4ZFUNyfFVNU4y9LUz93u9/0K+yLgA2bwRojxM8JU1DyvvMBabnZPBgMWREAJvU2jjVzq+LrFUglw==}
peerDependencies: peerDependencies:
@ -687,6 +709,15 @@ packages:
'@types/react': '@types/react':
optional: true optional: true
'@radix-ui/react-use-previous@1.1.1':
resolution: {integrity: sha512-2dHfToCj/pzca2Ck724OZ5L0EVrr3eHRNsG/b3xQJLA2hZpVCS99bLAX+hm1IHXDEnzU6by5z/5MIY794/a8NQ==}
peerDependencies:
'@types/react': '*'
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
optional: true
'@radix-ui/react-use-rect@1.1.1': '@radix-ui/react-use-rect@1.1.1':
resolution: {integrity: sha512-QTYuDesS0VtuHNNvMh+CjlKJ4LJickCMUAqjlE3+j8w+RlRpwyX3apEQKGFzbZGdo7XNG1tXa+bQqIE7HIXT2w==} resolution: {integrity: sha512-QTYuDesS0VtuHNNvMh+CjlKJ4LJickCMUAqjlE3+j8w+RlRpwyX3apEQKGFzbZGdo7XNG1tXa+bQqIE7HIXT2w==}
peerDependencies: peerDependencies:
@ -1450,6 +1481,12 @@ packages:
natural-compare@1.4.0: natural-compare@1.4.0:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
next-themes@0.4.6:
resolution: {integrity: sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==}
peerDependencies:
react: ^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc
react-dom: ^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc
node-releases@2.0.27: node-releases@2.0.27:
resolution: {integrity: sha512-nmh3lCkYZ3grZvqcCH+fjmQ7X+H0OeZgP40OierEaAptX4XofMh5kwNbWh7lBduUzCcV/8kZ+NDLCwm2iorIlA==} resolution: {integrity: sha512-nmh3lCkYZ3grZvqcCH+fjmQ7X+H0OeZgP40OierEaAptX4XofMh5kwNbWh7lBduUzCcV/8kZ+NDLCwm2iorIlA==}
@ -1613,6 +1650,12 @@ packages:
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
engines: {node: '>=8'} engines: {node: '>=8'}
sonner@2.0.7:
resolution: {integrity: sha512-W6ZN4p58k8aDKA4XPcx2hpIQXBRAgyiWVkYhT7CvK6D3iAu7xjvVyhQHg2/iaKJZ1XVJ4r7XuwGL+WGEK37i9w==}
peerDependencies:
react: ^18.0.0 || ^19.0.0 || ^19.0.0-rc
react-dom: ^18.0.0 || ^19.0.0 || ^19.0.0-rc
source-map-js@1.2.1: source-map-js@1.2.1:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@ -2067,6 +2110,22 @@ snapshots:
'@types/react': 19.2.2 '@types/react': 19.2.2
'@types/react-dom': 19.2.2(@types/react@19.2.2) '@types/react-dom': 19.2.2(@types/react@19.2.2)
'@radix-ui/react-checkbox@1.3.3(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)':
dependencies:
'@radix-ui/primitive': 1.1.3
'@radix-ui/react-compose-refs': 1.1.2(@types/react@19.2.2)(react@19.2.0)
'@radix-ui/react-context': 1.1.2(@types/react@19.2.2)(react@19.2.0)
'@radix-ui/react-presence': 1.1.5(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
'@radix-ui/react-primitive': 2.1.3(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)
'@radix-ui/react-use-controllable-state': 1.2.2(@types/react@19.2.2)(react@19.2.0)
'@radix-ui/react-use-previous': 1.1.1(@types/react@19.2.2)(react@19.2.0)
'@radix-ui/react-use-size': 1.1.1(@types/react@19.2.2)(react@19.2.0)
react: 19.2.0
react-dom: 19.2.0(react@19.2.0)
optionalDependencies:
'@types/react': 19.2.2
'@types/react-dom': 19.2.2(@types/react@19.2.2)
'@radix-ui/react-collection@1.1.7(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)': '@radix-ui/react-collection@1.1.7(@types/react-dom@19.2.2(@types/react@19.2.2))(@types/react@19.2.2)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)':
dependencies: dependencies:
'@radix-ui/react-compose-refs': 1.1.2(@types/react@19.2.2)(react@19.2.0) '@radix-ui/react-compose-refs': 1.1.2(@types/react@19.2.2)(react@19.2.0)
@ -2302,6 +2361,12 @@ snapshots:
optionalDependencies: optionalDependencies:
'@types/react': 19.2.2 '@types/react': 19.2.2
'@radix-ui/react-use-previous@1.1.1(@types/react@19.2.2)(react@19.2.0)':
dependencies:
react: 19.2.0
optionalDependencies:
'@types/react': 19.2.2
'@radix-ui/react-use-rect@1.1.1(@types/react@19.2.2)(react@19.2.0)': '@radix-ui/react-use-rect@1.1.1(@types/react@19.2.2)(react@19.2.0)':
dependencies: dependencies:
'@radix-ui/rect': 1.1.1 '@radix-ui/rect': 1.1.1
@ -3008,6 +3073,11 @@ snapshots:
natural-compare@1.4.0: {} natural-compare@1.4.0: {}
next-themes@0.4.6(react-dom@19.2.0(react@19.2.0))(react@19.2.0):
dependencies:
react: 19.2.0
react-dom: 19.2.0(react@19.2.0)
node-releases@2.0.27: {} node-releases@2.0.27: {}
openai@6.7.0: {} openai@6.7.0: {}
@ -3154,6 +3224,11 @@ snapshots:
shebang-regex@3.0.0: {} shebang-regex@3.0.0: {}
sonner@2.0.7(react-dom@19.2.0(react@19.2.0))(react@19.2.0):
dependencies:
react: 19.2.0
react-dom: 19.2.0(react@19.2.0)
source-map-js@1.2.1: {} source-map-js@1.2.1: {}
strip-json-comments@3.1.1: {} strip-json-comments@3.1.1: {}

View File

@ -73,7 +73,11 @@ function ExportLanguageModalImpl({
} }
// 追加结构外的剩余键,避免丢数据 // 追加结构外的剩余键,避免丢数据
for (const p of Object.keys(flat)) { for (const p of Object.keys(flat)) {
if (!added.has(p)) setByPath(p, flat[p]!); if (!added.has(p)) {
console.warn(`在结构图中未找到路径: ${p}`);
setByPath(p, flat[p]!);
}
} }
try { try {
return JSON.stringify(root, null, 2); return JSON.stringify(root, null, 2);
@ -115,7 +119,7 @@ function ExportLanguageModalImpl({
<Dialog open={open} onOpenChange={onOpenChange}> <Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-3xl"> <DialogContent className="max-w-3xl">
<DialogHeader> <DialogHeader>
<DialogTitle> JSON</DialogTitle> <DialogTitle> JSON</DialogTitle>
</DialogHeader> </DialogHeader>
<div className="space-y-3 min-w-0"> <div className="space-y-3 min-w-0">
<div className="flex flex-wrap gap-2"> <div className="flex flex-wrap gap-2">

View File

@ -10,6 +10,7 @@ import {
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { Checkbox } from "../ui/checkbox";
type Props = { type Props = {
open: boolean; open: boolean;
@ -17,6 +18,7 @@ type Props = {
projectId: string; projectId: string;
hasStructure: boolean; hasStructure: boolean;
onImported: () => void | Promise<void>; onImported: () => void | Promise<void>;
languages: string[];
}; };
function ImportLanguageModalImpl({ function ImportLanguageModalImpl({
@ -25,11 +27,13 @@ function ImportLanguageModalImpl({
projectId, projectId,
hasStructure, hasStructure,
onImported, onImported,
languages,
}: Props) { }: Props) {
const [lang, setLang] = useState(""); const [lang, setLang] = useState("");
const [importing, setImporting] = useState(false); const [importing, setImporting] = useState(false);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const fileRef = useRef<HTMLInputElement | null>(null); const fileRef = useRef<HTMLInputElement | null>(null);
const [forceOverride, setForceOverride] = useState(false);
async function handleSubmit(e: React.FormEvent) { async function handleSubmit(e: React.FormEvent) {
e.preventDefault(); e.preventDefault();
@ -57,14 +61,20 @@ function ImportLanguageModalImpl({
} catch { } catch {
throw new Error("JSON 解析失败,请检查文件内容"); throw new Error("JSON 解析失败,请检查文件内容");
} }
if (!hasStructure) {
// 如果没有结构或勾选强制覆盖,则根据文件重建结构
if (!hasStructure || forceOverride) {
const root = buildStructureFromObject(json); const root = buildStructureFromObject(json);
await upsertStructure({ projectId, root }); await upsertStructure({ projectId, root });
console.log("构建结构成功", root);
} }
// 导入翻译(可能包含结构外的键,注意需要保留额外处理)
const values = flattenValues(json); const values = flattenValues(json);
await upsertLanguageTranslations(projectId, language, values); await upsertLanguageTranslations(projectId, language, values);
setLang(""); setLang("");
if (fileRef.current) fileRef.current.value = ""; if (fileRef.current) fileRef.current.value = "";
setForceOverride(false);
onOpenChange(false); onOpenChange(false);
await onImported(); await onImported();
} catch (e) { } catch (e) {
@ -81,13 +91,14 @@ function ImportLanguageModalImpl({
if (!importing) { if (!importing) {
onOpenChange(v); onOpenChange(v);
if (!v) setError(null); if (!v) setError(null);
if (!v) setForceOverride(false);
} }
}} }}
> >
<DialogContent> <DialogContent>
<DialogHeader> <DialogHeader>
<DialogTitle> <DialogTitle>
{hasStructure ? "导入语言 JSON" : "导入翻译 JSON 并构建结构"} {hasStructure ? "导入 JSON" : "导入 JSON 并构建结构"}
</DialogTitle> </DialogTitle>
</DialogHeader> </DialogHeader>
<form onSubmit={handleSubmit} className="mt-2 space-y-3"> <form onSubmit={handleSubmit} className="mt-2 space-y-3">
@ -108,11 +119,31 @@ function ImportLanguageModalImpl({
</label> </label>
<Input <Input
placeholder="en" placeholder="en"
list="lang"
value={lang} value={lang}
onChange={(e) => setLang(e.target.value)} onChange={(e) => setLang(e.target.value)}
aria-label="语言代号" aria-label="语言代号"
/> />
<datalist id="lang">
{languages.map((lang) => (
<option key={lang} value={lang} />
))}
</datalist>
</div> </div>
{hasStructure && (
<div>
<label className="inline-flex items-center gap-2 text-sm select-none">
<Checkbox
checked={forceOverride}
onCheckedChange={(checked) => setForceOverride(checked === true)}
/>
</label>
<div className="mt-1 text-xs text-orange-500">
使
</div>
</div>
)}
{error && ( {error && (
<div className="text-sm text-red-600" role="alert"> <div className="text-sm text-red-600" role="alert">
{error} {error}
@ -125,6 +156,7 @@ function ImportLanguageModalImpl({
onClick={() => { onClick={() => {
onOpenChange(false); onOpenChange(false);
setError(null); setError(null);
setForceOverride(false);
}} }}
disabled={importing} disabled={importing}
> >

View File

@ -0,0 +1,30 @@
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { CheckIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function Checkbox({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="grid place-content-center text-current transition-none"
>
<CheckIcon className="size-3.5" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
}
export { Checkbox }

View File

@ -0,0 +1,38 @@
import {
CircleCheckIcon,
InfoIcon,
Loader2Icon,
OctagonXIcon,
TriangleAlertIcon,
} from "lucide-react";
import { useTheme } from "next-themes";
import { Toaster as Sonner, type ToasterProps } from "sonner";
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme();
return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
icons={{
success: <CircleCheckIcon className="size-4" />,
info: <InfoIcon className="size-4" />,
warning: <TriangleAlertIcon className="size-4" />,
error: <OctagonXIcon className="size-4" />,
loading: <Loader2Icon className="size-4 animate-spin" />,
}}
style={
{
"--normal-bg": "var(--popover)",
"--normal-text": "var(--popover-foreground)",
"--normal-border": "var(--border)",
"--border-radius": "var(--radius)",
} as React.CSSProperties
}
{...props}
/>
);
};
export { Toaster };

View File

@ -5,6 +5,7 @@ import { RouterProvider } from "react-router/dom";
import "./index.css"; import "./index.css";
import Home from "./pages/home.tsx"; import Home from "./pages/home.tsx";
import Editor from "./pages/editor.tsx"; import Editor from "./pages/editor.tsx";
import { Toaster } from "@/components/ui/sonner";
const router = createHashRouter([ const router = createHashRouter([
{ {
@ -19,6 +20,7 @@ const router = createHashRouter([
createRoot(document.getElementById("root")!).render( createRoot(document.getElementById("root")!).render(
<StrictMode> <StrictMode>
<RouterProvider router={router} />, <RouterProvider router={router} />
<Toaster position="top-center" />
</StrictMode> </StrictMode>
); );

View File

@ -30,6 +30,8 @@ import {
DropdownMenuItem, DropdownMenuItem,
DropdownMenuSeparator, DropdownMenuSeparator,
} from "@/components/ui/dropdown-menu"; } from "@/components/ui/dropdown-menu";
import { useClipboard } from "@/hooks/use-clipboard";
import { toast } from "sonner";
export default function Editor() { export default function Editor() {
const { id: projectId } = useParams(); const { id: projectId } = useParams();
@ -49,6 +51,8 @@ export default function Editor() {
const [fullMatch, setFullMatch] = useState(false); const [fullMatch, setFullMatch] = useState(false);
const [aiModal, setAiModal] = useState<{ open: boolean; path: string } | null>(null); const [aiModal, setAiModal] = useState<{ open: boolean; path: string } | null>(null);
const { copy } = useClipboard();
function highlightRow(index: number) { function highlightRow(index: number) {
const tryFindAndAnimate = (attempt = 0) => { const tryFindAndAnimate = (attempt = 0) => {
const root = scrollerRootRef.current as HTMLElement | null; const root = scrollerRootRef.current as HTMLElement | null;
@ -138,18 +142,27 @@ export default function Editor() {
const headerContent = useCallback(() => ( const headerContent = useCallback(() => (
<tr> <tr>
<th style={{ width: colWidth }} className="text-left px-3 py-2"></th> <th style={{ width: 200 }} className="text-left px-3 py-2"></th>
{languages.map((lang) => ( {languages.map((lang) => (
<th key={lang} style={{ width: colWidth }} className="text-left px-3 py-2 whitespace-nowrap">{lang}</th> <th key={lang} style={{ width: colWidth }} className="text-left px-3 py-2">{lang}</th>
))} ))}
<th style={{ width: "5em" }} className="text-left px-3 py-2"></th> <th style={{ width: 80 }} className="text-left px-3 py-2"></th>
</tr> </tr>
), [languages, colWidth]); ), [languages, colWidth]);
const renderItemContent = useCallback((_idx: number, entry: FlatEntry) => { const renderItemContent = useCallback((_idx: number, entry: FlatEntry) => {
const handleCopy = () => {
copy(entry.path);
toast.success("复制成功");
};
return ( return (
<> <>
<td style={{ width: colWidth }} className="px-3 py-2 font-mono whitespace-nowrap">{entry.path}</td> <td style={{ width: 200 }} className="px-3 py-2 font-mono">
<button type="button" className="w-full text-left min-h-8 leading-8 px-2 rounded hover:bg-accent" onClick={handleCopy} title="点击复制">
{entry.path}
</button>
</td>
{languages.map((lang) => { {languages.map((lang) => {
const isEditing = inline.isEditingCell(entry.path, lang); const isEditing = inline.isEditingCell(entry.path, lang);
const isSaving = inline.isSavingCell(entry.path, lang); const isSaving = inline.isSavingCell(entry.path, lang);
@ -183,7 +196,6 @@ export default function Editor() {
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button size="sm" variant="outline"> <Button size="sm" variant="outline">
<MoreVertical /> <MoreVertical />
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
@ -258,7 +270,7 @@ export default function Editor() {
return ( return (
<div className="h-screen flex flex-col"> <div className="h-screen flex flex-col">
<header className="h-14 border-b px-2 md:px-4"> <header className="h-14 px-2 md:px-4 from-blue-400 to-cyan-400 bg-linear-to-r text-white">
<div className="grid grid-cols-3 h-full items-center"> <div className="grid grid-cols-3 h-full items-center">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Button asChild size="icon" variant="ghost" aria-label="返回"> <Button asChild size="icon" variant="ghost" aria-label="返回">
@ -270,11 +282,11 @@ export default function Editor() {
<div className="text-center font-medium truncate"> <div className="text-center font-medium truncate">
{project?.name ?? "编辑器"} {project?.name ?? "编辑器"}
</div> </div>
<div className="flex items-center justify-end gap-2"> <div className="flex items-center justify-end gap-2 text-foreground">
{!structure ? ( {!structure ? (
<Button onClick={() => { setImportOpen(true); }}></Button> <Button onClick={() => { setImportOpen(true); }}></Button>
) : ( ) : (
<Button variant="outline" onClick={() => { setImportOpen(true); }}> JSON</Button> <Button variant="outline" onClick={() => { setImportOpen(true); }}> JSON</Button>
)} )}
{languages.length > 0 && ( {languages.length > 0 && (
<Button variant="outline" onClick={() => setExportOpen(true)}> JSON</Button> <Button variant="outline" onClick={() => setExportOpen(true)}> JSON</Button>
@ -300,7 +312,7 @@ export default function Editor() {
</div> </div>
</div> </div>
) : ( ) : (
<div> <div className="h-full flex flex-col">
<form className="mb-3 flex items-center gap-2" onSubmit={scrollToQuery}> <form className="mb-3 flex items-center gap-2" onSubmit={scrollToQuery}>
<Input placeholder="搜索翻译条目名称" value={query} onChange={(e) => setQuery(e.target.value)} /> <Input placeholder="搜索翻译条目名称" value={query} onChange={(e) => setQuery(e.target.value)} />
<Button <Button
@ -324,11 +336,10 @@ export default function Editor() {
</Button> </Button>
</form> </form>
<div className="border rounded-md"> <div className="flex-1 border rounded-md">
<TableVirtuoso <TableVirtuoso
ref={virtuosoRef} ref={virtuosoRef}
data={entries} data={entries}
style={{ height: "60vh" }}
fixedHeaderContent={headerContent} fixedHeaderContent={headerContent}
itemContent={renderItemContent} itemContent={renderItemContent}
components={virtuosoComponents} components={virtuosoComponents}
@ -346,6 +357,7 @@ export default function Editor() {
projectId={projectId ?? ""} projectId={projectId ?? ""}
hasStructure={!!structure} hasStructure={!!structure}
onImported={refresh} onImported={refresh}
languages={languages}
/> />
<ExportLanguageModal <ExportLanguageModal
open={exportOpen} open={exportOpen}