fix(workspace): fix workspace editorView is undefined
This commit is contained in:
parent
86d50e0946
commit
44beb2a25a
|
@ -3,7 +3,7 @@ import {
|
|||
IDesigner,
|
||||
isComponentMeta,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { IPublicTypeAssetsJson } from '@alilc/lowcode-utils';
|
||||
import { IPublicTypeAssetsJson, getLogger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
IPublicTypeComponentAction,
|
||||
IPublicTypeComponentMetadata,
|
||||
|
@ -21,6 +21,8 @@ import { editorSymbol, designerSymbol } from '../symbols';
|
|||
import { ComponentMeta as ShellComponentMeta } from '../model';
|
||||
import { ComponentType } from 'react';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell-material' });
|
||||
|
||||
const innerEditorSymbol = Symbol('editor');
|
||||
export class Material implements IPublicApiMaterial {
|
||||
private readonly [innerEditorSymbol]: IPublicModelEditor;
|
||||
|
@ -31,6 +33,10 @@ export class Material implements IPublicApiMaterial {
|
|||
}
|
||||
const workspace: InnerWorkspace = globalContext.get('workspace');
|
||||
if (workspace.isActive) {
|
||||
if (!workspace.window.editor) {
|
||||
logger.error('Material api 调用时机出现问题,请检查');
|
||||
return this[innerEditorSymbol];
|
||||
}
|
||||
return workspace.window.editor;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ export class Window implements IPublicModelWindow {
|
|||
}
|
||||
|
||||
get currentEditorView() {
|
||||
if (this[windowSymbol].editorView) {
|
||||
return new EditorView(this[windowSymbol].editorView).toProxy() as any;
|
||||
if (this[windowSymbol]._editorView) {
|
||||
return new EditorView(this[windowSymbol]._editorView).toProxy() as any;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan
|
|||
|
||||
editorViews: Map<string, IViewContext>;
|
||||
|
||||
editorView: IViewContext;
|
||||
_editorView: IViewContext;
|
||||
|
||||
changeViewName: (name: string, ignoreEmit?: boolean) => void;
|
||||
|
||||
|
@ -54,7 +54,7 @@ export class EditorWindow implements IEditorWindow {
|
|||
|
||||
url: string | undefined;
|
||||
|
||||
@obx.ref editorView: Context;
|
||||
@obx.ref _editorView: Context;
|
||||
|
||||
@obx editorViews: Map<string, Context> = new Map<string, Context>();
|
||||
|
||||
|
@ -62,6 +62,13 @@ export class EditorWindow implements IEditorWindow {
|
|||
|
||||
sleep: boolean | undefined;
|
||||
|
||||
get editorView() {
|
||||
if (!this._editorView) {
|
||||
return this.editorViews.values().next().value;
|
||||
}
|
||||
return this._editorView;
|
||||
}
|
||||
|
||||
constructor(readonly resource: IResource, readonly workspace: IWorkspace, private config: IWindowCOnfig) {
|
||||
makeObservable(this);
|
||||
this.title = config.title;
|
||||
|
@ -75,10 +82,10 @@ export class EditorWindow implements IEditorWindow {
|
|||
updateState(state: WINDOW_STATE): void {
|
||||
switch (state) {
|
||||
case WINDOW_STATE.active:
|
||||
this.editorView?.setActivate(true);
|
||||
this._editorView?.setActivate(true);
|
||||
break;
|
||||
case WINDOW_STATE.inactive:
|
||||
this.editorView?.setActivate(false);
|
||||
this._editorView?.setActivate(false);
|
||||
break;
|
||||
case WINDOW_STATE.destroyed:
|
||||
break;
|
||||
|
@ -146,7 +153,7 @@ export class EditorWindow implements IEditorWindow {
|
|||
for (let i = 0; i < editorViews.length; i++) {
|
||||
const name = editorViews[i].viewName;
|
||||
await this.initViewType(name);
|
||||
if (!this.editorView) {
|
||||
if (!this._editorView) {
|
||||
this.changeViewName(name);
|
||||
}
|
||||
}
|
||||
|
@ -190,14 +197,14 @@ export class EditorWindow implements IEditorWindow {
|
|||
};
|
||||
|
||||
changeViewName = (name: string, ignoreEmit: boolean = true) => {
|
||||
this.editorView?.setActivate(false);
|
||||
this.editorView = this.editorViews.get(name)!;
|
||||
this._editorView?.setActivate(false);
|
||||
this._editorView = this.editorViews.get(name)!;
|
||||
|
||||
if (!this.editorView) {
|
||||
if (!this._editorView) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.editorView.setActivate(true);
|
||||
this._editorView.setActivate(true);
|
||||
|
||||
if (!ignoreEmit) {
|
||||
this.emitter.emit('window.change.view.type', name);
|
||||
|
|
Loading…
Reference in New Issue