feat(frontend): add canvas agent empty state with server-driven starters

Render a CanvasAgentEmptyState in the Agent panel that fetches localized
starter content from the new agent-starters endpoint, with local defaults
as fallback. Clicking a starter focuses the prompt composer (new focus
handle). Includes accompanying UI polish: side-nav cleanup, animated
prompt examples, and canvas panel spacing tweaks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-10 22:19:22 +08:00
parent c94b163540
commit 71a1b3ace4
16 changed files with 472 additions and 77 deletions
@@ -0,0 +1,55 @@
import type { AgentStarterConfig } from "@/domain/design";
type Translate = (key: string) => string;
const starterPrompts = {
ecommerce: "Create a premium ecommerce product image for a portable espresso machine, with realistic lighting, clean composition, benefit callouts, and marketplace-ready visual hierarchy",
poster: "Design a bold launch poster for a new skincare product line, with strong typography, product focus, campaign headline, date, and a polished premium layout",
brandVisual: "Create a brand identity direction for a modern wellness drink brand, including color palette, typography mood, logo usage, packaging accents, and social-ready visual elements",
socialMedia: "Create a square Instagram promotion for a weekend fashion sale, with product cutouts, discount headline, brand colors, and a layout that works as a paid social ad",
logo: "Design a clean vector logo for a direct-to-consumer home goods brand named Loom & Line, with a simple mark, balanced wordmark, and clear black-and-white usage"
} as const;
export function defaultAgentStarterConfig(t: Translate): AgentStarterConfig {
return {
title: t("agentEmptyTitle"),
description: t("agentEmptyDescription"),
previewImages: [
"https://static.codia.ai/public/images/f788bdcc/lg.webp",
"https://static.codia.ai/public/images/ec25067a/lg.webp",
"https://static.codia.ai/public/images/d4ccbe39/lg.webp"
],
starters: [
{ id: "ecommerce", label: t("agentStarterEcommerce"), prompt: starterPrompts.ecommerce },
{ id: "poster", label: t("agentStarterPoster"), prompt: starterPrompts.poster },
{ id: "brand-visual", label: t("agentStarterBrandVisual"), prompt: starterPrompts.brandVisual },
{ id: "social-media", label: t("agentStarterSocialMedia"), prompt: starterPrompts.socialMedia },
{ id: "logo", label: t("agentStarterLogo"), prompt: starterPrompts.logo }
]
};
}
export function normalizeAgentStarterConfig(config: AgentStarterConfig, fallback: AgentStarterConfig): AgentStarterConfig {
const previewImages = Array.isArray(config.previewImages) ? config.previewImages.map((image) => image.trim()).filter(Boolean).slice(0, 3) : [];
const seen = new Set<string>();
const starters = Array.isArray(config.starters)
? config.starters
.map((starter) => ({
id: starter.id.trim(),
label: starter.label.trim(),
prompt: starter.prompt.trim()
}))
.filter((starter) => {
if (!starter.id || !starter.label || !starter.prompt || seen.has(starter.id)) return false;
seen.add(starter.id);
return true;
})
: [];
return {
title: config.title?.trim() || fallback.title,
description: config.description?.trim() || fallback.description,
previewImages: previewImages.length > 0 ? previewImages : fallback.previewImages,
starters: starters.length > 0 ? starters : fallback.starters
};
}
@@ -0,0 +1,154 @@
.canvas-agent-empty-state {
width: 100%;
min-height: 100%;
flex: 1 0 auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 28px 20px 36px;
text-align: center;
}
.canvas-agent-empty-visual {
height: 130px;
display: flex;
align-items: flex-end;
justify-content: center;
margin-bottom: 30px;
}
.canvas-agent-empty-image {
position: relative;
width: 80px;
height: 105px;
display: block;
flex: 0 0 auto;
overflow: hidden;
border: 1px solid rgba(20, 20, 20, 0.08);
border-radius: 12px;
background: #f2f2f0;
box-shadow: 0 12px 26px rgba(20, 20, 20, 0.14);
}
.canvas-agent-empty-image.left {
z-index: 1;
transform: rotate(-8deg);
transform-origin: right bottom;
}
.canvas-agent-empty-image.center {
z-index: 2;
width: 100px;
height: 130px;
margin-inline: -8px;
}
.canvas-agent-empty-image:only-child.center {
margin-inline: 0;
}
.canvas-agent-empty-image.right {
z-index: 1;
transform: rotate(6deg);
transform-origin: left bottom;
}
.canvas-agent-empty-image img {
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
.canvas-agent-empty-state h2 {
margin: 0 0 8px;
color: #202124;
font-size: 20px;
font-weight: 650;
line-height: 1.4;
}
.canvas-agent-empty-state p {
margin: 0 0 28px;
color: #96999f;
font-size: 14px;
font-weight: 400;
line-height: 1.6;
}
.canvas-agent-starters {
width: 100%;
max-width: 390px;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 12px;
}
.canvas-agent-starters button {
min-height: 42px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 9px 20px;
border: 1px solid #e1e3e6;
border-radius: 999px;
color: #27282b;
background: #fff;
font: inherit;
font-size: 14px;
font-weight: 500;
line-height: 1.5;
white-space: nowrap;
box-shadow: 0 1px 2px rgba(20, 20, 20, 0.02);
transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.canvas-agent-starters button:hover {
border-color: #d5d8dc;
background: #f7f7f6;
transform: translateY(-1px);
}
.canvas-agent-starters button:focus-visible {
outline: 2px solid #202124;
outline-offset: 2px;
}
.canvas-agent-starters button:active {
transform: translateY(0);
}
.canvas-agent-starters button:disabled {
color: #a6a9ae;
background: #f8f8f7;
transform: none;
cursor: default;
}
@media (max-width: 480px) {
.canvas-agent-empty-state {
padding-inline: 12px;
}
.canvas-agent-empty-visual {
margin-bottom: 24px;
}
.canvas-agent-empty-state p {
margin-bottom: 22px;
}
.canvas-agent-starters {
max-width: 340px;
gap: 8px;
}
.canvas-agent-starters button {
min-height: 38px;
padding: 7px 16px;
font-size: 13px;
}
}
@@ -0,0 +1,49 @@
"use client";
import type { AgentStarterConfig } from "@/domain/design";
import { useI18n } from "@/i18n/i18n";
import "./index.css";
type CanvasAgentEmptyStateProps = {
config: AgentStarterConfig;
disabled?: boolean;
onSelectPrompt: (prompt: string) => void;
};
export function CanvasAgentEmptyState({ config, disabled = false, onSelectPrompt }: CanvasAgentEmptyStateProps) {
const { t } = useI18n();
const previewImages = config.previewImages.slice(0, 3);
return (
<section className="canvas-agent-empty-state" data-testid="canvas-agent-empty-state">
<div className="canvas-agent-empty-visual" aria-hidden="true">
{previewImages.map((src, index) => (
<span className={`canvas-agent-empty-image ${previewImagePosition(index, previewImages.length)}`} key={src}>
<img src={src} alt="" draggable={false} decoding="async" />
</span>
))}
</div>
<h2>{config.title}</h2>
<p>{config.description}</p>
<div className="canvas-agent-starters" aria-label={t("agentEmptyStarterLabel")}>
{config.starters.map((starter) => (
<button
type="button"
key={starter.id}
disabled={disabled}
data-testid="canvas-agent-starter"
onClick={() => onSelectPrompt(starter.prompt)}
>
{starter.label}
</button>
))}
</div>
</section>
);
}
function previewImagePosition(index: number, count: number) {
if (count === 1) return "center";
if (count === 2) return index === 0 ? "left" : "right";
return ["left", "center", "right"][index] ?? "center";
}
@@ -107,7 +107,7 @@ export function CanvasGeneratedFilesPanel({
onDownload(node);
}}
>
<Download size={19} />
<Download size={16} />
</button>
</div>
))}
@@ -59,6 +59,7 @@ type PromptPart =
export type PromptComposerHandle = {
insertReference: (reference: UploadedReferenceImage) => void;
upsertReference: (reference: UploadedReferenceImage, options?: InsertReferenceOptions) => void;
focus: () => void;
isFocused: () => boolean;
insertAnnotation: (annotation: CanvasAnnotation) => void;
serialize: (t: Translate) => string;
@@ -833,6 +834,12 @@ export const PromptComposer = forwardRef<
upsertReference(reference, options) {
upsertReferenceIntoEditor(reference, options);
},
focus() {
const editor = editorRef.current;
if (!editor) return;
editor.focus();
placeCaretAtEnd(editor);
},
isFocused() {
const editor = editorRef.current;
return Boolean(editor && document.activeElement && editor.contains(document.activeElement));