@@ -3,6 +3,7 @@ import { NpmInfo, ComponentSchema } from '@alilc/lowcode-types';
33import { Component } from '@alilc/lowcode-designer' ;
44import { isESModule } from './is-es-module' ;
55import { isReactComponent , acceptsRef , wrapReactClass } from './is-react' ;
6+ import { isObject } from './is-object' ;
67
78interface LibraryMap {
89 [ key : string ] : string ;
@@ -76,6 +77,22 @@ function findComponent(libraryMap: LibraryMap, componentName: string, npm?: NpmI
7677 return getSubComponent ( library , paths ) ;
7778}
7879
80+ /**
81+ * 判断是否是一个混合组件,即 components 是一个对象,对象值是 React 组件
82+ * 示例:
83+ * {
84+ * Button: ReactNode,
85+ * Text: ReactNode,
86+ * }
87+ */
88+ function isMixinComponent ( components : any ) {
89+ if ( ! isObject ( components ) ) {
90+ return false ;
91+ }
92+
93+ return Object . keys ( components ) . some ( componentName => isReactComponent ( components [ componentName ] ) ) ;
94+ }
95+
7996export function buildComponents ( libraryMap : LibraryMap ,
8097 componentsMap : { [ componentName : string ] : NpmInfo | ComponentType < any > | ComponentSchema } ,
8198 createComponent : ( schema : ComponentSchema ) => Component | null ) {
@@ -89,6 +106,8 @@ export function buildComponents(libraryMap: LibraryMap,
89106 component = wrapReactClass ( component as FunctionComponent ) ;
90107 }
91108 components [ componentName ] = component ;
109+ } else if ( isMixinComponent ( component ) ) {
110+ components [ componentName ] = component ;
92111 } else {
93112 component = findComponent ( libraryMap , componentName , component ) ;
94113 if ( component ) {
0 commit comments