2025-12-03 21:02:26 +09:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
} from "@/components/ui/dialog";
|
2025-12-04 22:56:59 +09:00
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from "@/components/ui/select";
|
|
|
|
|
|
|
|
|
|
export type ExportFormat = "drawio" | "png" | "svg";
|
|
|
|
|
|
|
|
|
|
const FORMAT_OPTIONS: { value: ExportFormat; label: string; extension: string }[] = [
|
|
|
|
|
{ value: "drawio", label: "Draw.io XML", extension: ".drawio" },
|
|
|
|
|
{ value: "png", label: "PNG Image", extension: ".png" },
|
|
|
|
|
{ value: "svg", label: "SVG Image", extension: ".svg" },
|
|
|
|
|
];
|
2025-12-03 21:02:26 +09:00
|
|
|
|
|
|
|
|
interface SaveDialogProps {
|
|
|
|
|
open: boolean;
|
|
|
|
|
onOpenChange: (open: boolean) => void;
|
2025-12-04 22:56:59 +09:00
|
|
|
onSave: (filename: string, format: ExportFormat) => void;
|
2025-12-03 21:02:26 +09:00
|
|
|
defaultFilename: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SaveDialog({
|
|
|
|
|
open,
|
|
|
|
|
onOpenChange,
|
|
|
|
|
onSave,
|
|
|
|
|
defaultFilename,
|
|
|
|
|
}: SaveDialogProps) {
|
|
|
|
|
const [filename, setFilename] = useState(defaultFilename);
|
2025-12-04 22:56:59 +09:00
|
|
|
const [format, setFormat] = useState<ExportFormat>("drawio");
|
2025-12-03 21:02:26 +09:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (open) {
|
|
|
|
|
setFilename(defaultFilename);
|
|
|
|
|
}
|
|
|
|
|
}, [open, defaultFilename]);
|
|
|
|
|
|
|
|
|
|
const handleSave = () => {
|
|
|
|
|
const finalFilename = filename.trim() || defaultFilename;
|
2025-12-04 22:56:59 +09:00
|
|
|
onSave(finalFilename, format);
|
2025-12-03 21:02:26 +09:00
|
|
|
onOpenChange(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === "Enter") {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handleSave();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-04 22:56:59 +09:00
|
|
|
const currentFormat = FORMAT_OPTIONS.find((f) => f.value === format);
|
|
|
|
|
|
2025-12-03 21:02:26 +09:00
|
|
|
return (
|
|
|
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
|
|
|
<DialogContent className="sm:max-w-md">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>Save Diagram</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
2025-12-04 22:56:59 +09:00
|
|
|
<div className="space-y-4">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<label className="text-sm font-medium">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">Filename</label>
|
|
|
|
|
<div className="flex items-stretch">
|
|
|
|
|
<Input
|
|
|
|
|
value={filename}
|
|
|
|
|
onChange={(e) => setFilename(e.target.value)}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
placeholder="Enter filename"
|
|
|
|
|
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>
|
2025-12-03 21:02:26 +09:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleSave}>Save</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|