import type { FC } from 'react' import { Fragment, useEffect, useState, } from 'react' import { useTranslation } from 'react-i18next' import Uploader from './uploader' import ImageLinkInput from './image-link-input' import ImageList from './image-list' import { useImageFiles } from './hooks' import { ImagePlus } from '@/app/components/base/icons/src/vender/line/images' import { Link03 } from '@/app/components/base/icons/src/vender/line/general' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import type { ImageFile, VisionSettings } from '@/types/app' import { TransferMethod } from '@/types/app' type PasteImageLinkButtonProps = { onUpload: (imageFile: ImageFile) => void disabled?: boolean } const PasteImageLinkButton: FC = ({ onUpload, disabled, }) => { const { t } = useTranslation() const [open, setOpen] = useState(false) const handleUpload = (imageFile: ImageFile) => { setOpen(false) onUpload(imageFile) } const handleToggle = () => { if (disabled) return setOpen(v => !v) } return (
{t('common.imageUploader.pasteImageLink')}
) } type TextGenerationImageUploaderProps = { settings: VisionSettings onFilesChange: (files: ImageFile[]) => void } const TextGenerationImageUploader: FC = ({ settings, onFilesChange, }) => { const { t } = useTranslation() const { files, onUpload, onRemove, onImageLinkLoadError, onImageLinkLoadSuccess, onReUpload, } = useImageFiles() useEffect(() => { onFilesChange(files) }, [files]) const localUpload = ( = settings.number_limits} limit={+settings.image_file_size_limit!} > { hovering => (
{t('common.imageUploader.uploadFromComputer')}
) }
) const urlUpload = ( = settings.number_limits} /> ) return (
{ settings.transfer_methods.map((method) => { if (method === TransferMethod.local_file) return {localUpload} if (method === TransferMethod.remote_url) return {urlUpload} return null }) }
) } export default TextGenerationImageUploader