mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +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 './builtin-simulator';
|
||||
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 { ILowCodePluginConfig, ILowCodePluginManager, ILowCodePluginContext, IDesignerCabin } from './plugin-types';
|
||||
import { getLogger, Logger } from '../utils';
|
||||
@ -8,6 +8,7 @@ import {
|
||||
removeBuiltinComponentAction,
|
||||
} from '../component-meta';
|
||||
import { Designer } from '../designer';
|
||||
import { Setters } from '../types';
|
||||
|
||||
export default class PluginContext implements ILowCodePluginContext {
|
||||
editor: Editor;
|
||||
@ -17,6 +18,7 @@ export default class PluginContext implements ILowCodePluginContext {
|
||||
logger: Logger;
|
||||
plugins: ILowCodePluginManager;
|
||||
designerCabin: IDesignerCabin;
|
||||
setters: Setters;
|
||||
|
||||
constructor(editor: Editor, plugins: ILowCodePluginManager) {
|
||||
this.editor = editor;
|
||||
@ -25,6 +27,11 @@ export default class PluginContext implements ILowCodePluginContext {
|
||||
this.hotkey = hotkey;
|
||||
this.plugins = plugins;
|
||||
this.designerCabin = this.createDesignerCabin();
|
||||
this.setters = {
|
||||
getSetter,
|
||||
registerSetter,
|
||||
getSettersMap,
|
||||
};
|
||||
}
|
||||
|
||||
private createDesignerCabin(): IDesignerCabin {
|
||||
|
||||
@ -75,7 +75,12 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
logger.log('load plugin sequence:', sequence);
|
||||
|
||||
for (const pluginName of sequence) {
|
||||
await this.pluginsMap.get(pluginName)!.init();
|
||||
try {
|
||||
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,
|
||||
Designer,
|
||||
} from '@ali/lowcode-designer';
|
||||
import { Setters } from '../types';
|
||||
|
||||
export interface ILowCodePluginConfig {
|
||||
name: string;
|
||||
@ -51,6 +52,7 @@ export interface ILowCodePluginContext {
|
||||
logger: Logger;
|
||||
plugins: ILowCodePluginManager;
|
||||
designerCabin: IDesignerCabin;
|
||||
setters: Setters;
|
||||
/**
|
||||
其他暂不增加,按需增加
|
||||
*/
|
||||
|
||||
@ -42,6 +42,7 @@ export class LowCodePlugin implements ILowCodePlugin {
|
||||
}
|
||||
|
||||
get dep() {
|
||||
if (typeof this.config.dep === 'string') 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 {
|
||||
Designer,
|
||||
LowCodePluginManager,
|
||||
ILowCodePluginContext,
|
||||
Setters,
|
||||
} from '@ali/lowcode-designer';
|
||||
import * as designerCabin from '@ali/lowcode-designer';
|
||||
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();
|
||||
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 { Workbench } = skeletonCabin;
|
||||
const setters = {
|
||||
const setters: Setters = {
|
||||
getSetter,
|
||||
registerSetter,
|
||||
getSettersMap,
|
||||
@ -130,11 +96,64 @@ const getSelection = () => designer.currentDocument?.selection;
|
||||
init,
|
||||
};
|
||||
|
||||
// 注册默认的 setters
|
||||
plugins.register((ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
name: '___setter_registry___',
|
||||
init() {
|
||||
const builtinSetters = require('@ali/lowcode-engine-ext').setters;
|
||||
if (builtinSetters) {
|
||||
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) {
|
||||
const builtinSetters = require('@ali/lowcode-engine-ext').setters;
|
||||
if (builtinSetters) {
|
||||
registerSetter(builtinSetters as any);
|
||||
}
|
||||
let engineContainer = container;
|
||||
if (!engineContainer) {
|
||||
engineContainer = document.createElement('div');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user