34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
export type PreviewSelection = { targetKey: string; recordId?: string };
|
|
|
|
// 与模板 slot 一致,优先选择承载结构化内容的记录。
|
|
export function previewTrustRecordId(
|
|
items: { id?: string; type: string; config: Record<string, unknown> }[],
|
|
type: string | undefined,
|
|
): string | undefined {
|
|
const matches = items.filter((item) => item.type === type);
|
|
return (matches.find((item) => Object.keys(item.config).length > 0) ?? matches[0])?.id;
|
|
}
|
|
|
|
export type PreviewTarget = {
|
|
key: string;
|
|
label: string;
|
|
source: "brand" | "offering" | "trust" | "inquiry";
|
|
page: string;
|
|
composite?: boolean;
|
|
trustType?: string;
|
|
children?: string[];
|
|
};
|
|
|
|
export function resolvePreviewSelection(
|
|
targetKey: string,
|
|
recordId: string | undefined,
|
|
targets: PreviewTarget[],
|
|
page: string,
|
|
): PreviewSelection | undefined {
|
|
const target = targets.find((item) => item.key === targetKey && item.page === page);
|
|
if (!target) return undefined;
|
|
if (recordId && target.source !== "offering" && target.source !== "trust") return undefined;
|
|
// 空区域仍可选中,编辑面板提供创建内容的入口。
|
|
return recordId ? { targetKey, recordId } : { targetKey };
|
|
}
|