import { PlayIcon } from "@radix-ui/react-icons" import { useState } from "react" import { IconButton, ImageUploadButton } from "@/components/ui/button" import Shortcuts from "@/components/Shortcuts" import { useImage } from "@/hooks/useImage" import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover" import PromptInput from "./PromptInput" import { RotateCw, Image, Upload } from "lucide-react" import FileManager from "./FileManager" import { getMediaFile } from "@/lib/api" import { useStore } from "@/lib/states" import SettingsDialog from "./Settings" import { cn, fileToImage } from "@/lib/utils" import Coffee from "./Coffee" import { useToast } from "./ui/use-toast" const Header = () => { const [ file, customMask, isInpainting, serverConfig, runMannually, enableUploadMask, model, setFile, setCustomFile, runInpainting, showPrevMask, hidePrevMask, imageHeight, imageWidth, ] = useStore((state) => [ state.file, state.customMask, state.isInpainting, state.serverConfig, state.runMannually(), state.settings.enableUploadMask, state.settings.model, state.setFile, state.setCustomFile, state.runInpainting, state.showPrevMask, state.hidePrevMask, state.imageHeight, state.imageWidth, ]) const { toast } = useToast() const [maskImage, maskImageLoaded] = useImage(customMask) const [openMaskPopover, setOpenMaskPopover] = useState(false) const handleRerunLastMask = () => { runInpainting() } const onRerunMouseEnter = () => { showPrevMask() } const onRerunMouseLeave = () => { hidePrevMask() } return (
{serverConfig.enableFileManager ? ( { try { const newFile = await getMediaFile(tab, filename) setFile(newFile) } catch (e: any) { toast({ variant: "destructive", description: e.message ? e.message : e.toString(), }) return } }} /> ) : ( <> )} { setFile(file) }} >
{ let newCustomMask: HTMLImageElement | null = null try { newCustomMask = await fileToImage(file) } catch (e: any) { toast({ variant: "destructive", description: e.message ? e.message : e.toString(), }) return } if ( newCustomMask.naturalHeight !== imageHeight || newCustomMask.naturalWidth !== imageWidth ) { toast({ variant: "destructive", description: `The size of the mask must same as image: ${imageWidth}x${imageHeight}`, }) return } setCustomFile(file) if (!runMannually) { runInpainting() } }} > {customMask ? ( setOpenMaskPopover(true)} onMouseLeave={() => setOpenMaskPopover(false)} style={{ visibility: customMask ? "visible" : "hidden", outline: "none", }} onClick={() => { if (customMask) { } }} > {maskImageLoaded ? ( Custom mask ) : ( <> )} ) : ( <> )}
{file && !model.need_prompt ? ( ) : ( <> )}
{model.need_prompt ? : <>}
{serverConfig.disableModelSwitch ? <> : }
) } export default Header