GeezerVison is showing github.com — fix: fix low-code component rendering problems: 1. thisRequiredInJSE … · zfhstudy/lowcode-engine@5dd4625
File treeExpand file treeCollapse file tree Open diff view settings rax-simulator-renderer/src react-simulator-renderer/src renderer-core/src/renderer
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/rax-simulator-renderer/src/renderer.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -523,10 +523,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { | 523 | 523 | ...extraProps, | 524 | 524 | schema: _schema, | 525 | 525 | components, | 526 | | - designMode: renderer.designMode, | | 526 | + designMode: '', | 527 | 527 | device: renderer.device, | 528 | 528 | appHelper: renderer.context, | 529 | 529 | rendererName: 'LowCodeRenderer', | | 530 | + thisRequiredInJSE: host.thisRequiredInJSE, | 530 | 531 | customCreateElement: (Comp: any, props: any, children: any) => { | 531 | 532 | const componentMeta = host.currentDocument?.getComponentMeta(Comp.displayName); | 532 | 533 | if (componentMeta?.isModal) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-simulator-renderer/src/renderer.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -450,10 +450,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { | 450 | 450 | // 使用 _schema 为了使低代码组件在页面设计中使用变量,同 react 组件使用效果一致 | 451 | 451 | schema: _schema, | 452 | 452 | components: renderer.components, | 453 | | - designMode: renderer.designMode, | | 453 | + designMode: '', | 454 | 454 | device: renderer.device, | 455 | 455 | appHelper: renderer.context, | 456 | 456 | rendererName: 'LowCodeRenderer', | | 457 | + thisRequiredInJSE: host.thisRequiredInJSE, | 457 | 458 | customCreateElement: (Comp: any, props: any, children: any) => { | 458 | 459 | const componentMeta = host.currentDocument?.getComponentMeta(Comp.displayName); | 459 | 460 | if (componentMeta?.isModal) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/base.tsx +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 116 | 116 | if (func) { | 117 | 117 | if (isJSExpression(func) || isJSFunction(func)) { | 118 | 118 | const fn = props.thisRequiredInJSE ? parseThisRequiredExpression(func, this) : parseExpression(func, this); | 119 | | - return fn(props, state); | | 119 | + return fn?.(props, state); | 120 | 120 | } | 121 | 121 |
| 122 | 122 | if (typeof func === 'function') { | @@ -210,6 +210,14 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 210 | 210 | } | 211 | 211 | }; | 212 | 212 |
| | 213 | + _getComponentView = (componentName: string) => { | | 214 | + const { __components } = this.props; | | 215 | + if (!__components) { | | 216 | + return; | | 217 | + } | | 218 | + return __components[componentName]; | | 219 | + }; | | 220 | + | 213 | 221 | __bindCustomMethods = (props = this.props) => { | 214 | 222 | const { __schema } = props; | 215 | 223 | const customMethodsList = Object.keys(__schema.methods || {}) || []; | |
Collapse file Copy file name to clipboardExpand all lines: packages/utils/src/build-components.ts +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { NpmInfo, ComponentSchema } from '@alilc/lowcode-types'; | 3 | 3 | import { Component } from '@alilc/lowcode-designer'; | 4 | 4 | import { isESModule } from './is-es-module'; | 5 | 5 | import { isReactComponent, acceptsRef, wrapReactClass } from './is-react'; | | 6 | +import { isObject } from './is-object'; | 6 | 7 |
| 7 | 8 | interface LibraryMap { | 8 | 9 | [key: string]: string; | @@ -76,6 +77,22 @@ function findComponent(libraryMap: LibraryMap, componentName: string, npm?: NpmI | 76 | 77 | return getSubComponent(library, paths); | 77 | 78 | } | 78 | 79 |
| | 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 | + | 79 | 96 | export function buildComponents(libraryMap: LibraryMap, | 80 | 97 | componentsMap: { [componentName: string]: NpmInfo | ComponentType<any> | ComponentSchema }, | 81 | 98 | createComponent: (schema: ComponentSchema) => Component | null) { | @@ -89,6 +106,8 @@ export function buildComponents(libraryMap: LibraryMap, | 89 | 106 | component = wrapReactClass(component as FunctionComponent); | 90 | 107 | } | 91 | 108 | components[componentName] = component; | | 109 | + } else if (isMixinComponent(component)) { | | 110 | + components[componentName] = component; | 92 | 111 | } else { | 93 | 112 | component = findComponent(libraryMap, componentName, component); | 94 | 113 | if (component) { | |
|