import { type CSSProperties, type Dispatch, type ReactNode, type RefObject, type SetStateAction, } from 'react'; import { ImagePlus } from 'lucide-react'; import { PlatformActionButton } from '../common/PlatformActionButton'; import { PlatformFieldLabel } from '../common/PlatformFieldLabel'; import { PlatformFloatingMenu, PlatformFloatingMenuItem, } from '../common/PlatformFloatingMenu'; import { PlatformStatusMessage } from '../common/PlatformStatusMessage'; import { PlatformSelectField, PlatformTextField, } from '../common/PlatformTextField'; import { CHARACTER_SPEC_VIEW_OPTIONS, SPEC_GENERATION_COST, } from './ImageCanvasGenerationModel'; import type { GenerateDialogState, SpecFormValues, SpecGenerationType, UploadTarget, } from './ImageCanvasEditorTypes'; type ImageCanvasSpecGenerationPanelViewProps = { dialog: GenerateDialogState; style: CSSProperties; isGenerationReferenceMenuOpen?: boolean; generationReferenceButtonRef?: RefObject; setIsGenerationReferenceMenuOpen?: Dispatch>; setIsPickingGenerationReferenceFromCanvas?: Dispatch>; setGenerateDialog?: Dispatch>; renderEditorPortal?: (node: ReactNode) => ReactNode; buildPortalMenuStyle?: ( anchor: HTMLElement | null, placement: 'above' | 'below', ) => CSSProperties; onOpenSpecDialog?: (specType: SpecGenerationType) => void; onUpdateSpecFormValue: (key: keyof SpecFormValues, value: string) => void; onRequestUpload: (target: UploadTarget) => void; onSubmit: (dialog: GenerateDialogState) => void; }; export function ImageCanvasSpecGenerationPanelView({ dialog, style, isGenerationReferenceMenuOpen = false, generationReferenceButtonRef, setIsGenerationReferenceMenuOpen, setIsPickingGenerationReferenceFromCanvas, setGenerateDialog, renderEditorPortal = (node) => node, buildPortalMenuStyle = () => ({}), onOpenSpecDialog, onUpdateSpecFormValue, onRequestUpload, onSubmit, }: ImageCanvasSpecGenerationPanelViewProps) { const isUiDesignDialog = dialog.mode === 'ui-design'; const referenceLabel = isUiDesignDialog ? 'UI设计图标素材规范' : '参考图'; const uploadTarget: UploadTarget = isUiDesignDialog ? 'ui-design-icon-spec' : 'spec-reference'; const reference = isUiDesignDialog ? dialog.uiDesignSpecReference : dialog.specReference; const openReferenceMenu = () => { if (setIsGenerationReferenceMenuOpen) { setIsGenerationReferenceMenuOpen((open) => !open); return; } onRequestUpload(uploadTarget); }; return ( <>
event.stopPropagation()} onSubmit={(event) => { event.preventDefault(); if (dialog.status !== 'generating') { onSubmit(dialog); } }} >
{isUiDesignDialog ? ( ) : dialog.specType === 'custom' ? ( ) : ( <> {dialog.specType === 'character' ? ( <> ) : null} )} {isUiDesignDialog || dialog.specType ? (
{referenceLabel}
) : null}
{dialog.status === 'failed' ? ( {dialog.errorMessage} ) : null}
{dialog.status === 'generating' ? '生成中' : `消耗${SPEC_GENERATION_COST}泥点 · 生成`}
{isGenerationReferenceMenuOpen && generationReferenceButtonRef ? renderEditorPortal( { setIsGenerationReferenceMenuOpen?.(false); setIsPickingGenerationReferenceFromCanvas?.(true); }} > 从画布中选择 {isUiDesignDialog ? ( { setIsGenerationReferenceMenuOpen?.(false); onOpenSpecDialog?.('icon'); }} > 新建图标素材规范 ) : null} { setIsGenerationReferenceMenuOpen?.(false); setIsPickingGenerationReferenceFromCanvas?.(false); onRequestUpload(uploadTarget); }} > 上传图片 , ) : null} ); }