fix: images and content editor

This commit is contained in:
Ivan Rezchikov
2026-07-13 17:22:10 +03:00
parent fa0c2bf371
commit 8ee59bd310
4 changed files with 27 additions and 49 deletions
+21 -4
View File
@@ -49,6 +49,12 @@ function validateFile(file: File, accept: string): string | null {
return null;
}
function fileToFileList(file: File): FileList {
const dt = new DataTransfer();
dt.items.add(file);
return dt.files;
}
export function ImageUploader({ id, name, label, description, error, variant = "default", previewClassName, accept = DEFAULT_ACCEPT, required, value, onFileSelect, onRemove, isUploading, children, caption, onCaptionChange }: Props) {
const inputRef = useRef<HTMLInputElement>(null);
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
@@ -99,7 +105,12 @@ export function ImageUploader({ id, name, label, description, error, variant = "
e.preventDefault();
setIsDragOver(false);
const file = e.dataTransfer.files?.[0];
if (file) applyFile(file);
if (!file) return;
if (inputRef.current) {
inputRef.current.files = fileToFileList(file);
}
applyFile(file);
}
const displayedError = clientError ?? error;
@@ -167,11 +178,17 @@ export function ImageUploader({ id, name, label, description, error, variant = "
<Field data-invalid={!!displayedError}>
<FieldLabel htmlFor={id}>{label}</FieldLabel>
<div className="flex flex-col md:flex-row items-start gap-4">
<div
onDragOver={(e) => { e.preventDefault(); setIsDragOver(true); }}
onDragLeave={() => setIsDragOver(false)}
onDrop={handleDrop}
className="flex flex-col md:flex-row items-start gap-4"
>
<div
className={cn(
"w-28 rounded-md border border-dashed border-foreground/15 bg-muted flex items-center justify-center overflow-hidden shrink-0",
previewClassName ?? "aspect-square"
"w-28 rounded-md border border-dashed border-foreground/15 bg-muted flex items-center justify-center overflow-hidden shrink-0 transition-colors",
previewClassName ?? "aspect-square",
isDragOver && "bg-muted/60 border-foreground/30"
)}
>
{isUploading ? (