import { Fragment } from "react"; import type { SidebarBlockRef, SidebarWidgetPublic } from "@/lib/sidebarMeta"; import { renderSidebarBlock, type SidebarBlockProps } from "./registry"; // 页面从本文件导入该类型(registry 中定义) export type { SidebarBlockProps }; import CustomWidgetBlock from "./CustomWidgetBlock"; // 按管理端配置渲染一列侧栏块: // - 内置块经注册表解析,未知 key / 数据缺失静默跳过; // - 自定义工具引用已删除或停用(公开载荷不含)时静默跳过; // - className 缺省时输出 Fragment,布局容器(gap/space-y、sticky、限高)由页面自行决定。 export default function SidebarRenderer({ blocks, widgets, props, className, }: { blocks: SidebarBlockRef[]; widgets: SidebarWidgetPublic[]; props: SidebarBlockProps; className?: string; }) { const items = blocks .map((ref, i) => { if (ref.widget) { const widget = widgets.find((x) => x.id === ref.widget); if (!widget) return null; return ; } if (!ref.key) return null; const node = renderSidebarBlock(ref.key, props); if (node === null) return null; return {node}; }) .filter((x) => x !== null); if (items.length === 0) return null; return className ?
{items}
: <>{items}; }