refactor: dropzone update

This commit is contained in:
2026-08-22 15:04:49 +05:00
parent 06c6716cf5
commit 7afd07e8c1
2 changed files with 13 additions and 10 deletions
+7 -10
View File
@@ -1,24 +1,21 @@
<script lang="ts">
import { ACCEPTED_IMAGE_TYPES } from '$lib/core/io';
import { ACCEPTED_IMAGE_TYPES, isSupportedImage } from '$lib/core/io';
let {
onFile,
onError,
label = 'Перетащите изображение сюда или нажмите, чтобы выбрать файл'
}: {
interface Props {
onFile: (file: File) => void;
onError?: (message: string) => void;
label?: string;
} = $props();
}
let { onFile, onError, label = 'Перетащите изображение сюда или нажмите, чтобы выбрать файл' }: Props =
$props();
let input = $state<HTMLInputElement | undefined>();
let dragging = $state(false);
const acceptedMimes = new Set(ACCEPTED_IMAGE_TYPES.split(','));
function accept(file: File | undefined | null) {
if (!file) return;
if (!acceptedMimes.has(file.type)) {
if (!isSupportedImage(file)) {
onError?.(
`Неподдерживаемый формат файла (${file.type || 'неизвестный'}). Поддерживаются PNG, JPEG, WebP, GIF и BMP.`
);