mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-19 14:04:28 +00:00
feat: 隔离运行插件
feat: PluginContext 增加 setters
This commit is contained in:
parent
b295da1a02
commit
298c810937
@ -5,3 +5,4 @@ export * from './document';
|
|||||||
export * from './project';
|
export * from './project';
|
||||||
export * from './builtin-simulator';
|
export * from './builtin-simulator';
|
||||||
export * from './plugin';
|
export * from './plugin';
|
||||||
|
export * from './types';
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Editor, Hotkey, hotkey } from '@ali/lowcode-editor-core';
|
import { Editor, Hotkey, hotkey, getSetter, registerSetter, getSettersMap } from '@ali/lowcode-editor-core';
|
||||||
import { Skeleton } from '@ali/lowcode-editor-skeleton';
|
import { Skeleton } from '@ali/lowcode-editor-skeleton';
|
||||||
import { ILowCodePluginConfig, ILowCodePluginManager, ILowCodePluginContext, IDesignerCabin } from './plugin-types';
|
import { ILowCodePluginConfig, ILowCodePluginManager, ILowCodePluginContext, IDesignerCabin } from './plugin-types';
|
||||||
import { getLogger, Logger } from '../utils';
|
import { getLogger, Logger } from '../utils';
|
||||||
@ -8,6 +8,7 @@ import {
|
|||||||
removeBuiltinComponentAction,
|
removeBuiltinComponentAction,
|
||||||
} from '../component-meta';
|
} from '../component-meta';
|
||||||
import { Designer } from '../designer';
|
import { Designer } from '../designer';
|
||||||
|
import { Setters } from '../types';
|
||||||
|
|
||||||
export default class PluginContext implements ILowCodePluginContext {
|
export default class PluginContext implements ILowCodePluginContext {
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
@ -17,6 +18,7 @@ export default class PluginContext implements ILowCodePluginContext {
|
|||||||
logger: Logger;
|
logger: Logger;
|
||||||
plugins: ILowCodePluginManager;
|
plugins: ILowCodePluginManager;
|
||||||
designerCabin: IDesignerCabin;
|
designerCabin: IDesignerCabin;
|
||||||
|
setters: Setters;
|
||||||
|
|
||||||
constructor(editor: Editor, plugins: ILowCodePluginManager) {
|
constructor(editor: Editor, plugins: ILowCodePluginManager) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
@ -25,6 +27,11 @@ export default class PluginContext implements ILowCodePluginContext {
|
|||||||
this.hotkey = hotkey;
|
this.hotkey = hotkey;
|
||||||
this.plugins = plugins;
|
this.plugins = plugins;
|
||||||
this.designerCabin = this.createDesignerCabin();
|
this.designerCabin = this.createDesignerCabin();
|
||||||
|
this.setters = {
|
||||||
|
getSetter,
|
||||||
|
registerSetter,
|
||||||
|
getSettersMap,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private createDesignerCabin(): IDesignerCabin {
|
private createDesignerCabin(): IDesignerCabin {
|
||||||
|
|||||||
@ -75,7 +75,12 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
|||||||
logger.log('load plugin sequence:', sequence);
|
logger.log('load plugin sequence:', sequence);
|
||||||
|
|
||||||
for (const pluginName of sequence) {
|
for (const pluginName of sequence) {
|
||||||
|
try {
|
||||||
await this.pluginsMap.get(pluginName)!.init();
|
await this.pluginsMap.get(pluginName)!.init();
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(`Failed to init plugin:${pluginName}, it maybe affect those plugins which depend on this.`);
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import {
|
|||||||
MetadataTransducer,
|
MetadataTransducer,
|
||||||
Designer,
|
Designer,
|
||||||
} from '@ali/lowcode-designer';
|
} from '@ali/lowcode-designer';
|
||||||
|
import { Setters } from '../types';
|
||||||
|
|
||||||
export interface ILowCodePluginConfig {
|
export interface ILowCodePluginConfig {
|
||||||
name: string;
|
name: string;
|
||||||
@ -51,6 +52,7 @@ export interface ILowCodePluginContext {
|
|||||||
logger: Logger;
|
logger: Logger;
|
||||||
plugins: ILowCodePluginManager;
|
plugins: ILowCodePluginManager;
|
||||||
designerCabin: IDesignerCabin;
|
designerCabin: IDesignerCabin;
|
||||||
|
setters: Setters;
|
||||||
/**
|
/**
|
||||||
其他暂不增加,按需增加
|
其他暂不增加,按需增加
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -42,6 +42,7 @@ export class LowCodePlugin implements ILowCodePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get dep() {
|
get dep() {
|
||||||
|
if (typeof this.config.dep === 'string') return [this.config.dep];
|
||||||
return this.config.dep || [];
|
return this.config.dep || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
packages/designer/src/types/index.ts
Normal file
7
packages/designer/src/types/index.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { getSetter, registerSetter, getSettersMap } from '@ali/lowcode-editor-core';
|
||||||
|
|
||||||
|
export type Setters = {
|
||||||
|
getSetter: typeof getSetter;
|
||||||
|
registerSetter: typeof registerSetter;
|
||||||
|
getSettersMap: typeof getSettersMap;
|
||||||
|
};
|
||||||
@ -5,6 +5,8 @@ import * as editorCabin from '@ali/lowcode-editor-core';
|
|||||||
import {
|
import {
|
||||||
Designer,
|
Designer,
|
||||||
LowCodePluginManager,
|
LowCodePluginManager,
|
||||||
|
ILowCodePluginContext,
|
||||||
|
Setters,
|
||||||
} from '@ali/lowcode-designer';
|
} from '@ali/lowcode-designer';
|
||||||
import * as designerCabin from '@ali/lowcode-designer';
|
import * as designerCabin from '@ali/lowcode-designer';
|
||||||
import { Skeleton, SettingsPrimaryPane, registerDefaults } from '@ali/lowcode-editor-skeleton';
|
import { Skeleton, SettingsPrimaryPane, registerDefaults } from '@ali/lowcode-editor-skeleton';
|
||||||
@ -35,45 +37,9 @@ editor.set('designer' as any, designer);
|
|||||||
const plugins = new LowCodePluginManager(editor).toProxy();
|
const plugins = new LowCodePluginManager(editor).toProxy();
|
||||||
editor.set('plugins' as any, plugins);
|
editor.set('plugins' as any, plugins);
|
||||||
|
|
||||||
skeleton.add({
|
|
||||||
area: 'mainArea',
|
|
||||||
name: 'designer',
|
|
||||||
type: 'Widget',
|
|
||||||
content: DesignerPlugin,
|
|
||||||
});
|
|
||||||
skeleton.add({
|
|
||||||
area: 'rightArea',
|
|
||||||
name: 'settingsPane',
|
|
||||||
type: 'Panel',
|
|
||||||
content: SettingsPrimaryPane,
|
|
||||||
props: {
|
|
||||||
ignoreRoot: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
skeleton.add({
|
|
||||||
area: 'leftArea',
|
|
||||||
name: 'outlinePane',
|
|
||||||
type: 'PanelDock',
|
|
||||||
content: Outline,
|
|
||||||
panelProps: {
|
|
||||||
area: 'leftFixedArea',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
skeleton.add({
|
|
||||||
area: 'rightArea',
|
|
||||||
name: 'backupOutline',
|
|
||||||
type: 'Panel',
|
|
||||||
props: {
|
|
||||||
condition: () => {
|
|
||||||
return designer.dragon.dragging && !getTreeMaster(designer).hasVisibleTreeBoard();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
content: OutlineBackupPane,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { project, currentSelection: selection } = designer;
|
const { project, currentSelection: selection } = designer;
|
||||||
const { Workbench } = skeletonCabin;
|
const { Workbench } = skeletonCabin;
|
||||||
const setters = {
|
const setters: Setters = {
|
||||||
getSetter,
|
getSetter,
|
||||||
registerSetter,
|
registerSetter,
|
||||||
getSettersMap,
|
getSettersMap,
|
||||||
@ -130,11 +96,64 @@ const getSelection = () => designer.currentDocument?.selection;
|
|||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function init(container?: Element) {
|
// 注册默认的 setters
|
||||||
|
plugins.register((ctx: ILowCodePluginContext) => {
|
||||||
|
return {
|
||||||
|
name: '___setter_registry___',
|
||||||
|
init() {
|
||||||
const builtinSetters = require('@ali/lowcode-engine-ext').setters;
|
const builtinSetters = require('@ali/lowcode-engine-ext').setters;
|
||||||
if (builtinSetters) {
|
if (builtinSetters) {
|
||||||
registerSetter(builtinSetters as any);
|
ctx.setters.registerSetter(builtinSetters);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// 注册默认的面板
|
||||||
|
plugins.register((ctx: ILowCodePluginContext) => {
|
||||||
|
return {
|
||||||
|
name: '___default_panel___',
|
||||||
|
init() {
|
||||||
|
skeleton.add({
|
||||||
|
area: 'mainArea',
|
||||||
|
name: 'designer',
|
||||||
|
type: 'Widget',
|
||||||
|
content: DesignerPlugin,
|
||||||
|
});
|
||||||
|
skeleton.add({
|
||||||
|
area: 'rightArea',
|
||||||
|
name: 'settingsPane',
|
||||||
|
type: 'Panel',
|
||||||
|
content: SettingsPrimaryPane,
|
||||||
|
props: {
|
||||||
|
ignoreRoot: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
skeleton.add({
|
||||||
|
area: 'leftArea',
|
||||||
|
name: 'outlinePane',
|
||||||
|
type: 'PanelDock',
|
||||||
|
content: Outline,
|
||||||
|
panelProps: {
|
||||||
|
area: 'leftFixedArea',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
skeleton.add({
|
||||||
|
area: 'rightArea',
|
||||||
|
name: 'backupOutline',
|
||||||
|
type: 'Panel',
|
||||||
|
props: {
|
||||||
|
condition: () => {
|
||||||
|
return designer.dragon.dragging && !getTreeMaster(designer).hasVisibleTreeBoard();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
content: OutlineBackupPane,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function init(container?: Element) {
|
||||||
let engineContainer = container;
|
let engineContainer = container;
|
||||||
if (!engineContainer) {
|
if (!engineContainer) {
|
||||||
engineContainer = document.createElement('div');
|
engineContainer = document.createElement('div');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user