From 22d2fddc3e999dc8516f2d5b0e2b57527efbe741 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 11 May 2023 10:11:33 +0800 Subject: [PATCH] feat: workspace add onChangeActiveWindow event api --- packages/shell/src/api/workspace.ts | 4 ++++ packages/shell/src/model/editor-view.ts | 2 +- packages/workspace/src/window.ts | 7 +++++-- packages/workspace/src/workspace.ts | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/shell/src/api/workspace.ts b/packages/shell/src/api/workspace.ts index 9676b8522..bfc7b27e1 100644 --- a/packages/shell/src/api/workspace.ts +++ b/packages/shell/src/api/workspace.ts @@ -73,4 +73,8 @@ export class Workspace implements IPublicApiWorkspace { onChangeActiveWindow(fn: () => void): IPublicTypeDisposable { return this[workspaceSymbol].onChangeActiveWindow(fn); } + + onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable { + return this[workspaceSymbol].onChangeActiveEditorView(fn); + } } diff --git a/packages/shell/src/model/editor-view.ts b/packages/shell/src/model/editor-view.ts index 31027a5de..d70a109b1 100644 --- a/packages/shell/src/model/editor-view.ts +++ b/packages/shell/src/model/editor-view.ts @@ -10,7 +10,7 @@ export class EditorView { constructor(editorView: IViewContext) { this[editorViewSymbol] = editorView; this[pluginContextSymbol] = this[editorViewSymbol].innerPlugins._getLowCodePluginContext({ - pluginName: '', + pluginName: editorView.editorWindow + editorView.viewName, }); } diff --git a/packages/workspace/src/window.ts b/packages/workspace/src/window.ts index 92b707851..41b9c53ea 100644 --- a/packages/workspace/src/window.ts +++ b/packages/workspace/src/window.ts @@ -3,8 +3,7 @@ import { createModuleEventBus, IEventBus, makeObservable, obx } from '@alilc/low import { Context, IViewContext } from './context/view-context'; import { IWorkspace } from './workspace'; import { IResource } from './resource'; -import { IPublicTypeDisposable } from '../../types/es/shell/type/disposable'; -import { IPublicModelWindow } from '@alilc/lowcode-types'; +import { IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types'; interface IWindowCOnfig { title: string | undefined; @@ -158,6 +157,10 @@ export class EditorWindow implements IEditorWindow { if (!ignoreEmit) { this.emitter.emit('window.change.view.type', name); + + if (this.id === this.workspace.window.id) { + this.workspace.emitChangeActiveEditorView(); + } } this.editorView.setActivate(true); }; diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts index 26e1d6551..33daf064a 100644 --- a/packages/workspace/src/workspace.ts +++ b/packages/workspace/src/workspace.ts @@ -13,6 +13,8 @@ enum EVENT { CHANGE_ACTIVE_WINDOW = 'change_active_window', WINDOW_RENDER_READY = 'window_render_ready', + + CHANGE_ACTIVE_EDITOR_VIEW = 'change_active_editor_view', } const CHANGE_EVENT = 'resource.list.change'; @@ -42,6 +44,10 @@ export interface IWorkspace extends Omit void): IPublicTypeDisposable; + + emitChangeActiveEditorView(): void; } export class Workspace implements IWorkspace { @@ -258,12 +264,24 @@ export class Workspace implements IWorkspace { }; } + onChangeActiveEditorView(fn: () => void) { + this.emitter.on(EVENT.CHANGE_ACTIVE_EDITOR_VIEW, fn); + return () => { + this.emitter.removeListener(EVENT.CHANGE_ACTIVE_EDITOR_VIEW, fn); + }; + } + + emitChangeActiveEditorView() { + this.emitter.emit(EVENT.CHANGE_ACTIVE_EDITOR_VIEW); + } + emitChangeWindow() { this.emitter.emit(EVENT.CHANGE_WINDOW); } emitChangeActiveWindow() { this.emitter.emit(EVENT.CHANGE_ACTIVE_WINDOW); + this.emitChangeActiveEditorView(); } onChangeActiveWindow(fn: () => void) {