11import { uniqueId } from '@alilc/lowcode-utils' ;
2- import { makeObservable , obx } from '@alilc/lowcode-editor-core' ;
2+ import { createModuleEventBus , IEventBus , makeObservable , obx } from '@alilc/lowcode-editor-core' ;
33import { Context } from './context/view-context' ;
44import { Workspace } from './workspace' ;
55import { Resource } from './resource' ;
6+ import { IPublicTypeDisposable } from '../../types/es/shell/type/disposable' ;
67
78export class EditorWindow {
89 id : string = uniqueId ( 'window' ) ;
910 icon : React . ReactElement | undefined ;
1011
12+ private emitter : IEventBus = createModuleEventBus ( 'Project' ) ;
13+
1114 @obx . ref editorView : Context ;
1215
1316 @obx editorViews : Map < string , Context > = new Map < string , Context > ( ) ;
@@ -59,6 +62,14 @@ export class EditorWindow {
5962 }
6063 } ;
6164
65+ onChangeViewType ( fn : ( viewName : string ) => void ) : IPublicTypeDisposable {
66+ this . emitter . on ( 'window.change.view.type' , fn ) ;
67+
68+ return ( ) => {
69+ this . emitter . off ( 'window.change.view.type' , fn ) ;
70+ } ;
71+ }
72+
6273 execViewTypesInit = async ( ) => {
6374 const editorViews = this . resource . editorViews ;
6475 for ( let i = 0 ; i < editorViews . length ; i ++ ) {
@@ -81,10 +92,13 @@ export class EditorWindow {
8192 this . editorViews . set ( name , editorView ) ;
8293 } ;
8394
84- changeViewType = ( name : string ) => {
95+ changeViewType = ( name : string , ignoreEmit : boolean = true ) => {
8596 this . editorView ?. setActivate ( false ) ;
8697 this . editorView = this . editorViews . get ( name ) ! ;
8798
99+ if ( ! ignoreEmit ) {
100+ this . emitter . emit ( 'window.change.view.type' , name ) ;
101+ }
88102 this . editorView . setActivate ( true ) ;
89103 } ;
90104
0 commit comments