mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 09:41:57 +00:00
feat: 支持 FunctionComponent 选中
This commit is contained in:
parent
2c7dbe37f1
commit
d2d44e656e
@ -1,6 +1,6 @@
|
||||
import { ComponentType, forwardRef, createElement } from 'react';
|
||||
import { ComponentType, forwardRef, createElement, FunctionComponent } from 'react';
|
||||
import { NpmInfo } from '@ali/lowcode-types';
|
||||
import { isReactComponent } from './is-react';
|
||||
import { isReactComponent, acceptsRef, wrapReactClass } from './is-react';
|
||||
import { isESModule } from './is-es-module';
|
||||
|
||||
interface LibraryMap {
|
||||
@ -80,13 +80,14 @@ export function buildComponents(libraryMap: LibraryMap, componentsMap: { [compon
|
||||
};
|
||||
Object.keys(componentsMap).forEach((componentName) => {
|
||||
let component = componentsMap[componentName];
|
||||
if (isReactComponent(component)) {
|
||||
components[componentName] = component;
|
||||
} else {
|
||||
if (!isReactComponent(component)) {
|
||||
component = findComponent(libraryMap, componentName, component);
|
||||
if (component) {
|
||||
components[componentName] = component;
|
||||
}
|
||||
if (component) {
|
||||
if (!acceptsRef(component)) {
|
||||
component = wrapReactClass(component as FunctionComponent);
|
||||
}
|
||||
components[componentName] = component;
|
||||
}
|
||||
});
|
||||
return components;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ComponentClass, Component, FunctionComponent, ComponentType } from 'react';
|
||||
import { ComponentClass, Component, FunctionComponent, ComponentType, createElement } from 'react';
|
||||
|
||||
const hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
||||
const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
||||
@ -22,7 +22,7 @@ export function isReactComponent(obj: any): obj is ComponentType<any> {
|
||||
export function wrapReactClass(view: FunctionComponent) {
|
||||
const ViewComponentClass = class extends Component {
|
||||
render() {
|
||||
return view(this.props);
|
||||
return createElement(view, this.props);
|
||||
}
|
||||
} as any;
|
||||
ViewComponentClass.displayName = view.displayName;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user