1- import { BuiltinSimulatorRenderer , Component , DocumentModel , Node } from '@alilc/lowcode-designer' ;
2- import { IPublicTypeComponentSchema , IPublicTypeNodeSchema , IPublicTypeNpmInfo , IPublicEnumTransformStage , IPublicTypeNodeInstance } from '@alilc/lowcode-types' ;
3- import { Asset , compatibleLegaoSchema , cursor , isElement , isESModule , isPlainObject , isReactComponent , setNativeSelection } from '@alilc/lowcode-utils' ;
1+ import { BuiltinSimulatorRenderer , Component , IBaseNode , IDocumentModel } from '@alilc/lowcode-designer' ;
2+ import { IPublicTypeComponentSchema , IPublicTypeNodeSchema , IPublicTypeNpmInfo , IPublicEnumTransformStage , IPublicTypeNodeInstance , IPublicTypeProjectSchema } from '@alilc/lowcode-types' ;
3+ import { Asset , compatibleLegaoSchema , cursor , isElement , isESModule , isLowcodeProjectSchema , isComponentSchema , isPlainObject , isReactComponent , setNativeSelection } from '@alilc/lowcode-utils' ;
44import LowCodeRenderer from '@alilc/lowcode-rax-renderer' ;
55import { computed , observable as obx , makeObservable , configure } from 'mobx' ;
66import DriverUniversal from 'driver-universal' ;
@@ -47,15 +47,23 @@ const builtinComponents = {
4747function buildComponents (
4848 libraryMap : LibraryMap ,
4949 componentsMap : { [ componentName : string ] : IPublicTypeNpmInfo | ComponentType < any > | IPublicTypeComponentSchema } ,
50- createComponent : ( schema : IPublicTypeComponentSchema ) => Component | null ,
50+ createComponent : ( schema : IPublicTypeProjectSchema < IPublicTypeComponentSchema > ) => Component | null ,
5151) {
5252 const components : any = {
5353 ...builtinComponents ,
5454 } ;
5555 Object . keys ( componentsMap ) . forEach ( ( componentName ) => {
5656 let component = componentsMap [ componentName ] ;
57- if ( component && ( component as IPublicTypeComponentSchema ) . componentName === 'Component' ) {
58- components [ componentName ] = createComponent ( component as IPublicTypeComponentSchema ) ;
57+ if ( component && ( isLowcodeProjectSchema ( component ) || isComponentSchema ( component ) ) ) {
58+ if ( isComponentSchema ( component ) ) {
59+ components [ componentName ] = createComponent ( {
60+ version : '' ,
61+ componentsMap : [ ] ,
62+ componentsTree : [ component ] ,
63+ } ) ;
64+ } else {
65+ components [ componentName ] = createComponent ( component ) ;
66+ }
5967 } else if ( isReactComponent ( component ) ) {
6068 components [ componentName ] = component ;
6169 } else {
@@ -110,7 +118,7 @@ export class DocumentInstance {
110118 return this . document . export ( IPublicEnumTransformStage . Render ) ;
111119 }
112120
113- constructor ( readonly container : SimulatorRendererContainer , readonly document : DocumentModel ) {
121+ constructor ( readonly container : SimulatorRendererContainer , readonly document : IDocumentModel ) {
114122 makeObservable ( this ) ;
115123 }
116124
@@ -221,7 +229,7 @@ export class DocumentInstance {
221229 return this . instancesMap . get ( id ) || null ;
222230 }
223231
224- getNode ( id : string ) : Node < IPublicTypeNodeSchema > | null {
232+ getNode ( id : string ) : IBaseNode < IPublicTypeNodeSchema > | null {
225233 return this . document . getNode ( id ) ;
226234 }
227235}
@@ -256,6 +264,8 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
256264 // sync designMode
257265 this . _designMode = host . designMode ;
258266
267+ this . _locale = host . locale ;
268+
259269 // sync requestHandlersMap
260270 this . _requestHandlersMap = host . requestHandlersMap ;
261271
@@ -343,11 +353,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
343353 // TODO: remove this.createComponent
344354 this . _components = buildComponents ( this . _libraryMap , this . _componentsMap , this . createComponent . bind ( this ) ) ;
345355 }
346- @obx . ref private _components : any = { } ;
347- @computed get components ( ) : object {
356+ @obx . ref private _components : Record < string , React . FC | React . ComponentClass > | null = { } ;
357+ @computed get components ( ) : Record < string , React . FC | React . ComponentClass > {
348358 // 根据 device 选择不同组件,进行响应式
349359 // 更好的做法是,根据 device 选择加载不同的组件资源,甚至是 simulatorUrl
350- return this . _components ;
360+ return this . _components || { } ;
351361 }
352362 // context from: utils、constants、history、location、match
353363 @obx . ref private _appContext = { } ;
@@ -362,6 +372,10 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
362372 @computed get device ( ) {
363373 return this . _device ;
364374 }
375+ @obx . ref private _locale : string | undefined = undefined ;
376+ @computed get locale ( ) {
377+ return this . _locale ;
378+ }
365379 @obx . ref private _requestHandlersMap = null ;
366380 @computed get requestHandlersMap ( ) : any {
367381 return this . _requestHandlersMap ;
@@ -378,12 +392,15 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
378392 return loader . load ( asset ) ;
379393 }
380394
395+ async loadAsyncLibrary ( asyncLibraryMap : Record < string , any > ) {
396+ }
397+
381398 getComponent ( componentName : string ) {
382399 const paths = componentName . split ( '.' ) ;
383400 const subs : string [ ] = [ ] ;
384401
385402 while ( true ) {
386- const component = this . _components [ componentName ] ;
403+ const component = this . _components ?. [ componentName ] ;
387404 if ( component ) {
388405 return getSubComponent ( component , subs ) ;
389406 }
@@ -416,7 +433,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
416433 // if (instance && SYMBOL_VNID in instance) {
417434 // const docId = (instance.props as any).schema.docId;
418435 return {
419- docId : instance . props . _leaf . document . id ,
436+ docId : instance . props . _leaf . document ? .id || '' ,
420437 nodeId : instance . props . _leaf . getId ( ) ,
421438 instance,
422439 node : instance . props . _leaf ,
@@ -497,17 +514,26 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
497514 this . currentDocumentInstance ?. refresh ( ) ;
498515 }
499516
500- createComponent ( schema : IPublicTypeNodeSchema ) : Component | null {
501- const _schema : any = {
502- ...compatibleLegaoSchema ( schema ) ,
517+ stopAutoRepaintNode ( ) {
518+ }
519+
520+ enableAutoRepaintNode ( ) {
521+ }
522+
523+ createComponent ( schema : IPublicTypeProjectSchema < IPublicTypeComponentSchema > ) : Component | null {
524+ const _schema : IPublicTypeProjectSchema < IPublicTypeComponentSchema > = {
525+ ...schema ,
526+ componentsTree : schema . componentsTree . map ( compatibleLegaoSchema ) ,
503527 } ;
504528
505- if ( schema . componentName === 'Component' && ( schema as IPublicTypeComponentSchema ) . css ) {
529+ const componentsTreeSchema = _schema . componentsTree [ 0 ] ;
530+
531+ if ( componentsTreeSchema . componentName === 'Component' && componentsTreeSchema . css ) {
506532 const doc = window . document ;
507533 const s = doc . createElement ( 'style' ) ;
508534 s . setAttribute ( 'type' , 'text/css' ) ;
509- s . setAttribute ( 'id' , `Component-${ schema . id || '' } ` ) ;
510- s . appendChild ( doc . createTextNode ( ( schema as IPublicTypeComponentSchema ) . css || '' ) ) ;
535+ s . setAttribute ( 'id' , `Component-${ componentsTreeSchema . id || '' } ` ) ;
536+ s . appendChild ( doc . createTextNode ( componentsTreeSchema . css || '' ) ) ;
511537 doc . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( s ) ;
512538 }
513539
@@ -520,9 +546,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
520546 // @ts -ignore
521547 return createElement ( LowCodeRenderer , {
522548 ...extraProps ,
523- schema : _schema ,
549+ schema : componentsTreeSchema ,
524550 components,
525551 designMode : '' ,
552+ locale : renderer . locale ,
553+ messages : _schema . i18n || { } ,
526554 device : renderer . device ,
527555 appHelper : renderer . context ,
528556 rendererName : 'LowCodeRenderer' ,
0 commit comments