mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 01:37:17 +00:00
feat: add plugin to shell
This commit is contained in:
parent
bad2d5e8ad
commit
5312614d30
@ -42,7 +42,6 @@ export default class PluginContext implements ILowCodePluginContext, ILowCodePlu
|
||||
contextApiAssembler: ILowCodePluginContextApiAssembler,
|
||||
) {
|
||||
contextApiAssembler.assembleApis(this);
|
||||
this.plugins = plugins;
|
||||
const { pluginName = 'anonymous' } = options;
|
||||
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
||||
|
||||
|
||||
@ -33,13 +33,13 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
|
||||
contextApiAssembler: ILowCodePluginContextApiAssembler;
|
||||
|
||||
constructor(contextApiAssembler: ILowCodePluginContextApiAssembler) {
|
||||
constructor(contextApiAssembler: ILowCodePluginContextApiAssembler, readonly name = 'unknown') {
|
||||
this.contextApiAssembler = contextApiAssembler;
|
||||
}
|
||||
|
||||
_getLowCodePluginContext(options: IPluginContextOptions) {
|
||||
_getLowCodePluginContext = (options: IPluginContextOptions) => {
|
||||
return new LowCodePluginContext(this, options, this.contextApiAssembler);
|
||||
}
|
||||
};
|
||||
|
||||
isEngineVersionMatched(versionExp: string): boolean {
|
||||
const engineVersion = engineConfig.get('ENGINE_VERSION');
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
CompositeObject,
|
||||
ComponentAction,
|
||||
MetadataTransducer,
|
||||
IPublicApiPlugins,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { Setters } from '../types';
|
||||
@ -126,6 +127,7 @@ export interface ILowCodePluginContextPrivate {
|
||||
set event(event: IPublicApiEvent);
|
||||
set config(config: EngineConfig);
|
||||
set common(common: IPublicApiCommon);
|
||||
set plugins(plugins: IPublicApiPlugins);
|
||||
}
|
||||
export interface ILowCodePluginContextApiAssembler {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate) => void;
|
||||
|
||||
@ -367,7 +367,7 @@ export class Skeleton {
|
||||
...extraConfig,
|
||||
};
|
||||
parsedConfig.contentProps = {
|
||||
context: this.editor.get('plugins')?._getLowCodePluginContext({
|
||||
context: this.editor.get('innerPlugins')?._getLowCodePluginContext({
|
||||
pluginName: 'any',
|
||||
}),
|
||||
...(parsedConfig.contentProps || {}),
|
||||
|
||||
@ -34,6 +34,7 @@ import {
|
||||
Setters,
|
||||
Material,
|
||||
Event,
|
||||
Plugins,
|
||||
DocumentModel,
|
||||
Common,
|
||||
} from '@alilc/lowcode-shell';
|
||||
@ -82,6 +83,7 @@ const config = engineConfig;
|
||||
const event = new Event(editor, { prefix: 'common' });
|
||||
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
||||
const common = new Common(editor, innerSkeleton);
|
||||
let plugins: any;
|
||||
|
||||
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||
@ -93,9 +95,13 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||
context.event = event;
|
||||
context.config = config;
|
||||
context.common = common;
|
||||
context.plugins = plugins;
|
||||
},
|
||||
};
|
||||
const plugins = new LowCodePluginManager(pluginContextApiAssembler).toProxy();
|
||||
|
||||
const innerPlugins = new LowCodePluginManager(pluginContextApiAssembler);
|
||||
plugins = new Plugins(innerPlugins).toProxy();
|
||||
editor.set('innerPlugins' as any, innerPlugins);
|
||||
editor.set('plugins' as any, plugins);
|
||||
|
||||
export {
|
||||
|
||||
@ -15,6 +15,7 @@ import Dragon from './dragon';
|
||||
import SettingPropEntry from './setting-prop-entry';
|
||||
import SettingTopEntry from './setting-top-entry';
|
||||
import Common from './common';
|
||||
import Plugins from './plugins';
|
||||
|
||||
export * from './symbols';
|
||||
|
||||
@ -44,4 +45,5 @@ export {
|
||||
Dragon,
|
||||
Common,
|
||||
getEvent,
|
||||
Plugins,
|
||||
};
|
||||
52
packages/shell/src/plugins.ts
Normal file
52
packages/shell/src/plugins.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import {
|
||||
LowCodePluginManager,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { globalContext } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
IPublicApiPlugins,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { pluginsSymbol } from './symbols';
|
||||
|
||||
const innerPluginsSymbol = Symbol('plugin');
|
||||
export default class Plugins implements IPublicApiPlugins {
|
||||
private readonly [innerPluginsSymbol]: LowCodePluginManager;
|
||||
get [pluginsSymbol]() {
|
||||
if (this.workspaceMode) {
|
||||
return this[innerPluginsSymbol];
|
||||
}
|
||||
const workSpace = globalContext.get('workSpace');
|
||||
if (workSpace.isActive) {
|
||||
return workSpace.window.innerPlugins;
|
||||
}
|
||||
|
||||
return this[innerPluginsSymbol];
|
||||
}
|
||||
|
||||
constructor(plugins: LowCodePluginManager, public workspaceMode: boolean = false) {
|
||||
this[innerPluginsSymbol] = plugins;
|
||||
}
|
||||
|
||||
async register(
|
||||
pluginConfigCreator: (ctx: any, options: any) => any,
|
||||
options?: any,
|
||||
registerOptions?: any,
|
||||
): Promise<void> {
|
||||
await this[pluginsSymbol].register(pluginConfigCreator, options, registerOptions);
|
||||
}
|
||||
|
||||
toProxy() {
|
||||
return new Proxy(this, {
|
||||
get(target, prop, receiver) {
|
||||
const _target = target[pluginsSymbol];
|
||||
if (_target.pluginsMap.has(prop as string)) {
|
||||
// 禁用态的插件,直接返回 undefined
|
||||
if (_target.pluginsMap.get(prop as string)!.disabled) {
|
||||
return undefined;
|
||||
}
|
||||
return _target.pluginsMap.get(prop as string)?.toProxy();
|
||||
}
|
||||
return Reflect.get(target, prop, receiver);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -25,4 +25,5 @@ export const simulatorRendererSymbol = Symbol('simulatorRenderer');
|
||||
export const dragObjectSymbol = Symbol('dragObject');
|
||||
export const locateEventSymbol = Symbol('locateEvent');
|
||||
export const designerCabinSymbol = Symbol('designerCabin');
|
||||
export const hotkeySymbol = Symbol('hotkey');
|
||||
export const hotkeySymbol = Symbol('hotkey');
|
||||
export const pluginsSymbol = Symbol('plugins');
|
||||
@ -5,4 +5,5 @@ export * from './material';
|
||||
export * from './project';
|
||||
export * from './setters';
|
||||
export * from './simulator-host';
|
||||
export * from './skeleton';
|
||||
export * from './skeleton';
|
||||
export * from './plugins';
|
||||
7
packages/types/src/shell/api/plugins.ts
Normal file
7
packages/types/src/shell/api/plugins.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface IPublicApiPlugins {
|
||||
register(
|
||||
pluginConfigCreator: (ctx: any, options: any) => any,
|
||||
options?: any,
|
||||
registerOptions?: any,
|
||||
): Promise<void>;
|
||||
}
|
||||
@ -4,6 +4,7 @@ import {
|
||||
ILowCodePluginContextApiAssembler,
|
||||
LowCodePluginManager,
|
||||
ILowCodePluginContextPrivate,
|
||||
Project as InnerProject,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import {
|
||||
Skeleton as InnerSkeleton,
|
||||
@ -13,7 +14,16 @@ import {
|
||||
WorkSpace,
|
||||
} from '@alilc/lowcode-workspace';
|
||||
|
||||
import { Hotkey, Project, Skeleton, Setters, Material, Event, Common } from '@alilc/lowcode-shell';
|
||||
import {
|
||||
Hotkey,
|
||||
Plugins,
|
||||
Project,
|
||||
Skeleton,
|
||||
Setters,
|
||||
Material,
|
||||
Event,
|
||||
Common,
|
||||
} from '@alilc/lowcode-shell';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { setterRegistry } from 'engine/src/inner-plugins/setter-registry';
|
||||
import { componentMetaParser } from 'engine/src/inner-plugins/component-meta-parser';
|
||||
@ -23,34 +33,27 @@ import { EditorWindow } from './editor-window/context';
|
||||
import { shellModelFactory } from './shell-model-factory';
|
||||
|
||||
export class BasicContext {
|
||||
skeleton;
|
||||
plugins;
|
||||
project;
|
||||
setters;
|
||||
material;
|
||||
skeleton: Skeleton;
|
||||
plugins: Plugins;
|
||||
project: Project;
|
||||
setters: Setters;
|
||||
material: Material;
|
||||
config;
|
||||
event;
|
||||
logger;
|
||||
hotkey;
|
||||
innerProject;
|
||||
hotkey: Hotkey;
|
||||
innerProject: InnerProject;
|
||||
editor: Editor;
|
||||
designer;
|
||||
registerInnerPlugins: any;
|
||||
innerSetters: any;
|
||||
designer: Designer;
|
||||
registerInnerPlugins: () => Promise<void>;
|
||||
innerSetters: InnerSetters;
|
||||
innerSkeleton: any;
|
||||
innerHotkey: any;
|
||||
innerHotkey: InnerHotkey;
|
||||
innerPlugins: LowCodePluginManager;
|
||||
|
||||
constructor(workSpace: WorkSpace, name: string, public editorWindow?: EditorWindow) {
|
||||
const editor = new Editor(name, true);
|
||||
|
||||
// globalContext.register(editor, Editor);
|
||||
// globalContext.register(editor, 'editor');
|
||||
// if (editorWindow) {
|
||||
// }
|
||||
// const project = editorWindow ? editorWindow.project : new Project(innerProject);
|
||||
// if (editorWindow) {
|
||||
// }
|
||||
|
||||
const innerSkeleton = new InnerSkeleton(editor, name);
|
||||
editor.set('skeleton' as any, innerSkeleton);
|
||||
|
||||
@ -93,6 +96,7 @@ export class BasicContext {
|
||||
this.editor = editor;
|
||||
this.designer = designer;
|
||||
const common = new Common(editor, innerSkeleton);
|
||||
let plugins: any;
|
||||
|
||||
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||
@ -104,16 +108,19 @@ export class BasicContext {
|
||||
context.event = event;
|
||||
context.config = config;
|
||||
context.common = common;
|
||||
context.plugins = plugins;
|
||||
},
|
||||
};
|
||||
|
||||
const plugins = new LowCodePluginManager(pluginContextApiAssembler).toProxy();
|
||||
const innerPlugins = new LowCodePluginManager(pluginContextApiAssembler, name);
|
||||
this.innerPlugins = innerPlugins;
|
||||
plugins = new Plugins(innerPlugins, true).toProxy();
|
||||
editor.set('plugins' as any, plugins);
|
||||
editor.set('innerPlugins' as any, innerPlugins);
|
||||
this.plugins = plugins;
|
||||
|
||||
// 注册一批内置插件
|
||||
this.registerInnerPlugins = async function registerPlugins() {
|
||||
// console.log('ctx', ctx);
|
||||
await plugins.register(componentMetaParser(designer));
|
||||
await plugins.register(setterRegistry);
|
||||
await plugins.register(defaultPanelRegistry(editor, designer));
|
||||
|
||||
@ -26,10 +26,10 @@ export class Context extends BasicContext {
|
||||
|
||||
init = flow(function* (this: any) {
|
||||
yield this.registerInnerPlugins();
|
||||
yield this.editorView?.init(this.plugins._getLowCodePluginContext({
|
||||
yield this.editorView?.init(this.innerPlugins._getLowCodePluginContext({
|
||||
pluginName: 'any',
|
||||
}));
|
||||
yield this.plugins.init();
|
||||
yield this.innerPlugins.init();
|
||||
this.isInit = true;
|
||||
});
|
||||
}
|
||||
@ -96,4 +96,8 @@ export class EditorWindow {
|
||||
get designer() {
|
||||
return this.editorView?.designer;
|
||||
}
|
||||
|
||||
get innerPlugins() {
|
||||
return this.editorView?.innerPlugins;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user