mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 14:22:28 +08:00
* i18n support added
* fix: align i18n implementation with Next.js 16 guide
- Rename middleware.ts to proxy.ts (Next.js 16 convention)
- Fix params type to Promise<{lang: string}> for layout/metadata
- Add 'server-only' directive and dynamic imports to dictionaries.ts
- Add hasLocale type guard and notFound() for invalid locales
- Wrap LanguageToggle in Suspense for useSearchParams
- Fix dictionary key mismatch (learnmore -> learnMore)
- Improve Chinese translations per Gemini review:
- loading ellipsis, new -> 新建, styledMode -> 精致
- goodResponse/badResponse -> 有帮助/无帮助
- closeProtection -> 关闭确认, fileExceeds phrasing
- Improve Japanese translations per Gemini review:
- closeProtection -> ページ離脱確認
- invalidAccessCode phrasing, appendDiagram -> に追加
- styledMode -> スタイル付き
---------
Co-authored-by: dayuan.jiang <jdy.toh@gmail.com>
147 lines
4.9 KiB
TypeScript
147 lines
4.9 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, useState } from "react"
|
|
import { Button } from "@/components/ui/button"
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog"
|
|
import { Input } from "@/components/ui/input"
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select"
|
|
import { useDictionary } from "@/hooks/use-dictionary"
|
|
|
|
export type ExportFormat = "drawio" | "png" | "svg"
|
|
|
|
interface SaveDialogProps {
|
|
open: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
onSave: (filename: string, format: ExportFormat) => void
|
|
defaultFilename: string
|
|
}
|
|
|
|
export function SaveDialog({
|
|
open,
|
|
onOpenChange,
|
|
onSave,
|
|
defaultFilename,
|
|
}: SaveDialogProps) {
|
|
const dict = useDictionary()
|
|
const [filename, setFilename] = useState(defaultFilename)
|
|
const [format, setFormat] = useState<ExportFormat>("drawio")
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
setFilename(defaultFilename)
|
|
}
|
|
}, [open, defaultFilename])
|
|
|
|
const handleSave = () => {
|
|
const finalFilename = filename.trim() || defaultFilename
|
|
onSave(finalFilename, format)
|
|
onOpenChange(false)
|
|
}
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
if (e.key === "Enter") {
|
|
e.preventDefault()
|
|
handleSave()
|
|
}
|
|
}
|
|
|
|
const FORMAT_OPTIONS = [
|
|
{
|
|
value: "drawio" as const,
|
|
label: dict.save.formats.drawio,
|
|
extension: ".drawio",
|
|
},
|
|
{
|
|
value: "png" as const,
|
|
label: dict.save.formats.png,
|
|
extension: ".png",
|
|
},
|
|
{
|
|
value: "svg" as const,
|
|
label: dict.save.formats.svg,
|
|
extension: ".svg",
|
|
},
|
|
]
|
|
|
|
const currentFormat = FORMAT_OPTIONS.find((f) => f.value === format)
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="sm:max-w-md">
|
|
<DialogHeader>
|
|
<DialogTitle>{dict.save.title}</DialogTitle>
|
|
<DialogDescription>
|
|
{dict.save.description}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="space-y-4">
|
|
<div className="space-y-2">
|
|
<label className="text-sm font-medium">
|
|
{dict.save.format}
|
|
</label>
|
|
<Select
|
|
value={format}
|
|
onValueChange={(v) => setFormat(v as ExportFormat)}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{FORMAT_OPTIONS.map((opt) => (
|
|
<SelectItem
|
|
key={opt.value}
|
|
value={opt.value}
|
|
>
|
|
{opt.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<label className="text-sm font-medium">
|
|
{dict.save.filename}
|
|
</label>
|
|
<div className="flex items-stretch">
|
|
<Input
|
|
value={filename}
|
|
onChange={(e) => setFilename(e.target.value)}
|
|
onKeyDown={handleKeyDown}
|
|
placeholder={dict.save.filenamePlaceholder}
|
|
autoFocus
|
|
onFocus={(e) => e.target.select()}
|
|
className="rounded-r-none border-r-0 focus-visible:z-10"
|
|
/>
|
|
<span className="inline-flex items-center px-3 rounded-r-md border border-l-0 border-input bg-muted text-sm text-muted-foreground font-mono">
|
|
{currentFormat?.extension || ".drawio"}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button
|
|
variant="outline"
|
|
onClick={() => onOpenChange(false)}
|
|
>
|
|
{dict.common.cancel}
|
|
</Button>
|
|
<Button onClick={handleSave}>{dict.common.save}</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|