fix: images and content editor
This commit is contained in:
@@ -271,7 +271,7 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 items-center opacity-0 group-hover:opacity-100 transition-opacity shrink-0">
|
||||
<div className="flex flex-col gap-1 items-center lg:opacity-0 group-hover:opacity-100 transition-opacity shrink-0">
|
||||
<Button variant="ghost" onClick={() => moveBlockUp(index)} disabled={index === 0} size="icon-sm">
|
||||
<ChevronUpIcon />
|
||||
</Button>
|
||||
|
||||
@@ -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 ? (
|
||||
|
||||
Reference in New Issue
Block a user