@@ -100,18 +100,44 @@ const ICON_MAP: Record<string, LucideIcon> = {
100100 Shapes,
101101} ;
102102
103- const CATEGORY_DEFS = [
103+ export const COMPONENT_CATEGORY_DEFS = [
104104 { key : 'basic' , Icon : Box } ,
105105 { key : 'controls' , Icon : MousePointerClick } ,
106106 { key : 'charts' , Icon : BarChart3 } ,
107107 { key : 'media' , Icon : Film } ,
108+ { key : 'business' , Icon : Bell } ,
108109 { key : 'decoration' , Icon : Shapes } ,
109110 { key : 'industrial' , Icon : Cpu } ,
110111] as const ;
111112
112113type CategoryMap = Record < string , RegistryListEntry [ ] > ;
113114const HIDDEN_COMPONENT_IDS = new Set ( [ 'geo/map-china' ] ) ;
114115
116+ export type ComponentCategoryKey = ( typeof COMPONENT_CATEGORY_DEFS ) [ number ] [ 'key' ] ;
117+
118+ export function resolveComponentCategory (
119+ entry : Pick < RegistryListEntry , 'category' | 'componentId' > ,
120+ ) : ComponentCategoryKey {
121+ const rawCategory =
122+ entry . category ?. toLowerCase ( ) || ( entry . componentId . split ( '/' ) [ 0 ] || 'basic' ) . toLowerCase ( ) ;
123+ const prefixMap : Record < string , ComponentCategoryKey > = {
124+ basic : 'basic' ,
125+ controls : 'controls' ,
126+ display : 'basic' ,
127+ interaction : 'controls' ,
128+ chart : 'charts' ,
129+ charts : 'charts' ,
130+ media : 'media' ,
131+ resources : 'media' ,
132+ geo : 'media' ,
133+ custom : 'business' ,
134+ decoration : 'decoration' ,
135+ industrial : 'industrial' ,
136+ } ;
137+
138+ return prefixMap [ rawCategory ] ?? 'basic' ;
139+ }
140+
115141function resolveEntryDisplayName ( entry : RegistryListEntry , language : string ) : string {
116142 const normalized = ( language || '' ) . toLowerCase ( ) ;
117143 const baseLanguage = normalized . split ( '-' ) [ 0 ] ?? normalized ;
@@ -162,28 +188,13 @@ export default function ComponentsList({
162188
163189 const entriesByCategory = useMemo ( ( ) => {
164190 const map : CategoryMap = { } ;
165- const prefixMap : Record < string , string > = {
166- basic : 'basic' ,
167- controls : 'controls' ,
168- display : 'basic' ,
169- chart : 'charts' ,
170- charts : 'charts' ,
171- media : 'media' ,
172- decoration : 'decoration' ,
173- industrial : 'industrial' ,
174- } ;
175-
176- CATEGORY_DEFS . forEach ( ( def ) => {
191+ COMPONENT_CATEGORY_DEFS . forEach ( ( def ) => {
177192 map [ def . key ] = [ ] ;
178193 } ) ;
179194
180195 entries . forEach ( ( entry ) => {
181196 // 优先从注册表读取直接定义好的 category,如果不存在再 fallback 到路径前缀解析
182- const rawCategory =
183- ( ( entry as any ) . category as string | undefined ) ?. toLowerCase ( ) ||
184- ( entry . componentId . split ( '/' ) [ 0 ] || 'basic' ) . toLowerCase ( ) ;
185- const category = prefixMap [ rawCategory ] || rawCategory || 'basic' ;
186- map [ category ] = map [ category ] ?? [ ] ;
197+ const category = resolveComponentCategory ( entry ) ;
187198 map [ category ] . push ( entry ) ;
188199 } ) ;
189200
@@ -253,7 +264,7 @@ export default function ComponentsList({
253264 defaultValue = { searchQuery ? Object . keys ( filteredCategoriesMap ) : [ 'basic' ] }
254265 className = "space-y-2"
255266 >
256- { CATEGORY_DEFS . map ( ( categoryDef ) => {
267+ { COMPONENT_CATEGORY_DEFS . map ( ( categoryDef ) => {
257268 const items = filteredCategoriesMap [ categoryDef . key ] ?? [ ] ;
258269 if ( items . length === 0 && searchQuery ) {
259270 return null ;
0 commit comments