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