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