diff --git a/frontend/src/components/tools/ToolRenderer.tsx b/frontend/src/components/tools/ToolRenderer.tsx index 032d84828..06c5157a8 100644 --- a/frontend/src/components/tools/ToolRenderer.tsx +++ b/frontend/src/components/tools/ToolRenderer.tsx @@ -45,6 +45,13 @@ files, onPreviewFile={onPreviewFile} /> ); + case "convert": + return ( + + ); case "merge": return ( void; + getAvailableToExtensions: (fromExtension: string) => Array<{value: string, label: string, group: string}>; + disabled?: boolean; +} + +const ConvertSettings = ({ + parameters, + onParameterChange, + getAvailableToExtensions, + disabled = false +}: ConvertSettingsProps) => { + const { t } = useTranslation(); + + const handleFromExtensionChange = (value: string | null) => { + if (value) { + onParameterChange('fromExtension', value); + // Reset to extension when from extension changes + onParameterChange('toExtension', ''); + // Reset format-specific options + onParameterChange('imageOptions', { + colorType: COLOR_TYPES.COLOR, + dpi: 300, + singleOrMultiple: OUTPUT_OPTIONS.MULTIPLE, + }); + } + }; + + const handleToExtensionChange = (value: string | null) => { + if (value) { + onParameterChange('toExtension', value); + // Reset format-specific options when target extension changes + onParameterChange('imageOptions', { + colorType: COLOR_TYPES.COLOR, + dpi: 300, + singleOrMultiple: OUTPUT_OPTIONS.MULTIPLE, + }); + } + }; + + return ( + + {/* Format Selection */} + + + {t("convert.convertFrom", "Convert from")}: + + ({ value: option.value, label: option.label }))} + disabled={!parameters.fromExtension || disabled} + searchable + clearable + placeholder="Select target file format" + /> + + + {/* Format-specific options */} + {['png', 'jpg'].includes(parameters.toExtension) && ( + <> + + + {t("convert.imageOptions", "Image Options")}: + + val && onParameterChange('imageOptions', { + ...parameters.imageOptions, + singleOrMultiple: val as typeof OUTPUT_OPTIONS[keyof typeof OUTPUT_OPTIONS] + })} + data={[ + { value: OUTPUT_OPTIONS.SINGLE, label: t("convert.single", "Single") }, + { value: OUTPUT_OPTIONS.MULTIPLE, label: t("convert.multiple", "Multiple") }, + ]} + disabled={disabled} + /> + + + )} + + + {/* Color options for image to PDF conversion */} + {['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'webp'].includes(parameters.fromExtension) && parameters.toExtension === 'pdf' && ( + <> + + + {t("convert.pdfOptions", "PDF Options")}: + - -
- - {t("convert.convertTo", "Convert to")}: - - val && setColorType(val)} - data={[ - { value: 'color', label: t("convert.color", "Color") }, - { value: 'greyscale', label: t("convert.greyscale", "Greyscale") }, - { value: 'blackwhite', label: t("convert.blackwhite", "Black & White") }, - ]} - /> - typeof val === 'number' && setDpi(val)} - min={72} - max={600} - step={1} - /> - - val && setOutputFormat(val)} - data={ - toFormat === 'office-word' ? [ - { value: 'docx', label: t("convert.wordDocExt") }, - { value: 'odt', label: t("convert.odtExt") }, - ] : - toFormat === 'office-presentation' ? [ - { value: 'pptx', label: t("convert.pptExt") }, - { value: 'odp', label: t("convert.odpExt") }, - ] : - toFormat === 'office-text' ? [ - { value: 'txt', label: t("convert.txtExt") }, - { value: 'rtf', label: t("convert.rtfExt") }, - ] : [] - } - /> - - )} - - {fromFormat === 'image' && toFormat === 'pdf' && ( - - {t("convert.pdfOptions", "PDF Options")}: -