mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-10 18:03:01 +00:00
feat(workspace): update openEditorWindow api
This commit is contained in:
parent
9ddda1db9e
commit
899ffa1554
@ -84,7 +84,14 @@ setResourceList(resourceList: IPublicResourceList) {}
|
||||
打开视图窗口
|
||||
|
||||
```typescript
|
||||
openEditorWindow(resourceName: string, title: string, options: Object, viewName?: string): void;
|
||||
/**
|
||||
* 打开视图窗口
|
||||
* @deprecated
|
||||
*/
|
||||
openEditorWindow(resourceName: string, id: string, extra: Object, viewName?: string, sleep?: boolean): Promise<void>;
|
||||
|
||||
/** 打开视图窗口 */
|
||||
openEditorWindow(resource: Resource, sleep?: boolean): Promise<void>;
|
||||
```
|
||||
|
||||
### openEditorWindowById
|
||||
@ -100,7 +107,7 @@ openEditorWindowById(id: string): void;
|
||||
移除视图窗口
|
||||
|
||||
```typescript
|
||||
removeEditorWindow(resourceName: string, title: string): void;
|
||||
removeEditorWindow(resourceName: string, id: string): void;
|
||||
```
|
||||
|
||||
### removeEditorWindowById
|
||||
|
||||
@ -84,8 +84,8 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
const ctx = this._getLowCodePluginContext({ pluginName, meta });
|
||||
const customFilterValidOptions = engineConfig.get('customPluginFilterOptions', filterValidOptions);
|
||||
const pluginTransducer = engineConfig.get('customPluginTransducer', null);
|
||||
const newOptions = customFilterValidOptions(options, preferenceDeclaration!);
|
||||
const newPluginModel = pluginTransducer ? await pluginTransducer(pluginModel, ctx, newOptions) : pluginModel;
|
||||
const newPluginModel = pluginTransducer ? await pluginTransducer(pluginModel, ctx, options) : pluginModel;
|
||||
const newOptions = customFilterValidOptions(options, newPluginModel.meta?.preferenceDeclaration);
|
||||
const config = newPluginModel(ctx, newOptions);
|
||||
// compat the legacy way to declare pluginName
|
||||
// @ts-ignore
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
|
||||
import { IWorkspace } from '@alilc/lowcode-workspace';
|
||||
import { workspaceSymbol } from '../symbols';
|
||||
import { resourceSymbol, workspaceSymbol } from '../symbols';
|
||||
import { Resource as ShellResource, Window as ShellWindow } from '../model';
|
||||
import { Plugins } from './plugins';
|
||||
|
||||
@ -64,16 +64,20 @@ export class Workspace implements IPublicApiWorkspace {
|
||||
this[workspaceSymbol].registerResourceType(resourceTypeModel);
|
||||
}
|
||||
|
||||
async openEditorWindow(resourceName: string, title: string, extra: object, viewName?: string, sleep?: boolean): Promise<void> {
|
||||
await this[workspaceSymbol].openEditorWindow(resourceName, title, extra, viewName, sleep);
|
||||
async openEditorWindow(): Promise<void> {
|
||||
if (typeof arguments[0] === 'string') {
|
||||
await this[workspaceSymbol].openEditorWindow(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
|
||||
} else {
|
||||
await this[workspaceSymbol].openEditorWindowByResource(arguments[0]?.[resourceSymbol], arguments[1]);
|
||||
}
|
||||
}
|
||||
|
||||
openEditorWindowById(id: string) {
|
||||
this[workspaceSymbol].openEditorWindowById(id);
|
||||
}
|
||||
|
||||
removeEditorWindow(resourceName: string, title: string) {
|
||||
this[workspaceSymbol].removeEditorWindow(resourceName, title);
|
||||
removeEditorWindow(resourceName: string, id: string) {
|
||||
this[workspaceSymbol].removeEditorWindow(resourceName, id);
|
||||
}
|
||||
|
||||
removeEditorWindowById(id: string) {
|
||||
|
||||
@ -13,6 +13,10 @@ export class Resource implements IPublicModelResource {
|
||||
return this[resourceSymbol].title;
|
||||
}
|
||||
|
||||
get id() {
|
||||
return this[resourceSymbol].id;
|
||||
}
|
||||
|
||||
get icon() {
|
||||
return this[resourceSymbol].icon;
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@ import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTy
|
||||
|
||||
export interface IPublicApiWorkspace<
|
||||
Plugins = IPublicApiPlugins,
|
||||
ModelWindow = IPublicModelWindow
|
||||
ModelWindow = IPublicModelWindow,
|
||||
Resource = IPublicModelResource,
|
||||
> {
|
||||
|
||||
/** 是否启用 workspace 模式 */
|
||||
@ -29,14 +30,20 @@ export interface IPublicApiWorkspace<
|
||||
/** 注册资源 */
|
||||
registerResourceType(resourceTypeModel: IPublicTypeResourceType): void;
|
||||
|
||||
/**
|
||||
* 打开视图窗口
|
||||
* @deprecated
|
||||
*/
|
||||
openEditorWindow(resourceName: string, id: string, extra: Object, viewName?: string, sleep?: boolean): Promise<void>;
|
||||
|
||||
/** 打开视图窗口 */
|
||||
openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string, sleep?: boolean): Promise<void>;
|
||||
openEditorWindow(resource: Resource, sleep?: boolean): Promise<void>;
|
||||
|
||||
/** 通过视图 id 打开窗口 */
|
||||
openEditorWindowById(id: string): void;
|
||||
|
||||
/** 移除视图窗口 */
|
||||
removeEditorWindow(resourceName: string, title: string): void;
|
||||
removeEditorWindow(resourceName: string, id: string): void;
|
||||
|
||||
/** 通过视图 id 移除窗口 */
|
||||
removeEditorWindowById(id: string): void;
|
||||
|
||||
@ -5,6 +5,8 @@ export interface IBaseModelResource<
|
||||
> {
|
||||
get title(): string | undefined;
|
||||
|
||||
get id(): string | undefined;
|
||||
|
||||
get icon(): ReactElement | undefined;
|
||||
|
||||
get options(): Record<string, any>;
|
||||
|
||||
@ -8,6 +8,9 @@ export interface IPublicResourceData {
|
||||
/** 资源标题 */
|
||||
title?: string;
|
||||
|
||||
/** 资源 Id */
|
||||
id?: string;
|
||||
|
||||
/** 分类 */
|
||||
category?: string;
|
||||
|
||||
@ -24,10 +27,6 @@ export interface IPublicResourceData {
|
||||
|
||||
/** 资源子元素 */
|
||||
children?: IPublicResourceData[];
|
||||
|
||||
config?: {
|
||||
disableBehaviors?: ('copy' | 'remove')[];
|
||||
};
|
||||
}
|
||||
|
||||
export type IPublicResourceList = IPublicResourceData[];
|
||||
@ -60,6 +60,10 @@ export class Resource implements IResource {
|
||||
return this.resourceData.title || this.resourceTypeInstance.defaultTitle;
|
||||
}
|
||||
|
||||
get id(): string | undefined {
|
||||
return this.resourceData.id;
|
||||
}
|
||||
|
||||
get options() {
|
||||
return this.resourceData.options;
|
||||
}
|
||||
|
||||
@ -50,6 +50,8 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
|
||||
onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable;
|
||||
|
||||
emitChangeActiveEditorView(): void;
|
||||
|
||||
openEditorWindowByResource(resource: IResource, sleep: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
export class Workspace implements IWorkspace {
|
||||
@ -91,12 +93,12 @@ export class Workspace implements IWorkspace {
|
||||
|
||||
@obx.ref window: IEditorWindow;
|
||||
|
||||
windowQueue: {
|
||||
windowQueue: ({
|
||||
name: string;
|
||||
title: string;
|
||||
options: Object;
|
||||
viewName?: string;
|
||||
}[] = [];
|
||||
} | IResource)[] = [];
|
||||
|
||||
constructor(
|
||||
readonly registryInnerPlugin: (designer: IDesigner, editor: IEditor, plugins: IPublicApiPlugins) => Promise<IPublicTypeDisposable>,
|
||||
@ -192,7 +194,7 @@ export class Workspace implements IWorkspace {
|
||||
this.remove(index);
|
||||
}
|
||||
|
||||
private remove(index: number) {
|
||||
private async remove(index: number) {
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
@ -202,7 +204,7 @@ export class Workspace implements IWorkspace {
|
||||
if (this.window === window) {
|
||||
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
|
||||
if (this.window?.sleep) {
|
||||
this.window.init();
|
||||
await this.window.init();
|
||||
}
|
||||
this.emitChangeActiveWindow();
|
||||
}
|
||||
@ -210,8 +212,8 @@ export class Workspace implements IWorkspace {
|
||||
this.window?.updateState(WINDOW_STATE.active);
|
||||
}
|
||||
|
||||
removeEditorWindow(resourceName: string, title: string) {
|
||||
const index = this.windows.findIndex(d => (d.resource?.name === resourceName && d.title === title));
|
||||
removeEditorWindow(resourceName: string, id: string) {
|
||||
const index = this.windows.findIndex(d => (d.resource?.name === resourceName && d.title === id));
|
||||
this.remove(index);
|
||||
}
|
||||
|
||||
@ -228,6 +230,47 @@ export class Workspace implements IWorkspace {
|
||||
this.window?.updateState(WINDOW_STATE.active);
|
||||
}
|
||||
|
||||
async openEditorWindowByResource(resource: IResource, sleep: boolean = false): Promise<void> {
|
||||
if (this.window && !this.window?.initReady && !sleep) {
|
||||
this.windowQueue.push(resource);
|
||||
return;
|
||||
}
|
||||
|
||||
this.window?.updateState(WINDOW_STATE.inactive);
|
||||
|
||||
const filterWindows = this.windows.filter(d => (d.resource?.id === resource.id));
|
||||
if (filterWindows && filterWindows.length) {
|
||||
this.window = filterWindows[0];
|
||||
if (!sleep && this.window.sleep) {
|
||||
await this.window.init();
|
||||
} else {
|
||||
this.checkWindowQueue();
|
||||
}
|
||||
this.emitChangeActiveWindow();
|
||||
this.window?.updateState(WINDOW_STATE.active);
|
||||
return;
|
||||
}
|
||||
|
||||
const window = new EditorWindow(resource, this, {
|
||||
title: resource.title,
|
||||
options: resource.options,
|
||||
viewName: resource.viewName,
|
||||
sleep,
|
||||
});
|
||||
|
||||
this.windows = [...this.windows, window];
|
||||
this.editorWindowMap.set(window.id, window);
|
||||
if (sleep) {
|
||||
this.emitChangeWindow();
|
||||
return;
|
||||
}
|
||||
this.window = window;
|
||||
await this.window.init();
|
||||
this.emitChangeWindow();
|
||||
this.emitChangeActiveWindow();
|
||||
this.window?.updateState(WINDOW_STATE.active);
|
||||
}
|
||||
|
||||
async openEditorWindow(name: string, title: string, options: Object, viewName?: string, sleep?: boolean) {
|
||||
if (this.window && !this.window?.initReady && !sleep) {
|
||||
this.windowQueue.push({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user