From 78307de9a1599187fae3471ddde6d643e8507f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 4 Aug 2026 17:15:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=A4=8D=E7=94=A8=E4=B8=8E=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E7=9A=84=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复参考素材标签的空白文本回退显示 - 重构 quick-edit 参数选择逻辑,移除嵌套三元并统一回退 - 抽取生成复用流程的参数回退与缺失素材提示逻辑 - 使用 quick-edit 提交计划中的输出尺寸构建复用时占位符 --- .../ImageCanvasGenerationSubmissionModel.ts | 39 ++++++++--- .../ImageCanvasMetadataModalView.tsx | 2 +- ...ImageCanvasGenerationSubmissionWorkflow.ts | 37 ++++++++-- .../useImageCanvasGenerationWorkflow.ts | 67 +++++++++++-------- 4 files changed, 101 insertions(+), 44 deletions(-) diff --git a/src/components/image-editor/ImageCanvasGenerationSubmissionModel.ts b/src/components/image-editor/ImageCanvasGenerationSubmissionModel.ts index c01fc2ea3..09d0c518d 100644 --- a/src/components/image-editor/ImageCanvasGenerationSubmissionModel.ts +++ b/src/components/image-editor/ImageCanvasGenerationSubmissionModel.ts @@ -148,6 +148,23 @@ function getDialogDefaultPrompt(mode: GenerateDialogState['mode']) { return 'AI 生成图片'; } +function resolveOptionalFieldWithFallback( + preferredValue: string | undefined | null, + supportedValues: readonly string[], + fallbackValues: readonly T[], + defaultValue: T, +) { + const normalizedPreferred = preferredValue?.trim() ?? ''; + if (supportedValues.includes(normalizedPreferred)) { + return normalizedPreferred as T; + } + return ( + fallbackValues.find((fallbackValue) => + supportedValues.includes(fallbackValue), + ) ?? defaultValue + ); +} + export type ImageGenerationSubmissionPlan = | { kind: 'edit'; @@ -306,17 +323,21 @@ export function buildImageGenerationSubmissionPlan({ sourceLayer.originalHeight, ); const aspectRatio = supportedAspectRatios.includes(dialog.aspectRatio ?? '') - ? dialog.aspectRatio! - : supportedAspectRatios.includes(inferredAspectRatio) - ? inferredAspectRatio - : (dimensionOptions.aspectRatios[0] ?? '1:1'); + ? dialog.aspectRatio!.trim() + : resolveOptionalFieldWithFallback( + inferredAspectRatio, + supportedAspectRatios, + dimensionOptions.aspectRatios, + '1:1', + ); const imageSize = supportedImageSizes.includes(dialog.imageSize ?? '') ? dialog.imageSize! - : supportedImageSizes.includes(inferredImageSize) - ? inferredImageSize - : (dimensionOptions.imageSizes.find((size) => size === '1K') ?? - dimensionOptions.imageSizes[0] ?? - '1K'); + : resolveOptionalFieldWithFallback( + inferredImageSize, + supportedImageSizes, + dimensionOptions.imageSizes, + '1K', + ); const outputSize = resolveEditorImageGenerationPixelSize({ model: imageModel, aspectRatio, diff --git a/src/components/image-editor/ImageCanvasMetadataModalView.tsx b/src/components/image-editor/ImageCanvasMetadataModalView.tsx index f597f6b3a..86f352fc9 100644 --- a/src/components/image-editor/ImageCanvasMetadataModalView.tsx +++ b/src/components/image-editor/ImageCanvasMetadataModalView.tsx @@ -84,7 +84,7 @@ export function ImageCanvasMetadataModalView({ {reference.title} - {reference.label ?? '参考素材'} + {reference.label?.trim() || '参考素材'} {formatReferenceType(reference.refType)} ·{' '} diff --git a/src/components/image-editor/useImageCanvasGenerationSubmissionWorkflow.ts b/src/components/image-editor/useImageCanvasGenerationSubmissionWorkflow.ts index 4ffc10762..ad8998ff6 100644 --- a/src/components/image-editor/useImageCanvasGenerationSubmissionWorkflow.ts +++ b/src/components/image-editor/useImageCanvasGenerationSubmissionWorkflow.ts @@ -257,6 +257,29 @@ const EDITOR_GENERATION_QUEUE_POLL_INTERVAL_MS = 1600; const EDITOR_GENERATION_QUEUE_TIMEOUT_MS = 20 * 60 * 1000; const EDITOR_GENERATION_QUEUE_PROJECT_REFRESH_RETRY_MS = 650; +function getCanvasCompletionPlaceholderSizeFromPlan({ + sourceLayer, + outputSize, +}: { + sourceLayer: CanvasLayer; + outputSize: string | null | undefined; +}) { + const match = /^(\d+)x(\d+)$/i.exec(outputSize?.trim() ?? ''); + if (!match) { + return { + width: sourceLayer.originalWidth, + height: sourceLayer.originalHeight, + }; + } + const width = Number(match[1]); + const height = Number(match[2]); + return { + width: Number.isFinite(width) && width > 0 ? width : sourceLayer.originalWidth, + height: + Number.isFinite(height) && height > 0 ? height : sourceLayer.originalHeight, + }; +} + type GenerationSubmissionWorkflowOptions = { layers: CanvasLayer[]; canvasSize: CanvasSize; @@ -1899,6 +1922,10 @@ export function useImageCanvasGenerationSubmissionWorkflow({ projectId, ); } + const quickEditPlaceholderSize = getCanvasCompletionPlaceholderSizeFromPlan({ + sourceLayer: submissionPlan.sourceLayer, + outputSize: submissionPlan.editInput.size, + }); const generated = await runEditorGenerationWithWalletRefresh( editEditorImage({ prompt: submissionPlan.normalizedPrompt, @@ -1920,12 +1947,10 @@ export function useImageCanvasGenerationSubmissionWorkflow({ buildRightSideCanvasCompletionPlaceholder( submissionPlan.sourceLayer, { - width: submissionPlan.sourceLayer.originalWidth, - height: submissionPlan.sourceLayer.originalHeight, - originalWidth: - submissionPlan.sourceLayer.originalWidth, - originalHeight: - submissionPlan.sourceLayer.originalHeight, + width: quickEditPlaceholderSize.width, + height: quickEditPlaceholderSize.height, + originalWidth: quickEditPlaceholderSize.width, + originalHeight: quickEditPlaceholderSize.height, }, ), }, diff --git a/src/components/image-editor/useImageCanvasGenerationWorkflow.ts b/src/components/image-editor/useImageCanvasGenerationWorkflow.ts index 27339d0c9..5e85e8284 100644 --- a/src/components/image-editor/useImageCanvasGenerationWorkflow.ts +++ b/src/components/image-editor/useImageCanvasGenerationWorkflow.ts @@ -115,6 +115,31 @@ import { type CanvasSize = { width: number; height: number }; +function getCanvasGenerationRedrawWarning({ + hasParameterFallbacks, + unavailableReferenceCount, + isNormalizedGenerationInputs, +}: { + hasParameterFallbacks: boolean; + unavailableReferenceCount: number; + isNormalizedGenerationInputs: boolean; +}) { + const hasUnavailableReferences = unavailableReferenceCount > 0; + if (hasParameterFallbacks && hasUnavailableReferences) { + return `${CANVAS_GENERATION_PARAMETER_FALLBACK_WARNING} 部分原参考素材不在当前画布或来自面板上传,未恢复,请重新选择。`; + } + if (hasParameterFallbacks) { + return CANVAS_GENERATION_PARAMETER_FALLBACK_WARNING; + } + if (!isNormalizedGenerationInputs && hasUnavailableReferences) { + return '已按旧版数据恢复,部分参数可能使用当前默认值。'; + } + if (hasUnavailableReferences) { + return '部分原参考素材不在当前画布或来自面板上传,未恢复,请重新选择。'; + } + return null; +} + type CropExpandResizeDragState = { pointerId: number; handle: CropExpandResizeHandle; @@ -1345,18 +1370,13 @@ export function useImageCanvasGenerationWorkflow({ setQuickEditPanel(null); selectSingleLayer(extractionSource.id); setActiveTool('select'); - if (hasParameterFallbacks && unavailableReferences.length) { - showGenerationWarning( - `${CANVAS_GENERATION_PARAMETER_FALLBACK_WARNING} 部分原参考素材不在当前画布或来自面板上传,未恢复,请重新选择。`, - ); - } else if (hasParameterFallbacks) { - showGenerationWarning( - CANVAS_GENERATION_PARAMETER_FALLBACK_WARNING, - ); - } else if (unavailableReferences.length) { - showGenerationWarning( - '部分原参考素材不在当前画布或来自面板上传,未恢复,请重新选择。', - ); + const redrawWarning = getCanvasGenerationRedrawWarning({ + hasParameterFallbacks, + unavailableReferenceCount: unavailableReferences.length, + isNormalizedGenerationInputs, + }); + if (redrawWarning) { + showGenerationWarning(redrawWarning); } return; } @@ -1382,22 +1402,13 @@ export function useImageCanvasGenerationWorkflow({ setQuickEditPanel(null); selectSingleLayer(null); setActiveTool(getCanvasToolForGenerationMode(sameSourceDraft.mode)); - if (hasParameterFallbacks && unavailableReferences.length) { - showGenerationWarning( - `${CANVAS_GENERATION_PARAMETER_FALLBACK_WARNING} 部分原参考素材不在当前画布或来自面板上传,未恢复,请重新选择。`, - ); - } else if (hasParameterFallbacks) { - showGenerationWarning( - CANVAS_GENERATION_PARAMETER_FALLBACK_WARNING, - ); - } else if (isNormalizedGenerationInputs && unavailableReferences.length) { - showGenerationWarning( - '部分原参考素材不在当前画布或来自面板上传,未恢复,请重新选择。', - ); - } else if (!isNormalizedGenerationInputs) { - showGenerationWarning( - '已按旧版数据恢复,部分参数可能使用当前默认值。', - ); + const redrawWarning = getCanvasGenerationRedrawWarning({ + hasParameterFallbacks, + unavailableReferenceCount: unavailableReferences.length, + isNormalizedGenerationInputs, + }); + if (redrawWarning) { + showGenerationWarning(redrawWarning); } return; }