feat: 增加可视化模板页面编辑器
This commit is contained in:
1 parent
9d2038cc93
commit
c5af790554
24 files changed
+773
-129
No files matched your search
@@ -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}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user