feat: 增加可视化模板页面编辑器
This commit is contained in:
1 parent
9d2038cc93
commit
c5af790554
24 files changed
+773
-129
No files matched your search
@@ -14,6 +14,7 @@ import type {
|
||||
export type { PublicOffering } from "@personal-brand/types";
|
||||
export type { BookingStatus } from "@personal-brand/types";
|
||||
export type { BrandTemplateKey } from "@personal-brand/types";
|
||||
export type { EditorPreviewFrameMessage, EditorPreviewHostMessage } from "@personal-brand/types";
|
||||
|
||||
export interface BrandProfile {
|
||||
id: string;
|
||||
@@ -92,6 +93,7 @@ export interface TemplateAdminField {
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
previewTarget?: string;
|
||||
}
|
||||
|
||||
export interface TemplateAdminSection {
|
||||
@@ -100,6 +102,7 @@ export interface TemplateAdminSection {
|
||||
description: string;
|
||||
page: string;
|
||||
target: "brand" | "offering" | "trust" | "inquiry";
|
||||
previewTargets?: Array<{ key: string; label: string }>;
|
||||
fields: TemplateAdminField[];
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<Text className="slogan">“{text(brand.description)}”</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="notice">
|
||||
<View className="notice" data-editor-target="food.home.location">
|
||||
<Text className="notice-title">{p.stallTitle || "服务地点"}</Text>
|
||||
<Text>{text(brand.address)}</Text>
|
||||
{p.stallTime && <Text className="notice-time">{p.stallTime}</Text>}
|
||||
@@ -37,7 +37,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</Button>
|
||||
</View>
|
||||
</View>
|
||||
<View className="scene-wrap">
|
||||
<View className="scene-wrap" data-editor-target="food.home.hero">
|
||||
<View className="section-head">
|
||||
<Text className="eyebrow">{text(brand.name)}</Text>
|
||||
</View>
|
||||
@@ -50,7 +50,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
<View className="section-head">
|
||||
<View className="section-head" data-editor-target="food.home.offerings-heading">
|
||||
<View>
|
||||
<Text className="eyebrow">{p.worksEyebrow || "餐品与服务"}</Text>
|
||||
<Text className="heading">{p.worksTitle || "可选餐品"}</Text>
|
||||
@@ -75,7 +75,9 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<Text className="heading manifesto-heading">{p.manifestoTitle}</Text>
|
||||
<View data-editor-target="food.home.promise-heading">
|
||||
<Text className="heading manifesto-heading">{p.manifestoTitle}</Text>
|
||||
</View>
|
||||
{workspace.trustItems
|
||||
.filter((item) => ["promise", "case"].includes(item.type))
|
||||
.map((item) => (
|
||||
|
||||
@@ -188,9 +188,16 @@
|
||||
"description": "说明今天在哪里、何时营业,以及餐品有什么特点。",
|
||||
"page": "home",
|
||||
"target": "brand",
|
||||
"previewTargets": [
|
||||
{ "key": "food.home.location", "label": "服务地点" },
|
||||
{ "key": "food.home.hero", "label": "出摊现场图片" },
|
||||
{ "key": "food.home.offerings-heading", "label": "餐品区域标题" },
|
||||
{ "key": "food.home.promise-heading", "label": "出餐承诺标题" }
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"key": "stallTitle",
|
||||
"previewTarget": "food.home.location",
|
||||
"binding": "brand.config.visualPresentation.home.stallTitle",
|
||||
"label": "出摊信息标题",
|
||||
"input": "text",
|
||||
@@ -198,6 +205,7 @@
|
||||
},
|
||||
{
|
||||
"key": "heroImage",
|
||||
"previewTarget": "food.home.hero",
|
||||
"binding": "brand.config.heroImage",
|
||||
"label": "出摊现场主图",
|
||||
"help": "展示真实摊位、餐品或取餐场景,建议使用横向图片。",
|
||||
@@ -206,6 +214,7 @@
|
||||
},
|
||||
{
|
||||
"key": "stallTime",
|
||||
"previewTarget": "food.home.location",
|
||||
"binding": "brand.config.visualPresentation.home.stallTime",
|
||||
"label": "营业时间说明",
|
||||
"input": "text",
|
||||
@@ -213,18 +222,21 @@
|
||||
},
|
||||
{
|
||||
"key": "worksEyebrow",
|
||||
"previewTarget": "food.home.offerings-heading",
|
||||
"binding": "brand.config.visualPresentation.home.worksEyebrow",
|
||||
"label": "餐品区域小标题",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "worksTitle",
|
||||
"previewTarget": "food.home.offerings-heading",
|
||||
"binding": "brand.config.visualPresentation.home.worksTitle",
|
||||
"label": "招牌餐品标题",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "manifestoTitle",
|
||||
"previewTarget": "food.home.promise-heading",
|
||||
"binding": "brand.config.visualPresentation.home.manifestoTitle",
|
||||
"label": "出餐承诺标题",
|
||||
"input": "text"
|
||||
|
||||
@@ -66,6 +66,8 @@ export type TemplateAdminField = {
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
/** Stable visual-region identifier declared by the owning Admin section. */
|
||||
previewTarget?: string;
|
||||
};
|
||||
|
||||
/** 模板自己的浅层品牌字段,值存于 BrandProfile.config.templateData。 */
|
||||
@@ -83,6 +85,8 @@ export type TemplateAdminSection = {
|
||||
/** Exact Mini Program page that displays this section's content. */
|
||||
page: TemplatePageKey;
|
||||
target: "brand" | "offering" | "trust" | "inquiry";
|
||||
/** Visual regions rendered by this section's page. */
|
||||
previewTargets?: Array<{ key: string; label: string }>;
|
||||
fields: TemplateAdminField[];
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
const templateDirectories = fs
|
||||
.readdirSync(path.join(root, "packages"))
|
||||
.filter(
|
||||
(directory) =>
|
||||
directory.startsWith("template-") &&
|
||||
fs.existsSync(path.join(root, "packages", directory, "template.json")),
|
||||
);
|
||||
|
||||
for (const directory of templateDirectories) {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(root, "packages", directory, "template.json"), "utf8"),
|
||||
);
|
||||
const rendererPath = path.join(root, "packages", directory, "taro/index.tsx");
|
||||
|
||||
test(`${manifest.packageKey} preview targets match manifest and renderer`, () => {
|
||||
const sections = manifest.admin.sections;
|
||||
const targets = sections.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({ ...target, page: section.page, section })),
|
||||
);
|
||||
const keys = targets.map((target) => target.key);
|
||||
assert.equal(new Set(keys).size, keys.length, "preview target keys must be unique");
|
||||
|
||||
for (const { section } of targets) {
|
||||
for (const field of section.fields) {
|
||||
if (field.previewTarget)
|
||||
assert.ok(
|
||||
section.previewTargets.some((target) => target.key === field.previewTarget),
|
||||
`${section.key}.${field.key} references an undeclared previewTarget`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const target of targets)
|
||||
assert.ok(
|
||||
target.section.fields.some((field) => field.previewTarget === target.key),
|
||||
`${target.key} must map to at least one editable field`,
|
||||
);
|
||||
|
||||
if (!targets.length) return;
|
||||
assert.ok(fs.existsSync(rendererPath), "templates with preview targets need a Taro renderer");
|
||||
const renderer = fs.readFileSync(rendererPath, "utf8");
|
||||
for (const target of targets)
|
||||
assert.ok(
|
||||
renderer.includes(`data-editor-target="${target.key}"`),
|
||||
`renderer is missing data-editor-target ${target.key}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -21,7 +21,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
return (
|
||||
<View className="editorial-home">
|
||||
<View className="page">
|
||||
<View className="founder-card">
|
||||
<View className="founder-card" data-editor-target="editorial.home.identity">
|
||||
{text(b.avatarUrl) && (
|
||||
<Image className="avatar" src={text(b.avatarUrl)} mode="aspectFill" />
|
||||
)}
|
||||
@@ -32,7 +32,11 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
</View>
|
||||
{p.founderBadge && <Text className="badge">{p.founderBadge}</Text>}
|
||||
</View>
|
||||
<View className="hero" onClick={() => navigate("offerings")}>
|
||||
<View
|
||||
className="hero"
|
||||
data-editor-target="editorial.home.hero"
|
||||
onClick={() => navigate("offerings")}
|
||||
>
|
||||
<Image className="hero-image" src={text(b.heroImage)} mode="aspectFill" />
|
||||
<View className="hero-shade" />
|
||||
<View className="hero-copy">
|
||||
@@ -46,7 +50,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
<Text className="hero-button">{text(hero.cta) || "查看作品"}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="intro">
|
||||
<View className="intro" data-editor-target="editorial.home.proof">
|
||||
<Text className="eyebrow dark">{p.proofEyebrow}</Text>
|
||||
<Text className="section-title">{p.proofTitle}</Text>
|
||||
<Text className="body">{credential?.content}</Text>
|
||||
@@ -60,7 +64,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
<View className="trust">
|
||||
<View className="trust" data-editor-target="editorial.home.manifesto">
|
||||
<Text className="eyebrow">{p.manifestoEyebrow}</Text>
|
||||
<Text className="section-title light">{p.manifestoTitle}</Text>
|
||||
{t.pillars?.map((item, index) => (
|
||||
@@ -71,7 +75,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||
))}
|
||||
</View>
|
||||
<View className="section">
|
||||
<View className="section-head">
|
||||
<View className="section-head" data-editor-target="editorial.home.works">
|
||||
<View>
|
||||
<Text className="eyebrow dark">{p.worksEyebrow}</Text>
|
||||
<Text className="section-title">{p.worksTitle}</Text>
|
||||
|
||||
@@ -157,9 +157,17 @@
|
||||
"description": "用简洁的语言解释你的项目方法、代表作品和合作流程。",
|
||||
"page": "home",
|
||||
"target": "brand",
|
||||
"previewTargets": [
|
||||
{ "key": "editorial.home.identity", "label": "主理人标签" },
|
||||
{ "key": "editorial.home.hero", "label": "首页主视觉" },
|
||||
{ "key": "editorial.home.proof", "label": "信任介绍" },
|
||||
{ "key": "editorial.home.manifesto", "label": "品牌主张" },
|
||||
{ "key": "editorial.home.works", "label": "代表案例标题" }
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"key": "founderBadge",
|
||||
"previewTarget": "editorial.home.identity",
|
||||
"binding": "brand.config.visualPresentation.home.founderBadge",
|
||||
"label": "主理人标签",
|
||||
"input": "text",
|
||||
@@ -167,6 +175,7 @@
|
||||
},
|
||||
{
|
||||
"key": "heroImage",
|
||||
"previewTarget": "editorial.home.hero",
|
||||
"binding": "brand.config.heroImage",
|
||||
"label": "首页项目主图",
|
||||
"help": "展示真实别墅、入户门或空间细节,体现项目能力。",
|
||||
@@ -175,36 +184,42 @@
|
||||
},
|
||||
{
|
||||
"key": "proofTitle",
|
||||
"previewTarget": "editorial.home.proof",
|
||||
"binding": "brand.config.visualPresentation.home.proofTitle",
|
||||
"label": "信任介绍标题",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "proofEyebrow",
|
||||
"previewTarget": "editorial.home.proof",
|
||||
"binding": "brand.config.visualPresentation.home.proofEyebrow",
|
||||
"label": "信任介绍小标题",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "manifestoEyebrow",
|
||||
"previewTarget": "editorial.home.manifesto",
|
||||
"binding": "brand.config.visualPresentation.home.manifestoEyebrow",
|
||||
"label": "品牌主张小标题",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "manifestoTitle",
|
||||
"previewTarget": "editorial.home.manifesto",
|
||||
"binding": "brand.config.visualPresentation.home.manifestoTitle",
|
||||
"label": "品牌主张",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "worksEyebrow",
|
||||
"previewTarget": "editorial.home.works",
|
||||
"binding": "brand.config.visualPresentation.home.worksEyebrow",
|
||||
"label": "代表案例小标题",
|
||||
"input": "text"
|
||||
},
|
||||
{
|
||||
"key": "worksTitle",
|
||||
"previewTarget": "editorial.home.works",
|
||||
"binding": "brand.config.visualPresentation.home.worksTitle",
|
||||
"label": "代表案例标题",
|
||||
"input": "text"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { RuntimeWorkspace } from "./runtime-workspace.js";
|
||||
|
||||
export type EditorPreviewHostMessage =
|
||||
| {
|
||||
protocol: "personal-brand-editor-preview";
|
||||
version: 1;
|
||||
type: "brandDraft";
|
||||
brand: Partial<RuntimeWorkspace["brand"]>;
|
||||
}
|
||||
| {
|
||||
protocol: "personal-brand-editor-preview";
|
||||
version: 1;
|
||||
type: "focusTarget";
|
||||
targetKey: string;
|
||||
};
|
||||
|
||||
export type EditorPreviewFrameMessage =
|
||||
| {
|
||||
protocol: "personal-brand-editor-preview";
|
||||
version: 1;
|
||||
type: "ready";
|
||||
}
|
||||
| {
|
||||
protocol: "personal-brand-editor-preview";
|
||||
version: 1;
|
||||
type: "targetSelected";
|
||||
targetKey: string;
|
||||
page: string;
|
||||
};
|
||||
@@ -41,4 +41,5 @@ export interface PublicOffering {
|
||||
}
|
||||
|
||||
export * from "./runtime-workspace.js";
|
||||
export * from "./editor-preview.js";
|
||||
export * from "./runtime-content-contract.js";
|
||||
Reference in new issue
Block a user