mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
feat(workspace): add enableAutoOpenFirstWindow config and onWindowRendererReady function
This commit is contained in:
parent
dff06e70ac
commit
9b50bc700e
@ -145,6 +145,11 @@ const VALID_ENGINE_OPTIONS = {
|
|||||||
type: 'function',
|
type: 'function',
|
||||||
description: '配置指定节点为根组件',
|
description: '配置指定节点为根组件',
|
||||||
},
|
},
|
||||||
|
enableAutoOpenFirstWindow: {
|
||||||
|
type: 'boolean',
|
||||||
|
description: '应用级设计模式下,自动打开第一个窗口',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStrictModeValue = (engineOptions: IPublicTypeEngineOptions, defaultValue: boolean): boolean => {
|
const getStrictModeValue = (engineOptions: IPublicTypeEngineOptions, defaultValue: boolean): boolean => {
|
||||||
|
|||||||
@ -9,12 +9,15 @@ import {
|
|||||||
engineConfig,
|
engineConfig,
|
||||||
Setters as InnerSetters,
|
Setters as InnerSetters,
|
||||||
Hotkey as InnerHotkey,
|
Hotkey as InnerHotkey,
|
||||||
|
IEditor,
|
||||||
} from '@alilc/lowcode-editor-core';
|
} from '@alilc/lowcode-editor-core';
|
||||||
import {
|
import {
|
||||||
IPublicTypeEngineOptions,
|
IPublicTypeEngineOptions,
|
||||||
IPublicModelDocumentModel,
|
IPublicModelDocumentModel,
|
||||||
IPublicTypePluginMeta,
|
IPublicTypePluginMeta,
|
||||||
IPublicTypeDisposable,
|
IPublicTypeDisposable,
|
||||||
|
IPublicApiPlugins,
|
||||||
|
IPublicApiWorkspace,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import {
|
import {
|
||||||
Designer,
|
Designer,
|
||||||
@ -22,6 +25,7 @@ import {
|
|||||||
ILowCodePluginContextPrivate,
|
ILowCodePluginContextPrivate,
|
||||||
ILowCodePluginContextApiAssembler,
|
ILowCodePluginContextApiAssembler,
|
||||||
PluginPreference,
|
PluginPreference,
|
||||||
|
IDesigner,
|
||||||
} from '@alilc/lowcode-designer';
|
} from '@alilc/lowcode-designer';
|
||||||
import {
|
import {
|
||||||
Skeleton as InnerSkeleton,
|
Skeleton as InnerSkeleton,
|
||||||
@ -30,6 +34,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
Workspace as InnerWorkspace,
|
Workspace as InnerWorkspace,
|
||||||
Workbench as WorkSpaceWorkbench,
|
Workbench as WorkSpaceWorkbench,
|
||||||
|
IWorkspace,
|
||||||
} from '@alilc/lowcode-workspace';
|
} from '@alilc/lowcode-workspace';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -61,7 +66,7 @@ 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): Promise<IPublicTypeDisposable> {
|
async function registryInnerPlugin(designer: IDesigner, editor: IEditor, plugins: IPublicApiPlugins): Promise<IPublicTypeDisposable> {
|
||||||
// 注册一批内置插件
|
// 注册一批内置插件
|
||||||
const componentMetaParserPlugin = componentMetaParser(designer);
|
const componentMetaParserPlugin = componentMetaParser(designer);
|
||||||
const defaultPanelRegistryPlugin = defaultPanelRegistry(editor);
|
const defaultPanelRegistryPlugin = defaultPanelRegistry(editor);
|
||||||
@ -83,8 +88,8 @@ async function registryInnerPlugin(designer: Designer, editor: Editor, plugins:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const innerWorkspace = new InnerWorkspace(registryInnerPlugin, shellModelFactory);
|
const innerWorkspace: IWorkspace = new InnerWorkspace(registryInnerPlugin, shellModelFactory);
|
||||||
const workspace = new Workspace(innerWorkspace);
|
const workspace: IPublicApiWorkspace = new Workspace(innerWorkspace);
|
||||||
const editor = new Editor();
|
const editor = new Editor();
|
||||||
globalContext.register(editor, Editor);
|
globalContext.register(editor, Editor);
|
||||||
globalContext.register(editor, 'editor');
|
globalContext.register(editor, 'editor');
|
||||||
@ -207,7 +212,9 @@ export async function init(
|
|||||||
}),
|
}),
|
||||||
engineContainer,
|
engineContainer,
|
||||||
);
|
);
|
||||||
|
innerWorkspace.enableAutoOpenFirstWindow = engineConfig.get('enableAutoOpenFirstWindow', true);
|
||||||
innerWorkspace.setActive(true);
|
innerWorkspace.setActive(true);
|
||||||
|
innerWorkspace.initWindow();
|
||||||
innerHotkey.activate(false);
|
innerHotkey.activate(false);
|
||||||
await innerWorkspace.plugins.init(pluginPreference);
|
await innerWorkspace.plugins.init(pluginPreference);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ 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) {
|
if (!workspace.window?.innerProject) {
|
||||||
logger.error('project api 调用时机出现问题,请检查');
|
logger.error('project api 调用时机出现问题,请检查');
|
||||||
return this[innerProjectSymbol];
|
return this[innerProjectSymbol];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,12 @@ import {
|
|||||||
} from '@alilc/lowcode-editor-skeleton';
|
} from '@alilc/lowcode-editor-skeleton';
|
||||||
import { skeletonSymbol } from '../symbols';
|
import { skeletonSymbol } from '../symbols';
|
||||||
import { IPublicApiSkeleton, IPublicTypeDisposable, IPublicTypeSkeletonConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types';
|
import { IPublicApiSkeleton, IPublicTypeDisposable, IPublicTypeSkeletonConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types';
|
||||||
|
import { getLogger } from '@alilc/lowcode-utils';
|
||||||
|
|
||||||
const innerSkeletonSymbol = Symbol('skeleton');
|
const innerSkeletonSymbol = Symbol('skeleton');
|
||||||
|
|
||||||
|
const logger = getLogger({ level: 'warn', bizName: 'shell-skeleton' });
|
||||||
|
|
||||||
export class Skeleton implements IPublicApiSkeleton {
|
export class Skeleton implements IPublicApiSkeleton {
|
||||||
private readonly [innerSkeletonSymbol]: ISkeleton;
|
private readonly [innerSkeletonSymbol]: ISkeleton;
|
||||||
private readonly pluginName: string;
|
private readonly pluginName: string;
|
||||||
@ -18,6 +21,10 @@ export class Skeleton implements IPublicApiSkeleton {
|
|||||||
}
|
}
|
||||||
const workspace = globalContext.get('workspace');
|
const workspace = globalContext.get('workspace');
|
||||||
if (workspace.isActive) {
|
if (workspace.isActive) {
|
||||||
|
if (!workspace.window.innerSkeleton) {
|
||||||
|
logger.error('skeleton api 调用时机出现问题,请检查');
|
||||||
|
return this[innerSkeletonSymbol];
|
||||||
|
}
|
||||||
return workspace.window.innerSkeleton;
|
return workspace.window.innerSkeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,9 +28,16 @@ export class Workspace implements IPublicApiWorkspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get window() {
|
get window() {
|
||||||
|
if (!this[workspaceSymbol].window) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new ShellWindow(this[workspaceSymbol].window);
|
return new ShellWindow(this[workspaceSymbol].window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onWindowRendererReady(fn: () => void): IPublicTypeDisposable {
|
||||||
|
return this[workspaceSymbol].onWindowRendererReady(fn);
|
||||||
|
}
|
||||||
|
|
||||||
registerResourceType(resourceTypeModel: IPublicTypeResourceType): void {
|
registerResourceType(resourceTypeModel: IPublicTypeResourceType): void {
|
||||||
this[workspaceSymbol].registerResourceType(resourceTypeModel);
|
this[workspaceSymbol].registerResourceType(resourceTypeModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,4 +41,8 @@ export class Window implements IPublicModelWindow {
|
|||||||
async save() {
|
async save() {
|
||||||
return await this[windowSymbol].save();
|
return await this[windowSymbol].save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get plugins() {
|
||||||
|
return this[windowSymbol].plugins;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export interface IPublicApiWorkspace<
|
|||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
|
||||||
/** 当前设计器窗口 */
|
/** 当前设计器窗口 */
|
||||||
window: ModelWindow;
|
window: ModelWindow | null;
|
||||||
|
|
||||||
plugins: Plugins;
|
plugins: Plugins;
|
||||||
|
|
||||||
@ -46,4 +46,10 @@ export interface IPublicApiWorkspace<
|
|||||||
|
|
||||||
/** active 窗口变更事件 */
|
/** active 窗口变更事件 */
|
||||||
onChangeActiveWindow(fn: () => void): IPublicTypeDisposable;
|
onChangeActiveWindow(fn: () => void): IPublicTypeDisposable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* window 下的所有视图 renderer ready 事件
|
||||||
|
* @since v1.1.7
|
||||||
|
*/
|
||||||
|
onWindowRendererReady(fn: () => void): IPublicTypeDisposable;
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@ import { RequestHandlersMap } from '@alilc/lowcode-datasource-types';
|
|||||||
import { ComponentType } from 'react';
|
import { ComponentType } from 'react';
|
||||||
|
|
||||||
export interface IPublicTypeEngineOptions {
|
export interface IPublicTypeEngineOptions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否开启 condition 的能力,默认在设计器中不管 condition 是啥都正常展示
|
* 是否开启 condition 的能力,默认在设计器中不管 condition 是啥都正常展示
|
||||||
* when this is true, node that configured as conditional not renderring
|
* when this is true, node that configured as conditional not renderring
|
||||||
@ -136,8 +137,10 @@ export interface IPublicTypeEngineOptions {
|
|||||||
* 与 react-renderer 的 appHelper 一致,https://lowcode-engine.cn/site/docs/guide/expand/runtime/renderer#apphelper
|
* 与 react-renderer 的 appHelper 一致,https://lowcode-engine.cn/site/docs/guide/expand/runtime/renderer#apphelper
|
||||||
*/
|
*/
|
||||||
appHelper?: {
|
appHelper?: {
|
||||||
|
|
||||||
/** 全局公共函数 */
|
/** 全局公共函数 */
|
||||||
utils?: Record<string, any>;
|
utils?: Record<string, any>;
|
||||||
|
|
||||||
/** 全局常量 */
|
/** 全局常量 */
|
||||||
constants?: Record<string, any>;
|
constants?: Record<string, any>;
|
||||||
};
|
};
|
||||||
@ -168,6 +171,12 @@ export interface IPublicTypeEngineOptions {
|
|||||||
* 开启应用级设计模式
|
* 开启应用级设计模式
|
||||||
*/
|
*/
|
||||||
enableWorkspaceMode?: boolean;
|
enableWorkspaceMode?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @default true
|
||||||
|
* 应用级设计模式下,自动打开第一个窗口
|
||||||
|
*/
|
||||||
|
enableAutoOpenFirstWindow?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,10 +17,6 @@ export class Context extends BasicContext {
|
|||||||
|
|
||||||
@obx isInit: boolean = false;
|
@obx isInit: boolean = false;
|
||||||
|
|
||||||
@computed get active() {
|
|
||||||
return this._activate;
|
|
||||||
}
|
|
||||||
|
|
||||||
init = flow(function* (this: Context) {
|
init = flow(function* (this: Context) {
|
||||||
if (this.viewType === 'webview') {
|
if (this.viewType === 'webview') {
|
||||||
const url = yield this.instance?.url?.();
|
const url = yield this.instance?.url?.();
|
||||||
@ -43,6 +39,18 @@ export class Context extends BasicContext {
|
|||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@computed get active() {
|
||||||
|
return this._activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSimulatorRendererReady = (): Promise<void> => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.project.onSimulatorRendererReady(() => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
setActivate = (_activate: boolean) => {
|
setActivate = (_activate: boolean) => {
|
||||||
this._activate = _activate;
|
this._activate = _activate;
|
||||||
this.innerHotkey.activate(this._activate);
|
this.innerHotkey.activate(this._activate);
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export class Workbench extends Component<{
|
|||||||
{
|
{
|
||||||
workspace.windows.map(d => (
|
workspace.windows.map(d => (
|
||||||
<WindowView
|
<WindowView
|
||||||
active={d.id === workspace.window.id}
|
active={d.id === workspace.window?.id}
|
||||||
window={d}
|
window={d}
|
||||||
key={d.id}
|
key={d.id}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -82,6 +82,9 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
async init() {
|
async init() {
|
||||||
await this.initViewTypes();
|
await this.initViewTypes();
|
||||||
await this.execViewTypesInit();
|
await this.execViewTypesInit();
|
||||||
|
Promise.all(Array.from(this.editorViews.values()).map((d) => d.onSimulatorRendererReady)).then(() => {
|
||||||
|
this.workspace.emitWindowRendererReady();
|
||||||
|
});
|
||||||
this.url = await this.resource.url();
|
this.url = await this.resource.url();
|
||||||
this.setDefaultViewType();
|
this.setDefaultViewType();
|
||||||
this.initReady = true;
|
this.initReady = true;
|
||||||
@ -182,6 +185,10 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
return this.editorView?.designer;
|
return this.editorView?.designer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get plugins() {
|
||||||
|
return this.editorView?.plugins;
|
||||||
|
}
|
||||||
|
|
||||||
get innerPlugins() {
|
get innerPlugins() {
|
||||||
return this.editorView?.innerPlugins;
|
return this.editorView?.innerPlugins;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { IDesigner, ILowCodePluginManager, LowCodePluginManager } from '@alilc/lowcode-designer';
|
import { IDesigner, ILowCodePluginManager, LowCodePluginManager } from '@alilc/lowcode-designer';
|
||||||
import { createModuleEventBus, Editor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
import { createModuleEventBus, Editor, IEditor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
||||||
import { IPublicApiPlugins, IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType, IShellModelFactory } from '@alilc/lowcode-types';
|
import { IPublicApiPlugins, IPublicApiWorkspace, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType, IShellModelFactory } from '@alilc/lowcode-types';
|
||||||
import { BasicContext } from './context/base-context';
|
import { BasicContext } from './context/base-context';
|
||||||
import { EditorWindow } from './window';
|
import { EditorWindow } from './window';
|
||||||
import type { IEditorWindow } from './window';
|
import type { IEditorWindow } from './window';
|
||||||
@ -11,6 +11,8 @@ enum EVENT {
|
|||||||
CHANGE_WINDOW = 'change_window',
|
CHANGE_WINDOW = 'change_window',
|
||||||
|
|
||||||
CHANGE_ACTIVE_WINDOW = 'change_active_window',
|
CHANGE_ACTIVE_WINDOW = 'change_active_window',
|
||||||
|
|
||||||
|
WINDOW_RENDER_READY = 'window_render_ready',
|
||||||
}
|
}
|
||||||
|
|
||||||
const CHANGE_EVENT = 'resource.list.change';
|
const CHANGE_EVENT = 'resource.list.change';
|
||||||
@ -19,10 +21,12 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
|
|||||||
LowCodePluginManager,
|
LowCodePluginManager,
|
||||||
IEditorWindow
|
IEditorWindow
|
||||||
>, 'resourceList' | 'plugins'> {
|
>, 'resourceList' | 'plugins'> {
|
||||||
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<void>;
|
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<IPublicTypeDisposable>;
|
||||||
|
|
||||||
readonly shellModelFactory: IShellModelFactory;
|
readonly shellModelFactory: IShellModelFactory;
|
||||||
|
|
||||||
|
enableAutoOpenFirstWindow: boolean;
|
||||||
|
|
||||||
window: IEditorWindow;
|
window: IEditorWindow;
|
||||||
|
|
||||||
plugins: ILowCodePluginManager;
|
plugins: ILowCodePluginManager;
|
||||||
@ -32,11 +36,19 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
|
|||||||
getResourceType(resourceName: string): IResourceType;
|
getResourceType(resourceName: string): IResourceType;
|
||||||
|
|
||||||
checkWindowQueue(): void;
|
checkWindowQueue(): void;
|
||||||
|
|
||||||
|
emitWindowRendererReady(): void;
|
||||||
|
|
||||||
|
initWindow(): void;
|
||||||
|
|
||||||
|
setActive(active: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Workspace implements IWorkspace {
|
export class Workspace implements IWorkspace {
|
||||||
context: BasicContext;
|
context: BasicContext;
|
||||||
|
|
||||||
|
enableAutoOpenFirstWindow: boolean;
|
||||||
|
|
||||||
private emitter: IEventBus = createModuleEventBus('workspace');
|
private emitter: IEventBus = createModuleEventBus('workspace');
|
||||||
|
|
||||||
private _isActive = false;
|
private _isActive = false;
|
||||||
@ -79,10 +91,10 @@ export class Workspace implements IWorkspace {
|
|||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<void>,
|
readonly registryInnerPlugin: (designer: IDesigner, editor: IEditor, plugins: IPublicApiPlugins) => Promise<IPublicTypeDisposable>,
|
||||||
readonly shellModelFactory: any,
|
readonly shellModelFactory: any,
|
||||||
) {
|
) {
|
||||||
this.init();
|
this.context = new BasicContext(this, '');
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,13 +109,8 @@ export class Workspace implements IWorkspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
|
||||||
this.initWindow();
|
|
||||||
this.context = new BasicContext(this, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
initWindow() {
|
initWindow() {
|
||||||
if (!this.defaultResourceType) {
|
if (!this.defaultResourceType || this.enableAutoOpenFirstWindow === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const resourceName = this.defaultResourceType.name;
|
const resourceName = this.defaultResourceType.name;
|
||||||
@ -128,7 +135,7 @@ export class Workspace implements IWorkspace {
|
|||||||
const resourceType = new ResourceType(resourceTypeModel);
|
const resourceType = new ResourceType(resourceTypeModel);
|
||||||
this.resourceTypeMap.set(resourceTypeModel.resourceName, resourceType);
|
this.resourceTypeMap.set(resourceTypeModel.resourceName, resourceType);
|
||||||
|
|
||||||
if (!this.window && this.defaultResourceType) {
|
if (!this.window && this.defaultResourceType && this._isActive) {
|
||||||
this.initWindow();
|
this.initWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,6 +156,17 @@ export class Workspace implements IWorkspace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onWindowRendererReady(fn: () => void): IPublicTypeDisposable {
|
||||||
|
this.emitter.on(EVENT.WINDOW_RENDER_READY, fn);
|
||||||
|
return () => {
|
||||||
|
this.emitter.off(EVENT.WINDOW_RENDER_READY, fn);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
emitWindowRendererReady() {
|
||||||
|
this.emitter.emit(EVENT.WINDOW_RENDER_READY);
|
||||||
|
}
|
||||||
|
|
||||||
getResourceType(resourceName: string): IResourceType {
|
getResourceType(resourceName: string): IResourceType {
|
||||||
return this.resourceTypeMap.get(resourceName)!;
|
return this.resourceTypeMap.get(resourceName)!;
|
||||||
}
|
}
|
||||||
@ -188,7 +206,7 @@ export class Workspace implements IWorkspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
|
openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
|
||||||
if (!this.window?.initReady && !sleep) {
|
if (this.window && !this.window?.initReady && !sleep) {
|
||||||
this.windowQueue.push({
|
this.windowQueue.push({
|
||||||
name, title, options, viewType,
|
name, title, options, viewType,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user