ai-chatbot/lib/home/lovart-sidebar-config.ts

178 lines
4.3 KiB
TypeScript

export const LOVART_HOME_SIDEBAR_CONFIG_KEY = "lovart_home_sidebar_config";
export const DEFAULT_LOVART_HOME_SIDEBAR_ITEMS = [
{
key: "newProject",
label: "新建项目",
description: "首页左侧顶部的新建项目按钮",
},
{
key: "home",
label: "首页",
description: "回到首页主视图",
},
{
key: "projects",
label: "项目列表",
description: "打开项目列表视图",
},
{
key: "profile",
label: "个人主页",
description: "首页侧边栏个人主页入口",
},
{
key: "gallery",
label: "个人相册",
description: "跳转到个人相册",
},
{
key: "tutorial",
label: "视频教程",
description: "展示视频教程悬浮面板",
},
{
key: "imageEditor",
label: "图片编辑",
description: "打开图片编辑功能",
},
{
key: "aiCad",
label: "HiCAD",
description: "进入官方 HiCAD 工作区",
},
{
key: "model3d",
label: "3D建模",
defaultEnabled: false,
description: "跳转 3D 建模工作台",
},
{
key: "scene",
label: "场景",
description: "跳转 AI 场景建模工作台",
},
{
key: "agent",
label: "风格化",
description: "跳转风格化工作区",
},
{
key: "videoCanvas",
label: "视频画布",
description: "跳转视频画布页面",
},
{
key: "flowBoard",
label: "流程白板",
description: "跳转流程白板页面",
},
{
key: "productPlanning",
label: "商品策划",
description: "跳转商品策划页面",
},
{
key: "toolbox1",
label: "工具箱",
description: "展示工具箱一链接列表",
},
{
key: "toolbox2",
label: "工具箱2",
description: "展示工具箱二链接列表",
},
{
key: "settings",
label: "系统设置",
description: "管理员系统设置入口",
},
] as const;
export type LovartHomeSidebarItemKey =
(typeof DEFAULT_LOVART_HOME_SIDEBAR_ITEMS)[number]["key"];
export type LovartHomeSidebarItemConfig = {
label: string;
iconUrl: string;
enabled: boolean;
};
export type LovartHomeSidebarConfig = {
items: Record<LovartHomeSidebarItemKey, LovartHomeSidebarItemConfig>;
};
const DEFAULT_ITEMS = DEFAULT_LOVART_HOME_SIDEBAR_ITEMS.reduce(
(accumulator, item) => {
const defaultEnabled =
"defaultEnabled" in item ? item.defaultEnabled : true;
accumulator[item.key] = {
label: item.label,
iconUrl: "",
enabled: defaultEnabled,
};
return accumulator;
},
{} as Record<LovartHomeSidebarItemKey, LovartHomeSidebarItemConfig>
);
export const defaultLovartHomeSidebarConfig: LovartHomeSidebarConfig = {
items: DEFAULT_ITEMS,
};
export function getDefaultLovartHomeSidebarItem(
key: LovartHomeSidebarItemKey
): LovartHomeSidebarItemConfig {
return defaultLovartHomeSidebarConfig.items[key];
}
export function normalizeLovartHomeSidebarConfig(
value: unknown
): LovartHomeSidebarConfig {
const raw =
value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
const rawItems =
raw.items && typeof raw.items === "object" && !Array.isArray(raw.items)
? (raw.items as Record<string, unknown>)
: {};
const items = DEFAULT_LOVART_HOME_SIDEBAR_ITEMS.reduce(
(accumulator, item) => {
const itemRaw =
rawItems[item.key] &&
typeof rawItems[item.key] === "object" &&
!Array.isArray(rawItems[item.key])
? (rawItems[item.key] as Record<string, unknown>)
: {};
const label = String(itemRaw.label || "")
.trim()
.slice(0, 32);
const iconUrl = String(itemRaw.iconUrl || "")
.trim()
.slice(0, 2000);
const defaultEnabled =
"defaultEnabled" in item ? item.defaultEnabled : true;
const normalizedLabel =
item.key === "aiCad" && label === "AI-CAD"
? item.label
: label || item.label;
accumulator[item.key] = {
label: normalizedLabel,
iconUrl,
enabled:
typeof itemRaw.enabled === "boolean"
? itemRaw.enabled
: defaultEnabled,
};
return accumulator;
},
{} as Record<LovartHomeSidebarItemKey, LovartHomeSidebarItemConfig>
);
return { items };
}