feat: added features in workspace mode

This commit is contained in:
liujuping 2023-04-13 11:33:39 +08:00 committed by 林熠
parent 3d470cad69
commit 33fd6bf642
19 changed files with 155 additions and 50 deletions

View File

@ -20,7 +20,9 @@ export function createSimulator(
): Promise<BuiltinSimulatorRenderer> { ): Promise<BuiltinSimulatorRenderer> {
const win: any = iframe.contentWindow; const win: any = iframe.contentWindow;
const doc = iframe.contentDocument!; const doc = iframe.contentDocument!;
const innerPlugins = host.designer.editor.get('innerPlugins');
win.AliLowCodeEngine = innerPlugins._getLowCodePluginContext({});
win.LCSimulatorHost = host; win.LCSimulatorHost = host;
win._ = window._; win._ = window._;

View File

@ -1,5 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { observer, globalContext } from '@alilc/lowcode-editor-core'; import { observer } from '@alilc/lowcode-editor-core';
import { BuiltinSimulatorHost, BuiltinSimulatorProps } from './host'; import { BuiltinSimulatorHost, BuiltinSimulatorProps } from './host';
import { BemTools } from './bem-tools'; import { BemTools } from './bem-tools';
import { Project } from '../project'; import { Project } from '../project';
@ -76,8 +76,7 @@ class Content extends Component<{ host: BuiltinSimulatorHost }> {
private dispose?: () => void; private dispose?: () => void;
componentDidMount() { componentDidMount() {
const workspace = globalContext.get('workspace'); const editor = this.props.host.designer.editor;
const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor');
const onEnableEvents = (type: boolean) => { const onEnableEvents = (type: boolean) => {
this.setState({ this.setState({
disabledEvents: type, disabledEvents: type,

View File

@ -16,6 +16,7 @@ import {
IPublicApiWorkspace, IPublicApiWorkspace,
IPublicTypePluginMeta, IPublicTypePluginMeta,
IPublicTypePluginRegisterOptions, IPublicTypePluginRegisterOptions,
IPublicModelWindow,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import PluginContext from './plugin-context'; import PluginContext from './plugin-context';
@ -56,6 +57,7 @@ export interface ILowCodePluginContextPrivate {
set pluginEvent(event: IPublicApiEvent); set pluginEvent(event: IPublicApiEvent);
set canvas(canvas: IPublicApiCanvas); set canvas(canvas: IPublicApiCanvas);
set workspace(workspace: IPublicApiWorkspace); set workspace(workspace: IPublicApiWorkspace);
set editorWindow(window: IPublicModelWindow);
} }
export interface ILowCodePluginContextApiAssembler { export interface ILowCodePluginContextApiAssembler {
assembleApis( assembleApis(

View File

@ -1,3 +1,4 @@
import { IPublicTypePluginMeta } from './../../../../lib/packages/types/src/shell/type/plugin-meta.d';
import '../fixtures/window'; import '../fixtures/window';
import { import {
Editor, Editor,
@ -22,6 +23,7 @@ import { BuiltinSimulatorHost } from '../../src/builtin-simulator/host';
import { fireEvent } from '@testing-library/react'; import { fireEvent } from '@testing-library/react';
import { shellModelFactory } from '../../../engine/src/modules/shell-model-factory'; import { shellModelFactory } from '../../../engine/src/modules/shell-model-factory';
import { Setters, Workspace } from '@alilc/lowcode-shell'; import { Setters, Workspace } from '@alilc/lowcode-shell';
import { ILowCodePluginContextApiAssembler, ILowCodePluginContextPrivate, LowCodePluginManager } from '@alilc/lowcode-designer';
describe('Host 测试', () => { describe('Host 测试', () => {
let editor: Editor; let editor: Editor;
@ -32,10 +34,20 @@ describe('Host 测试', () => {
beforeAll(() => { beforeAll(() => {
editor = new Editor(); editor = new Editor();
const innerWorkspace = new InnerWorkspace(); const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string, meta: IPublicTypePluginMeta) => {
context.project = project;
const eventPrefix = meta?.eventPrefix || 'common';
context.workspace = workspace;
},
};
const innerPlugins = new LowCodePluginManager(pluginContextApiAssembler);
const innerWorkspace = new InnerWorkspace(() => {}, {});
const workspace = new Workspace(innerWorkspace); const workspace = new Workspace(innerWorkspace);
editor.set('innerHotkey', new InnerHotkey()) editor.set('innerHotkey', new InnerHotkey())
editor.set('setters', new Setters(new InnerSetters())); editor.set('setters', new Setters(new InnerSetters()));
editor.set('innerPlugins' as any, innerPlugins);
!globalContext.has(Editor) && globalContext.register(editor, Editor); !globalContext.has(Editor) && globalContext.register(editor, Editor);
!globalContext.has('workspace') && globalContext.register(innerWorkspace, 'workspace'); !globalContext.has('workspace') && globalContext.register(innerWorkspace, 'workspace');
}); });

View File

@ -1,5 +1,5 @@
import { Component, MouseEvent, Fragment } from 'react'; import { Component, MouseEvent, Fragment } from 'react';
import { shallowIntl, observer, obx, engineConfig, runInAction, globalContext } from '@alilc/lowcode-editor-core'; import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils'; import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton'; import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
import { IPublicTypeCustomView } from '@alilc/lowcode-types'; import { IPublicTypeCustomView } from '@alilc/lowcode-types';
@ -40,7 +40,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
stageName: string | undefined; stageName: string | undefined;
setters: Setters; setters?: Setters;
constructor(props: SettingFieldViewProps) { constructor(props: SettingFieldViewProps) {
super(props); super(props);
@ -49,10 +49,10 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
const { extraProps } = field; const { extraProps } = field;
const { display } = extraProps; const { display } = extraProps;
const workspace = globalContext.get('workspace'); const editor = field.designer?.editor;
const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); const skeleton = editor?.get('skeleton') as Skeleton;
const { stages } = editor.get('skeleton') as Skeleton; const { stages } = skeleton || {};
this.setters = editor.get('setters'); this.setters = editor?.get('setters');
let stageName; let stageName;
if (display === 'entry') { if (display === 'entry') {
runInAction(() => { runInAction(() => {
@ -291,9 +291,8 @@ class SettingGroupView extends Component<SettingGroupViewProps> {
const { field } = this.props; const { field } = this.props;
const { extraProps } = field; const { extraProps } = field;
const { display } = extraProps; const { display } = extraProps;
const workspace = globalContext.get('workspace'); const editor = this.props.field.designer?.editor;
const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); const { stages } = editor?.get('skeleton') as Skeleton;
const { stages } = editor.get('skeleton') as Skeleton;
// const items = field.items; // const items = field.items;
let stageName; let stageName;
@ -343,15 +342,15 @@ class SettingGroupView extends Component<SettingGroupViewProps> {
} }
} }
export function createSettingFieldView(item: ISettingField | IPublicTypeCustomView, field: ISettingEntry, index?: number) { export function createSettingFieldView(field: ISettingField | IPublicTypeCustomView, fieldEntry: ISettingEntry, index?: number) {
if (isSettingField(item)) { if (isSettingField(field)) {
if (item.isGroup) { if (field.isGroup) {
return <SettingGroupView field={item} key={item.id} />; return <SettingGroupView field={field} key={field.id} />;
} else { } else {
return <SettingFieldView field={item} key={item.id} />; return <SettingFieldView field={field} key={field.id} />;
} }
} else { } else {
return createContent(item, { key: index, field }); return createContent(field, { key: index, field: fieldEntry });
} }
} }

View File

@ -14,6 +14,7 @@ import {
IPublicTypeEngineOptions, IPublicTypeEngineOptions,
IPublicModelDocumentModel, IPublicModelDocumentModel,
IPublicTypePluginMeta, IPublicTypePluginMeta,
IPublicTypeDisposable,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { import {
Designer, Designer,
@ -60,14 +61,26 @@ export * from './modules/skeleton-types';
export * from './modules/designer-types'; export * from './modules/designer-types';
export * from './modules/lowcode-types'; export * from './modules/lowcode-types';
async function registryInnerPlugin(designer: Designer, editor: Editor, plugins: Plugins) { async function registryInnerPlugin(designer: Designer, editor: Editor, plugins: Plugins): Promise<IPublicTypeDisposable> {
// 注册一批内置插件 // 注册一批内置插件
const componentMetaParserPlugin = componentMetaParser(designer);
const defaultPanelRegistryPlugin = defaultPanelRegistry(editor);
await plugins.register(OutlinePlugin, {}, { autoInit: true }); await plugins.register(OutlinePlugin, {}, { autoInit: true });
await plugins.register(componentMetaParser(designer)); await plugins.register(componentMetaParserPlugin);
await plugins.register(setterRegistry, {}); await plugins.register(setterRegistry, {});
await plugins.register(defaultPanelRegistry(editor)); await plugins.register(defaultPanelRegistryPlugin);
await plugins.register(builtinHotkey); await plugins.register(builtinHotkey);
await plugins.register(registerDefaults, {}, { autoInit: true }); await plugins.register(registerDefaults, {}, { autoInit: true });
return () => {
plugins.delete(OutlinePlugin.pluginName);
plugins.delete(componentMetaParserPlugin.pluginName);
plugins.delete(setterRegistry.pluginName);
plugins.delete(defaultPanelRegistryPlugin.pluginName);
plugins.delete(defaultPanelRegistryPlugin.pluginName);
plugins.delete(builtinHotkey.pluginName);
plugins.delete(registerDefaults.pluginName);
};
} }
const innerWorkspace = new InnerWorkspace(registryInnerPlugin, shellModelFactory); const innerWorkspace = new InnerWorkspace(registryInnerPlugin, shellModelFactory);
@ -158,7 +171,7 @@ let engineContainer: HTMLElement;
export const version = VERSION_PLACEHOLDER; export const version = VERSION_PLACEHOLDER;
engineConfig.set('ENGINE_VERSION', version); engineConfig.set('ENGINE_VERSION', version);
registryInnerPlugin(designer, editor, plugins); const pluginPromise = registryInnerPlugin(designer, editor, plugins);
export async function init( export async function init(
container?: HTMLElement, container?: HTMLElement,
@ -183,10 +196,10 @@ export async function init(
} }
engineConfig.setEngineOptions(engineOptions as any); engineConfig.setEngineOptions(engineOptions as any);
await plugins.init(pluginPreference as any);
const { Workbench } = common.skeletonCabin; const { Workbench } = common.skeletonCabin;
if (options && options.enableWorkspaceMode) { if (options && options.enableWorkspaceMode) {
const disposeFun = await pluginPromise;
disposeFun && disposeFun();
render( render(
createElement(WorkSpaceWorkbench, { createElement(WorkSpaceWorkbench, {
workspace: innerWorkspace, workspace: innerWorkspace,
@ -202,6 +215,8 @@ export async function init(
return; return;
} }
await plugins.init(pluginPreference as any);
render( render(
createElement(Workbench, { createElement(Workbench, {
skeleton: innerSkeleton, skeleton: innerSkeleton,

View File

@ -102,6 +102,9 @@ function initRerenderEvent({
return; return;
} }
cache.event.get(schema.id)?.dispose.forEach((disposeFn: any) => disposeFn && disposeFn()); cache.event.get(schema.id)?.dispose.forEach((disposeFn: any) => disposeFn && disposeFn());
const debounceRerender = debounce(() => {
container.rerender();
}, 20);
cache.event.set(schema.id, { cache.event.set(schema.id, {
clear: false, clear: false,
leaf, leaf,
@ -111,21 +114,21 @@ function initRerenderEvent({
return; return;
} }
__debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onPropsChange make rerender`); __debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onPropsChange make rerender`);
container.rerender(); debounceRerender();
}), }),
leaf?.onChildrenChange?.(() => { leaf?.onChildrenChange?.(() => {
if (!container.autoRepaintNode) { if (!container.autoRepaintNode) {
return; return;
} }
__debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onChildrenChange make rerender`); __debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onChildrenChange make rerender`);
container.rerender(); debounceRerender();
}) as Function, }) as Function,
leaf?.onVisibleChange?.(() => { leaf?.onVisibleChange?.(() => {
if (!container.autoRepaintNode) { if (!container.autoRepaintNode) {
return; return;
} }
__debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onVisibleChange make rerender`); __debug(`${schema.componentName}[${schema.id}] leaf not render in SimulatorRendererView, leaf onVisibleChange make rerender`);
container.rerender(); debounceRerender();
}), }),
], ],
}); });

View File

@ -1,4 +1,4 @@
import { editorSymbol, skeletonSymbol, designerCabinSymbol, designerSymbol } from '../symbols'; import { editorSymbol, skeletonSymbol, designerCabinSymbol, designerSymbol, settingFieldSymbol } from '../symbols';
import { import {
isFormEvent as innerIsFormEvent, isFormEvent as innerIsFormEvent,
compatibleLegaoSchema as innerCompatibleLegaoSchema, compatibleLegaoSchema as innerCompatibleLegaoSchema,
@ -25,6 +25,7 @@ import {
IPublicTypeLocationDetailType as InnerLocationDetailType, IPublicTypeLocationDetailType as InnerLocationDetailType,
IPublicApiCommonEditorCabin, IPublicApiCommonEditorCabin,
IPublicModelDragon, IPublicModelDragon,
IPublicModelSettingField,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { import {
SettingField as InnerSettingField, SettingField as InnerSettingField,
@ -168,8 +169,8 @@ class SkeletonCabin implements IPublicApiCommonSkeletonCabin {
/** /**
* @deprecated * @deprecated
*/ */
createSettingFieldView(item: any, field: any) { createSettingFieldView(field: IPublicModelSettingField, fieldEntry: any) {
return innerCreateSettingFieldView(item, field); return innerCreateSettingFieldView((field as any)[settingFieldSymbol] || field, fieldEntry);
} }
/** /**

View File

@ -18,6 +18,9 @@ import {
import { DocumentModel as ShellDocumentModel } from '../model'; import { DocumentModel as ShellDocumentModel } from '../model';
import { SimulatorHost } from './simulator-host'; import { SimulatorHost } from './simulator-host';
import { editorSymbol, projectSymbol, simulatorHostSymbol, documentSymbol } from '../symbols'; import { editorSymbol, projectSymbol, simulatorHostSymbol, documentSymbol } from '../symbols';
import { getLogger } from '@alilc/lowcode-utils';
const logger = getLogger({ level: 'warn', bizName: 'shell-project' });
const innerProjectSymbol = Symbol('innerProject'); const innerProjectSymbol = Symbol('innerProject');
export class Project implements IPublicApiProject { export class Project implements IPublicApiProject {
@ -29,6 +32,10 @@ export class Project implements IPublicApiProject {
} }
const workspace = globalContext.get('workspace'); const workspace = globalContext.get('workspace');
if (workspace.isActive) { if (workspace.isActive) {
if (!workspace.window.innerProject) {
logger.error('project api 调用时机出现问题,请检查');
return this[innerProjectSymbol];
}
return workspace.window.innerProject; return workspace.window.innerProject;
} }
@ -43,8 +50,8 @@ export class Project implements IPublicApiProject {
this[innerProjectSymbol] = project; this[innerProjectSymbol] = project;
} }
static create(project: InnerProject) { static create(project: InnerProject, workspaceMode: boolean = false) {
return new Project(project); return new Project(project, workspaceMode);
} }
/** /**
@ -225,15 +232,15 @@ export class Project implements IPublicApiProject {
*/ */
setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void; setConfig<T extends keyof IPublicTypeAppConfig>(key: T, value: IPublicTypeAppConfig[T]): void;
setConfig(value: IPublicTypeAppConfig): void; setConfig(value: IPublicTypeAppConfig): void;
setConfig(...params: any[]): void{ setConfig(...params: any[]): void {
if(params.length === 2) { if (params.length === 2) {
const oldConfig = this[projectSymbol].get('config'); const oldConfig = this[projectSymbol].get('config');
this[projectSymbol].set('config', { this[projectSymbol].set('config', {
...oldConfig, ...oldConfig,
[params[0]]: params[1], [params[0]]: params[1],
}) });
} else { } else {
this[projectSymbol].set('config', params[0]) this[projectSymbol].set('config', params[0]);
} }
} }
} }

View File

@ -1,10 +1,13 @@
import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types'; import { IPublicTypeCustomView, IPublicApiSetters, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
import { Setters as InnerSetters, globalContext } from '@alilc/lowcode-editor-core'; import { Setters as InnerSetters, globalContext } from '@alilc/lowcode-editor-core';
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import { getLogger } from '@alilc/lowcode-utils';
const innerSettersSymbol = Symbol('setters'); const innerSettersSymbol = Symbol('setters');
const settersSymbol = Symbol('setters'); const settersSymbol = Symbol('setters');
const logger = getLogger({ level: 'warn', bizName: 'shell-setters' });
export class Setters implements IPublicApiSetters { export class Setters implements IPublicApiSetters {
readonly [innerSettersSymbol]: InnerSetters; readonly [innerSettersSymbol]: InnerSetters;
@ -15,6 +18,10 @@ export class Setters implements IPublicApiSetters {
const workspace = globalContext.get('workspace'); const workspace = globalContext.get('workspace');
if (workspace.isActive) { if (workspace.isActive) {
if (!workspace.window.innerSetters) {
logger.error('setter api 调用时机出现问题,请检查');
return this[innerSettersSymbol];
}
return workspace.window.innerSetters; return workspace.window.innerSetters;
} }

View File

@ -35,8 +35,8 @@ export class Workspace implements IPublicApiWorkspace {
this[workspaceSymbol].registerResourceType(resourceTypeModel); this[workspaceSymbol].registerResourceType(resourceTypeModel);
} }
openEditorWindow(resourceName: string, title: string, extra: object, viewName?: string) { openEditorWindow(resourceName: string, title: string, extra: object, viewName?: string, sleep?: boolean): void {
this[workspaceSymbol].openEditorWindow(resourceName, title, extra, viewName); this[workspaceSymbol].openEditorWindow(resourceName, title, extra, viewName, sleep);
} }
openEditorWindowById(id: string) { openEditorWindowById(id: string) {

View File

@ -10,6 +10,7 @@ import {
SettingTopEntry, SettingTopEntry,
Clipboard, Clipboard,
SettingField, SettingField,
Window,
} from './model'; } from './model';
import { import {
Project, Project,
@ -50,6 +51,7 @@ export {
Selection, Selection,
Setters, Setters,
Hotkey, Hotkey,
Window,
Skeleton, Skeleton,
SettingField as SettingPropEntry, SettingField as SettingPropEntry,
SettingTopEntry, SettingTopEntry,

View File

@ -90,7 +90,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
* @returns * @returns
*/ */
get project(): IPublicApiProject { get project(): IPublicApiProject {
return ShellProject.create(this[documentSymbol].project); return ShellProject.create(this[documentSymbol].project, true);
} }
/** /**

View File

@ -30,7 +30,7 @@ export interface IPublicApiWorkspace<
registerResourceType(resourceTypeModel: IPublicTypeResourceType): void; registerResourceType(resourceTypeModel: IPublicTypeResourceType): void;
/** 打开视图窗口 */ /** 打开视图窗口 */
openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string): void; openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string, sleep?: boolean): void;
/** 通过视图 id 打开窗口 */ /** 通过视图 id 打开窗口 */
openEditorWindowById(id: string): void; openEditorWindowById(id: string): void;

View File

@ -30,6 +30,7 @@ import {
Common, Common,
Logger, Logger,
Workspace, Workspace,
Window,
Canvas, Canvas,
} from '@alilc/lowcode-shell'; } from '@alilc/lowcode-shell';
import { import {
@ -164,6 +165,9 @@ export class BasicContext implements IBasicContext {
context.plugins = plugins; context.plugins = plugins;
context.logger = new Logger({ level: 'warn', bizName: `plugin:${pluginName}` }); context.logger = new Logger({ level: 'warn', bizName: `plugin:${pluginName}` });
context.canvas = canvas; context.canvas = canvas;
if (editorWindow) {
context.editorWindow = new Window(editorWindow);
}
}, },
}; };

View File

@ -368,6 +368,9 @@ body {
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
flex-direction: column;
display: flex;
align-content: stretch;
} }
.engine-actionitem { .engine-actionitem {

View File

@ -39,7 +39,7 @@ export class Resource implements IResource {
} }
get viewName() { get viewName() {
return this.resourceData.viewName || (this.resourceData as any).viewType; return this.resourceData.viewName || (this.resourceData as any).viewType || this.defaultViewType;
} }
get description() { get description() {

View File

@ -10,6 +10,7 @@ interface IWindowCOnfig {
title: string | undefined; title: string | undefined;
options?: Object; options?: Object;
viewType?: string | undefined; viewType?: string | undefined;
sleep?: boolean;
} }
export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'changeViewType'> { export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'changeViewType'> {
@ -18,6 +19,12 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan
editorViews: Map<string, Context>; editorViews: Map<string, Context>;
changeViewType: (name: string, ignoreEmit?: boolean) => void; changeViewType: (name: string, ignoreEmit?: boolean) => void;
initReady: boolean;
sleep?: boolean;
init(): void;
} }
export class EditorWindow implements IEditorWindow { export class EditorWindow implements IEditorWindow {
@ -36,11 +43,16 @@ export class EditorWindow implements IEditorWindow {
@obx initReady = false; @obx initReady = false;
sleep: boolean | undefined;
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.init();
this.title = config.title; this.title = config.title;
this.icon = resource.icon; this.icon = resource.icon;
this.sleep = config.sleep;
if (!config.sleep) {
this.init();
}
} }
async importSchema(schema: any) { async importSchema(schema: any) {
@ -73,6 +85,8 @@ export class EditorWindow implements IEditorWindow {
this.url = await this.resource.url(); this.url = await this.resource.url();
this.setDefaultViewType(); this.setDefaultViewType();
this.initReady = true; this.initReady = true;
this.workspace.checkWindowQueue();
this.sleep = false;
} }
initViewTypes = async () => { initViewTypes = async () => {

View File

@ -30,6 +30,8 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
getResourceList(): IResource[]; getResourceList(): IResource[];
getResourceType(resourceName: string): IResourceType; getResourceType(resourceName: string): IResourceType;
checkWindowQueue(): void;
} }
export class Workspace implements IWorkspace { export class Workspace implements IWorkspace {
@ -69,6 +71,13 @@ export class Workspace implements IWorkspace {
@obx.ref window: IEditorWindow; @obx.ref window: IEditorWindow;
windowQueue: {
name: string;
title: string;
options: Object;
viewType?: string;
}[] = [];
constructor( constructor(
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<void>, readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<void>,
readonly shellModelFactory: any, readonly shellModelFactory: any,
@ -77,6 +86,17 @@ export class Workspace implements IWorkspace {
makeObservable(this); makeObservable(this);
} }
checkWindowQueue() {
if (!this.windowQueue || !this.windowQueue.length) {
return;
}
const windowInfo = this.windowQueue.shift();
if (windowInfo) {
this.openEditorWindow(windowInfo.name, windowInfo.title, windowInfo.options, windowInfo.viewType);
}
}
init() { init() {
this.initWindow(); this.initWindow();
this.context = new BasicContext(this, ''); this.context = new BasicContext(this, '');
@ -86,13 +106,13 @@ export class Workspace implements IWorkspace {
if (!this.defaultResourceType) { if (!this.defaultResourceType) {
return; return;
} }
const title = this.defaultResourceType.name; const resourceName = this.defaultResourceType.name;
const resource = new Resource({ const resource = new Resource({
resourceName: title, resourceName,
options: {}, options: {},
}, this.defaultResourceType, this); }, this.defaultResourceType, this);
this.window = new EditorWindow(resource, this, { this.window = new EditorWindow(resource, this, {
title, title: resource.title,
}); });
this.editorWindowMap.set(this.window.id, this.window); this.editorWindowMap.set(this.window.id, this.window);
this.windows.push(this.window); this.windows.push(this.window);
@ -167,7 +187,13 @@ export class Workspace implements IWorkspace {
} }
} }
openEditorWindow(name: string, title: string, options: Object, viewType?: string) { openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
if (!this.window?.initReady && !sleep) {
this.windowQueue.push({
name, title, options, viewType,
});
return;
}
const resourceType = this.resourceTypeMap.get(name); const resourceType = this.resourceTypeMap.get(name);
if (!resourceType) { if (!resourceType) {
console.error(`${name} resourceType is not available`); console.error(`${name} resourceType is not available`);
@ -176,6 +202,11 @@ export class Workspace implements IWorkspace {
const filterWindows = this.windows.filter(d => (d.resource?.name === name && d.resource.title == title)); const filterWindows = this.windows.filter(d => (d.resource?.name === name && d.resource.title == title));
if (filterWindows && filterWindows.length) { if (filterWindows && filterWindows.length) {
this.window = filterWindows[0]; this.window = filterWindows[0];
if (!sleep && this.window.sleep) {
this.window.init();
} else {
this.checkWindowQueue();
}
this.emitChangeActiveWindow(); this.emitChangeActiveWindow();
return; return;
} }
@ -184,13 +215,17 @@ export class Workspace implements IWorkspace {
title, title,
options, options,
}, resourceType, this); }, resourceType, this);
this.window = new EditorWindow(resource, this, { const window = new EditorWindow(resource, this, {
title, title,
options, options,
viewType, viewType,
sleep,
}); });
this.windows = [...this.windows, this.window]; this.windows = [...this.windows, window];
this.editorWindowMap.set(this.window.id, this.window); this.editorWindowMap.set(window.id, window);
if (!sleep) {
this.window = window;
}
this.emitChangeWindow(); this.emitChangeWindow();
this.emitChangeActiveWindow(); this.emitChangeActiveWindow();
} }