import { Box, Flex, IconButton } from '@invoke-ai/ui-library'; import { useAppSelector } from 'app/store/storeHooks'; import { useFocusRegion } from 'common/hooks/focus'; import { useAssertSingleton } from 'common/hooks/useAssertSingleton'; import { CompareToolbar } from 'features/gallery/components/ImageViewer/CompareToolbar'; import CurrentImagePreview from 'features/gallery/components/ImageViewer/CurrentImagePreview'; import { ImageComparison } from 'features/gallery/components/ImageViewer/ImageComparison'; import { ImageComparisonDroppable } from 'features/gallery/components/ImageViewer/ImageComparisonDroppable'; import { ViewerToolbar } from 'features/gallery/components/ImageViewer/ViewerToolbar'; import { selectHasImageToCompare } from 'features/gallery/store/gallerySelectors'; import type { ReactNode } from 'react'; import { memo, useRef } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import { useTranslation } from 'react-i18next'; import { PiXBold } from 'react-icons/pi'; import { useMeasure } from 'react-use'; import { useImageViewer } from './useImageViewer'; type Props = { closeButton?: ReactNode; }; const useFocusRegionOptions = { focusOnMount: true, }; export const ImageViewer = memo(({ closeButton }: Props) => { useAssertSingleton('ImageViewer'); const hasImageToCompare = useAppSelector(selectHasImageToCompare); const [containerRef, containerDims] = useMeasure(); const ref = useRef(null); useFocusRegion('viewer', ref, useFocusRegionOptions); return ( {hasImageToCompare && } {!hasImageToCompare && } {!hasImageToCompare && } {hasImageToCompare && } ); }); ImageViewer.displayName = 'ImageViewer'; export const GatedImageViewer = memo(() => { const imageViewer = useImageViewer(); if (!imageViewer.isOpen) { return null; } return } />; }); GatedImageViewer.displayName = 'GatedImageViewer'; const ImageViewerCloseButton = memo(() => { const { t } = useTranslation(); const imageViewer = useImageViewer(); useAssertSingleton('ImageViewerCloseButton'); useHotkeys('esc', imageViewer.close); return ( } variant="link" alignSelf="stretch" onClick={imageViewer.close} /> ); }); ImageViewerCloseButton.displayName = 'ImageViewerCloseButton'; const GatedImageViewerCloseButton = memo(() => { const imageViewer = useImageViewer(); if (!imageViewer.isOpen) { return null; } return ; }); GatedImageViewerCloseButton.displayName = 'GatedImageViewerCloseButton';