mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 18:58:11 +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 { NpmInfo } from '@ali/lowcode-types';
|
||||||
import { isReactComponent } from './is-react';
|
import { isReactComponent, acceptsRef, wrapReactClass } from './is-react';
|
||||||
import { isESModule } from './is-es-module';
|
import { isESModule } from './is-es-module';
|
||||||
|
|
||||||
interface LibraryMap {
|
interface LibraryMap {
|
||||||
@ -80,13 +80,14 @@ export function buildComponents(libraryMap: LibraryMap, componentsMap: { [compon
|
|||||||
};
|
};
|
||||||
Object.keys(componentsMap).forEach((componentName) => {
|
Object.keys(componentsMap).forEach((componentName) => {
|
||||||
let component = componentsMap[componentName];
|
let component = componentsMap[componentName];
|
||||||
if (isReactComponent(component)) {
|
if (!isReactComponent(component)) {
|
||||||
components[componentName] = component;
|
|
||||||
} else {
|
|
||||||
component = findComponent(libraryMap, componentName, 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;
|
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 hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
||||||
const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
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) {
|
export function wrapReactClass(view: FunctionComponent) {
|
||||||
const ViewComponentClass = class extends Component {
|
const ViewComponentClass = class extends Component {
|
||||||
render() {
|
render() {
|
||||||
return view(this.props);
|
return createElement(view, this.props);
|
||||||
}
|
}
|
||||||
} as any;
|
} as any;
|
||||||
ViewComponentClass.displayName = view.displayName;
|
ViewComponentClass.displayName = view.displayName;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user