Skip to content

CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.

feat(ppt): move the template picker below the button, and file templates by category

codingFeng101948b27b94df2
diff --git a/client/workspaces/ppt/canvas/hooks/use-template-library.ts b/client/workspaces/ppt/canvas/hooks/use-template-library.ts
index 3da7ae4..9829b1d 100644
--- a/client/workspaces/ppt/canvas/hooks/use-template-library.ts
+++ b/client/workspaces/ppt/canvas/hooks/use-template-library.ts
@@ -99,13 +99,17 @@ export function useTemplateLibrary({ initialSelectedTemplateId, uiLang, tr }: Te
kind: "preset" as const,
previewSrc: t.path,
presetPath: t.path,
+ categories: t.categories,
})),
+ // Uploads carry no category: the picker files them under "mine", which
+ // is where someone looks for a template they added themselves.
...uploadedTemplates.map((t) => ({
id: t.id,
name: t.name,
kind: "upload" as const,
previewSrc: t.dataUrl,
dataUrl: t.dataUrl,
+ categories: [] as string[],
})),
],
[hiddenPresetTemplateIds, uploadedTemplates, uiLang],
diff --git a/client/workspaces/ppt/canvas/lib/constants.ts b/client/workspaces/ppt/canvas/lib/constants.ts
index b8fe10a..5094e48 100644
--- a/client/workspaces/ppt/canvas/lib/constants.ts
+++ b/client/workspaces/ppt/canvas/lib/constants.ts
@@ -1,4 +1,4 @@
-import type { PresetTemplate } from "@/workspaces/ppt/canvas/types";
+import type { PresetTemplate, TemplateCategory } from "@/workspaces/ppt/canvas/types";
/** Marks a version synthesised from a slide that had no explicit version yet. */
export const SYNTHETIC_PRIMARY_VERSION_PREFIX = "synthetic-primary:";
@@ -12,13 +12,39 @@ export const PPT_TEMPLATE_HIDDEN_PRESETS_KEY = "ppt_template_hidden_presets_v1";
export const REVIEW_BOX_COLOR = "#22d3ee";
export const REVIEW_BOX_SELECTED_COLOR = "#f59e0b";
+/**
+ * Buckets for the template picker, in the order the filter shows them.
+ *
+ * There are more of these than there are templates on purpose: the library is
+ * meant to grow, and a new template should only need a file, a name and one or
+ * more of these ids. A bucket with nothing in it is not rendered, so an unused
+ * id costs nothing until it is used.
+ */
+export const TEMPLATE_CATEGORIES: TemplateCategory[] = [
+ { id: "business", zhName: "商务办公", enName: "Business" },
+ { id: "tech", zhName: "科技互联网", enName: "Tech" },
+ { id: "academic", zhName: "学术教育", enName: "Academic" },
+ { id: "report", zhName: "总结汇报", enName: "Report" },
+ { id: "marketing", zhName: "营销发布", enName: "Marketing" },
+ { id: "minimal", zhName: "极简", enName: "Minimal" },
+ { id: "creative", zhName: "创意插画", enName: "Creative" },
+ { id: "data", zhName: "数据图表", enName: "Data" },
+ { id: "finance", zhName: "金融财经", enName: "Finance" },
+ { id: "medical", zhName: "医疗健康", enName: "Medical" },
+ { id: "culture", zhName: "文化艺术", enName: "Culture" },
+ { id: "nature", zhName: "自然环保", enName: "Nature" },
+ { id: "festival", zhName: "节日庆典", enName: "Festival" },
+ { id: "resume", zhName: "简历求职", enName: "Resume" },
+ { id: "other", zhName: "其他", enName: "Other" },
+];
+
export const PRESET_TEMPLATES: PresetTemplate[] = [
- { id: "preset-tech-business", zhName: "科技商务", enName: "Tech Business", path: "/templates/template_b.png" },
- { id: "preset-academic", zhName: "学术汇报", enName: "Academic", path: "/templates/template_academic.jpg" },
- { id: "preset-minimal", zhName: "极简主义", enName: "Minimal", path: "/templates/template_s.png" },
- { id: "preset-vector", zhName: "矢量插画", enName: "Vector Illustration", path: "/templates/template_vector_illustration.png" },
- { id: "preset-yellow", zhName: "活力黄", enName: "Vibrant Yellow", path: "/templates/template_y.png" },
- { id: "preset-glass", zhName: "磨砂玻璃", enName: "Frosted Glass", path: "/templates/template_glass.png" },
+ { id: "preset-tech-business", zhName: "科技商务", enName: "Tech Business", path: "/templates/template_b.png", categories: ["tech", "business"] },
+ { id: "preset-academic", zhName: "学术汇报", enName: "Academic", path: "/templates/template_academic.jpg", categories: ["academic", "report"] },
+ { id: "preset-minimal", zhName: "极简主义", enName: "Minimal", path: "/templates/template_s.png", categories: ["minimal", "business"] },
+ { id: "preset-vector", zhName: "矢量插画", enName: "Vector Illustration", path: "/templates/template_vector_illustration.png", categories: ["creative", "marketing"] },
+ { id: "preset-yellow", zhName: "活力黄", enName: "Vibrant Yellow", path: "/templates/template_y.png", categories: ["marketing", "creative"] },
+ { id: "preset-glass", zhName: "磨砂玻璃", enName: "Frosted Glass", path: "/templates/template_glass.png", categories: ["tech", "minimal"] },
];
/** Fan-out limits: the provider rejects larger bursts of per-slide calls. */
diff --git a/client/workspaces/ppt/canvas/types.ts b/client/workspaces/ppt/canvas/types.ts
index f1716da..d5d7e16 100644
--- a/client/workspaces/ppt/canvas/types.ts
+++ b/client/workspaces/ppt/canvas/types.ts
@@ -62,9 +62,26 @@ export type ReferenceVisualAsset = {
textHint: string;
};
-export type PresetTemplate = { id: string; zhName: string; enName: string; path: string };
+/**
+ * A bucket in the template picker. The set is deliberately wider than the
+ * presets that exist today: adding a template is then a matter of dropping a
+ * file in and naming its categories, with no UI change.
+ */
+export type TemplateCategory = { id: string; zhName: string; enName: string };
+
+/**
+ * A template can sit in more than one bucket -- a frosted-glass deck is both
+ * "tech" and "minimal" -- so listing it twice is not a mistake.
+ */
+export type PresetTemplate = {
+ id: string;
+ zhName: string;
+ enName: string;
+ path: string;
+ categories: string[];
+};
export type UploadTemplate = { id: string; name: string; dataUrl: string };
export type TemplateItem =
- | { id: string; name: string; kind: "preset"; previewSrc: string; presetPath: string }
- | { id: string; name: string; kind: "upload"; previewSrc: string; dataUrl: string };
+ | { id: string; name: string; kind: "preset"; previewSrc: string; presetPath: string; categories: string[] }
+ | { id: string; name: string; kind: "upload"; previewSrc: string; dataUrl: string; categories: string[] };
diff --git a/client/workspaces/ppt/canvas/views/CreationStart.tsx b/client/workspaces/ppt/canvas/views/CreationStart.tsx
index 9ad311e..a862ad2 100644
--- a/client/workspaces/ppt/canvas/views/CreationStart.tsx
+++ b/client/workspaces/ppt/canvas/views/CreationStart.tsx
@@ -1,6 +1,6 @@
import { motion } from "motion/react";
import { SPRING } from "@/shared/motion";
-import { FileText, Lightbulb, Loader2, Presentation, Sparkles, Upload, X } from "lucide-react";
+import { FileText, Lightbulb, Loader2, Presentation, Sparkles, Upload } from "lucide-react";
import { Button } from "@/shared/ui/button";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/shared/ui/dialog";
import { Textarea } from "@/shared/ui/textarea";
@@ -8,6 +8,7 @@ import { isPdfFile } from "@/workspaces/ppt/canvas/lib/deck-source";
import type { CreationProgress } from "@/workspaces/ppt/canvas/lib/creation-machine";
import type { useCreationInputs } from "@/workspaces/ppt/canvas/hooks/use-creation-inputs";
import type { useTemplateLibrary } from "@/workspaces/ppt/canvas/hooks/use-template-library";
+import { TemplatePicker } from "@/workspaces/ppt/canvas/views/TemplatePicker";
interface CreationStartProps {
inputs: ReturnType<typeof useCreationInputs>;
@@ -80,78 +81,10 @@ export function CreationStart({
<div className="max-w-4xl mx-auto space-y-8 bg-card p-8 rounded-2xl shadow-soft border border-border/60">
<div className="space-y-8">
- {/* Template Selection */}
- {creationMode !== "image_transform" ? (
- <div className="space-y-4">
- <label className="text-sm font-semibold text-foreground flex items-center gap-2">
- <span className="w-6 h-6 rounded-full bg-primary/12 text-primary-strong text-xs flex items-center justify-center font-bold">1</span>
- {tr("选择或上传参考模板", "Choose or upload a reference template")}
- </label>
-
- <div className="grid gap-4 grid-cols-[repeat(auto-fill,minmax(180px,1fr))]">
- <label className="cursor-pointer border-2 border-dashed rounded-xl transition-all duration-200 overflow-hidden relative aspect-video flex flex-col items-center justify-center group border-border hover:border-primary hover:bg-primary/[0.08]">
- <div className="flex flex-col items-center text-muted-foreground/70 group-hover:text-primary-strong transition-colors">
- <div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center mb-2 group-hover:bg-primary/12 transition-colors">
- <Upload className="w-5 h-5" />
- </div>
- <span className="text-xs font-medium">{tr("添加模板", "Add template")}</span>
- </div>
- <input type="file" accept="image/*" multiple className="hidden" onChange={templateLibrary.handleUploadInputChange} />
- </label>
- <button
- type="button"
- onClick={() => templateLibrary.generator.setOpen(true)}
- title={tr("AI生成模板", "AI generate template")}
- className="cursor-pointer border-2 border-dashed rounded-xl transition-all duration-200 overflow-hidden relative aspect-video flex flex-col items-center justify-center group border-border hover:border-primary hover:bg-primary/[0.08]"
- >
- <div className="flex flex-col items-center text-muted-foreground/70 group-hover:text-primary-strong transition-colors">
- <div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center mb-2 group-hover:bg-primary/12 transition-colors">
- <Sparkles className="w-5 h-5" />
- </div>
- <span className="text-xs font-medium">{tr("AI生成模板", "AI generate")}</span>
- </div>
- </button>
- {templateLibrary.templates.map((t, i) => (
- <div
- key={t.id}
- onClick={() => void templateLibrary.selectTemplate(t)}
- style={{ animationDelay: `${Math.min(i, 8) * 40}ms` }}
- className={`animate-rise-in cursor-pointer border rounded-xl overflow-hidden relative aspect-video group transition-all duration-base ease-out-soft bg-muted ${
- templateLibrary.selectedTemplateId === t.id
- ? "border-primary ring-2 ring-primary shadow-md"
- : "border-border hover:ring-2 hover:ring-primary hover:shadow-md"
- }`}
- >
- <img src={t.previewSrc} className="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" alt={t.name} />
- {templateLibrary.selectedTemplateId === t.id && (
- <div className="absolute top-2 left-2 rounded-full bg-primary px-2 py-0.5 text-[10px] font-medium text-primary-foreground shadow-xs">
- {tr("已选择", "Selected")}
- </div>
- )}
- <button
- type="button"
- onClick={(e) => {
- e.stopPropagation();
- templateLibrary.deleteTemplate(t);
- }}
- className="absolute top-2 right-2 rounded-full bg-black/50 text-white p-1 opacity-0 group-hover:opacity-100 transition-opacity"
- title={tr("删除模板", "Delete template")}
- >
- <X className="w-3.5 h-3.5" />
- </button>
- <div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-3 pt-8 opacity-0 group-hover:opacity-100 transition-opacity duration-200">
- <div className="text-white text-xs font-medium text-center">{t.name}</div>
- </div>
- </div>
- ))}
- </div>
- </div>
- ) : null}
-
{/* Mode Selection & Input */}
<div className="space-y-4">
<label className="text-sm font-semibold text-foreground flex items-center gap-2">
- <span className="w-6 h-6 rounded-full bg-primary/12 text-primary-strong text-xs flex items-center justify-center font-bold">{creationMode === "image_transform" ? "1" : "2"}</span>
+ <span className="w-6 h-6 rounded-full bg-primary/12 text-primary-strong text-xs flex items-center justify-center font-bold">1</span>
{tr("输入内容", "Input")}
</label>
@@ -380,6 +313,22 @@ export function CreationStart({
{progress.message ? <Loader2 className="size-5 mr-2 animate-spin" /> : <Sparkles className="size-5 mr-2" />}
{progress.message || (creationMode === "beautify" ? tr("开始渲染", "Start rendering") : creationMode === "image_transform" ? tr("开始转化", "Start transform") : creationMode === "idea" ? tr("开始生成大纲", "Generate outline") : tr("载入大纲", "Load outline"))}
</Button>
+
+ {/* Below the button, at the user's request: the template is
+ a refinement, not the first decision. The header carries
+ the current selection so it stays visible from up there. */}
+ {creationMode !== "image_transform" ? (
+ <TemplatePicker
+ templateLibrary={templateLibrary}
+ tr={tr}
+ heading={
+ <label className="text-sm font-semibold text-foreground flex items-center gap-2">
+ <span className="w-6 h-6 rounded-full bg-primary/12 text-primary-strong text-xs flex items-center justify-center font-bold">2</span>
+ {tr("选择或上传参考模板", "Choose or upload a reference template")}
+ </label>
+ }
+ />
+ ) : null}
</div>
<Dialog open={inputs.reference.previewOpen} onOpenChange={inputs.reference.setPreviewOpen}>
diff --git a/client/workspaces/ppt/canvas/views/TemplatePicker.tsx b/client/workspaces/ppt/canvas/views/TemplatePicker.tsx
new file mode 100644
index 0000000..c98a5d5
--- /dev/null
+++ b/client/workspaces/ppt/canvas/views/TemplatePicker.tsx
@@ -0,0 +1,151 @@
+import { useMemo, useState } from "react";
+import { Sparkles, Upload, X } from "lucide-react";
+import { cn } from "@/shared/lib/utils";
+import { TEMPLATE_CATEGORIES } from "@/workspaces/ppt/canvas/lib/constants";
+import type { useTemplateLibrary } from "@/workspaces/ppt/canvas/hooks/use-template-library";
+
+const ALL = "__all__";
+const MINE = "__mine__";
+
+interface TemplatePickerProps {
+ templateLibrary: ReturnType<typeof useTemplateLibrary>;
+ tr: (zh: string, en: string) => string;
+ /** Rendered before the filter row; the step number and its label. */
+ heading: React.ReactNode;
+}
+
+/**
+ * The reference-template gallery, filtered by category.
+ *
+ * Only buckets that actually hold something are offered, so the row grows on
+ * its own as templates are added and never shows a filter that leads nowhere.
+ * The add and generate tiles stay put under every filter -- they are actions,
+ * not results.
+ */
+export function TemplatePicker({ templateLibrary, tr, heading }: TemplatePickerProps) {
+ const [active, setActive] = useState<string>(ALL);
+ const { templates, selectedTemplateId } = templateLibrary;
+
+ const filters = useMemo(() => {
+ const counts = new Map<string, number>();
+ let mine = 0;
+ for (const t of templates) {
+ if (t.kind === "upload") mine += 1;
+ for (const c of t.categories) counts.set(c, (counts.get(c) || 0) + 1);
+ }
+ const rows = [{ id: ALL, label: tr("全部", "All"), count: templates.length }];
+ for (const c of TEMPLATE_CATEGORIES) {
+ const count = counts.get(c.id) || 0;
+ if (count > 0) rows.push({ id: c.id, label: tr(c.zhName, c.enName), count });
+ }
+ if (mine > 0) rows.push({ id: MINE, label: tr("我的模板", "Mine"), count: mine });
+ return rows;
+ }, [templates, tr]);
+
+ // A bucket can empty out from under the selection -- delete the last upload
+ // while "Mine" is active -- so fall back rather than showing nothing.
+ const activeId = filters.some((f) => f.id === active) ? active : ALL;
+
+ const visible = useMemo(() => {
+ if (activeId === ALL) return templates;
+ if (activeId === MINE) return templates.filter((t) => t.kind === "upload");
+ return templates.filter((t) => t.categories.includes(activeId));
+ }, [templates, activeId]);
+
+ const selectedName = templates.find((t) => t.id === selectedTemplateId)?.name;
+
+ return (
+ <div className="space-y-4">
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ {heading}
+ {selectedName && (
+ <span className="text-xs text-muted-foreground">
+ {tr("已选:", "Selected: ")}
+ <span className="font-medium text-foreground">{selectedName}</span>
+ </span>
+ )}
+ </div>
+
+ <div className="flex flex-wrap gap-1.5">
+ {filters.map((f) => (
+ <button
+ key={f.id}
+ type="button"
+ onClick={() => setActive(f.id)}
+ aria-pressed={activeId === f.id}
+ className={cn(
+ "rounded-full border px-3 py-1 text-xs font-medium transition-colors duration-fast ease-out-soft",
+ activeId === f.id
+ ? "border-primary/40 bg-primary/12 text-primary-strong"
+ : "border-border/70 bg-card text-muted-foreground hover:bg-accent hover:text-foreground",
+ )}
+ >
+ {f.label}
+ <span className="ml-1 tabular-nums opacity-60">{f.count}</span>
+ </button>
+ ))}
+ </div>
+
+ <div className="grid gap-4 grid-cols-[repeat(auto-fill,minmax(180px,1fr))]">
+ <label className="cursor-pointer border-2 border-dashed rounded-xl transition-all duration-200 overflow-hidden relative aspect-video flex flex-col items-center justify-center group border-border hover:border-primary hover:bg-primary/[0.08]">
+ <div className="flex flex-col items-center text-muted-foreground/70 group-hover:text-primary-strong transition-colors">
+ <div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center mb-2 group-hover:bg-primary/12 transition-colors">
+ <Upload className="w-5 h-5" />
+ </div>
+ <span className="text-xs font-medium">{tr("添加模板", "Add template")}</span>
+ </div>
+ <input type="file" accept="image/*" multiple className="hidden" onChange={templateLibrary.handleUploadInputChange} />
+ </label>
+
+ <button
+ type="button"
+ onClick={() => templateLibrary.generator.setOpen(true)}
+ title={tr("AI生成模板", "AI generate template")}
+ className="cursor-pointer border-2 border-dashed rounded-xl transition-all duration-200 overflow-hidden relative aspect-video flex flex-col items-center justify-center group border-border hover:border-primary hover:bg-primary/[0.08]"
+ >
+ <div className="flex flex-col items-center text-muted-foreground/70 group-hover:text-primary-strong transition-colors">
+ <div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center mb-2 group-hover:bg-primary/12 transition-colors">
+ <Sparkles className="w-5 h-5" />
+ </div>
+ <span className="text-xs font-medium">{tr("AI生成模板", "AI generate")}</span>
+ </div>
+ </button>
+
+ {visible.map((t, i) => (
+ <div
+ key={t.id}
+ onClick={() => void templateLibrary.selectTemplate(t)}
+ style={{ animationDelay: `${Math.min(i, 8) * 40}ms` }}
+ className={cn(
+ "animate-rise-in cursor-pointer border rounded-xl overflow-hidden relative aspect-video group transition-all duration-base ease-out-soft bg-muted",
+ selectedTemplateId === t.id
+ ? "border-primary ring-2 ring-primary shadow-md"
+ : "border-border hover:ring-2 hover:ring-primary hover:shadow-md",
+ )}
+ >
+ <img src={t.previewSrc} className="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" alt={t.name} />
+ {selectedTemplateId === t.id && (
+ <div className="absolute top-2 left-2 rounded-full bg-primary px-2 py-0.5 text-[10px] font-medium text-primary-foreground shadow-xs">
+ {tr("已选择", "Selected")}
+ </div>
+ )}
+ <button
+ type="button"
+ onClick={(e) => {
+ e.stopPropagation();
+ templateLibrary.deleteTemplate(t);
+ }}
+ className="absolute top-2 right-2 rounded-full bg-black/50 text-white p-1 opacity-0 group-hover:opacity-100 transition-opacity"
+ title={tr("删除模板", "Delete template")}
+ >
+ <X className="w-3.5 h-3.5" />
+ </button>
+ <div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-3 pt-8 opacity-0 group-hover:opacity-100 transition-opacity duration-200">
+ <div className="text-white text-xs font-medium text-center">{t.name}</div>
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+}