mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 17:57:13 +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: ILowCodePluginContextApiAssembler,
|
||||||
) {
|
) {
|
||||||
contextApiAssembler.assembleApis(this);
|
contextApiAssembler.assembleApis(this);
|
||||||
this.plugins = plugins;
|
|
||||||
const { pluginName = 'anonymous' } = options;
|
const { pluginName = 'anonymous' } = options;
|
||||||
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
||||||
|
|
||||||
|
|||||||
@ -33,13 +33,13 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
|||||||
|
|
||||||
contextApiAssembler: ILowCodePluginContextApiAssembler;
|
contextApiAssembler: ILowCodePluginContextApiAssembler;
|
||||||
|
|
||||||
constructor(contextApiAssembler: ILowCodePluginContextApiAssembler) {
|
constructor(contextApiAssembler: ILowCodePluginContextApiAssembler, readonly name = 'unknown') {
|
||||||
this.contextApiAssembler = contextApiAssembler;
|
this.contextApiAssembler = contextApiAssembler;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getLowCodePluginContext(options: IPluginContextOptions) {
|
_getLowCodePluginContext = (options: IPluginContextOptions) => {
|
||||||
return new LowCodePluginContext(this, options, this.contextApiAssembler);
|
return new LowCodePluginContext(this, options, this.contextApiAssembler);
|
||||||
}
|
};
|
||||||
|
|
||||||
isEngineVersionMatched(versionExp: string): boolean {
|
isEngineVersionMatched(versionExp: string): boolean {
|
||||||
const engineVersion = engineConfig.get('ENGINE_VERSION');
|
const engineVersion = engineConfig.get('ENGINE_VERSION');
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
CompositeObject,
|
CompositeObject,
|
||||||
ComponentAction,
|
ComponentAction,
|
||||||
MetadataTransducer,
|
MetadataTransducer,
|
||||||
|
IPublicApiPlugins,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { Setters } from '../types';
|
import { Setters } from '../types';
|
||||||
@ -126,6 +127,7 @@ export interface ILowCodePluginContextPrivate {
|
|||||||
set event(event: IPublicApiEvent);
|
set event(event: IPublicApiEvent);
|
||||||
set config(config: EngineConfig);
|
set config(config: EngineConfig);
|
||||||
set common(common: IPublicApiCommon);
|
set common(common: IPublicApiCommon);
|
||||||
|
set plugins(plugins: IPublicApiPlugins);
|
||||||
}
|
}
|
||||||
export interface ILowCodePluginContextApiAssembler {
|
export interface ILowCodePluginContextApiAssembler {
|
||||||
assembleApis: (context: ILowCodePluginContextPrivate) => void;
|
assembleApis: (context: ILowCodePluginContextPrivate) => void;
|
||||||
|
|||||||
@ -367,7 +367,7 @@ export class Skeleton {
|
|||||||
...extraConfig,
|
...extraConfig,
|
||||||
};
|
};
|
||||||
parsedConfig.contentProps = {
|
parsedConfig.contentProps = {
|
||||||
context: this.editor.get('plugins')?._getLowCodePluginContext({
|
context: this.editor.get('innerPlugins')?._getLowCodePluginContext({
|
||||||
pluginName: 'any',
|
pluginName: 'any',
|
||||||
}),
|
}),
|
||||||
...(parsedConfig.contentProps || {}),
|
...(parsedConfig.contentProps || {}),
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import {
|
|||||||
Setters,
|
Setters,
|
||||||
Material,
|
Material,
|
||||||
Event,
|
Event,
|
||||||
|
Plugins,
|
||||||
DocumentModel,
|
DocumentModel,
|
||||||
Common,
|
Common,
|
||||||
} from '@alilc/lowcode-shell';
|
} from '@alilc/lowcode-shell';
|
||||||
@ -82,6 +83,7 @@ const config = engineConfig;
|
|||||||
const event = new Event(editor, { prefix: 'common' });
|
const event = new Event(editor, { prefix: 'common' });
|
||||||
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
||||||
const common = new Common(editor, innerSkeleton);
|
const common = new Common(editor, innerSkeleton);
|
||||||
|
let plugins: any;
|
||||||
|
|
||||||
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||||
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||||
@ -93,9 +95,13 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
|||||||
context.event = event;
|
context.event = event;
|
||||||
context.config = config;
|
context.config = config;
|
||||||
context.common = common;
|
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);
|
editor.set('plugins' as any, plugins);
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import Dragon from './dragon';
|
|||||||
import SettingPropEntry from './setting-prop-entry';
|
import SettingPropEntry from './setting-prop-entry';
|
||||||
import SettingTopEntry from './setting-top-entry';
|
import SettingTopEntry from './setting-top-entry';
|
||||||
import Common from './common';
|
import Common from './common';
|
||||||
|
import Plugins from './plugins';
|
||||||
|
|
||||||
export * from './symbols';
|
export * from './symbols';
|
||||||
|
|
||||||
@ -44,4 +45,5 @@ export {
|
|||||||
Dragon,
|
Dragon,
|
||||||
Common,
|
Common,
|
||||||
getEvent,
|
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 dragObjectSymbol = Symbol('dragObject');
|
||||||
export const locateEventSymbol = Symbol('locateEvent');
|
export const locateEventSymbol = Symbol('locateEvent');
|
||||||
export const designerCabinSymbol = Symbol('designerCabin');
|
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 './project';
|
||||||
export * from './setters';
|
export * from './setters';
|
||||||
export * from './simulator-host';
|
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,
|
ILowCodePluginContextApiAssembler,
|
||||||
LowCodePluginManager,
|
LowCodePluginManager,
|
||||||
ILowCodePluginContextPrivate,
|
ILowCodePluginContextPrivate,
|
||||||
|
Project as InnerProject,
|
||||||
} from '@alilc/lowcode-designer';
|
} from '@alilc/lowcode-designer';
|
||||||
import {
|
import {
|
||||||
Skeleton as InnerSkeleton,
|
Skeleton as InnerSkeleton,
|
||||||
@ -13,7 +14,16 @@ import {
|
|||||||
WorkSpace,
|
WorkSpace,
|
||||||
} from '@alilc/lowcode-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 { getLogger } from '@alilc/lowcode-utils';
|
||||||
import { setterRegistry } from 'engine/src/inner-plugins/setter-registry';
|
import { setterRegistry } from 'engine/src/inner-plugins/setter-registry';
|
||||||
import { componentMetaParser } from 'engine/src/inner-plugins/component-meta-parser';
|
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';
|
import { shellModelFactory } from './shell-model-factory';
|
||||||
|
|
||||||
export class BasicContext {
|
export class BasicContext {
|
||||||
skeleton;
|
skeleton: Skeleton;
|
||||||
plugins;
|
plugins: Plugins;
|
||||||
project;
|
project: Project;
|
||||||
setters;
|
setters: Setters;
|
||||||
material;
|
material: Material;
|
||||||
config;
|
config;
|
||||||
event;
|
event;
|
||||||
logger;
|
logger;
|
||||||
hotkey;
|
hotkey: Hotkey;
|
||||||
innerProject;
|
innerProject: InnerProject;
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
designer;
|
designer: Designer;
|
||||||
registerInnerPlugins: any;
|
registerInnerPlugins: () => Promise<void>;
|
||||||
innerSetters: any;
|
innerSetters: InnerSetters;
|
||||||
innerSkeleton: any;
|
innerSkeleton: any;
|
||||||
innerHotkey: any;
|
innerHotkey: InnerHotkey;
|
||||||
|
innerPlugins: LowCodePluginManager;
|
||||||
|
|
||||||
constructor(workSpace: WorkSpace, name: string, public editorWindow?: EditorWindow) {
|
constructor(workSpace: WorkSpace, name: string, public editorWindow?: EditorWindow) {
|
||||||
const editor = new Editor(name, true);
|
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);
|
const innerSkeleton = new InnerSkeleton(editor, name);
|
||||||
editor.set('skeleton' as any, innerSkeleton);
|
editor.set('skeleton' as any, innerSkeleton);
|
||||||
|
|
||||||
@ -93,6 +96,7 @@ export class BasicContext {
|
|||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
this.designer = designer;
|
this.designer = designer;
|
||||||
const common = new Common(editor, innerSkeleton);
|
const common = new Common(editor, innerSkeleton);
|
||||||
|
let plugins: any;
|
||||||
|
|
||||||
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||||
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||||
@ -104,16 +108,19 @@ export class BasicContext {
|
|||||||
context.event = event;
|
context.event = event;
|
||||||
context.config = config;
|
context.config = config;
|
||||||
context.common = common;
|
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('plugins' as any, plugins);
|
||||||
|
editor.set('innerPlugins' as any, innerPlugins);
|
||||||
this.plugins = plugins;
|
this.plugins = plugins;
|
||||||
|
|
||||||
// 注册一批内置插件
|
// 注册一批内置插件
|
||||||
this.registerInnerPlugins = async function registerPlugins() {
|
this.registerInnerPlugins = async function registerPlugins() {
|
||||||
// console.log('ctx', ctx);
|
|
||||||
await plugins.register(componentMetaParser(designer));
|
await plugins.register(componentMetaParser(designer));
|
||||||
await plugins.register(setterRegistry);
|
await plugins.register(setterRegistry);
|
||||||
await plugins.register(defaultPanelRegistry(editor, designer));
|
await plugins.register(defaultPanelRegistry(editor, designer));
|
||||||
|
|||||||
@ -26,10 +26,10 @@ export class Context extends BasicContext {
|
|||||||
|
|
||||||
init = flow(function* (this: any) {
|
init = flow(function* (this: any) {
|
||||||
yield this.registerInnerPlugins();
|
yield this.registerInnerPlugins();
|
||||||
yield this.editorView?.init(this.plugins._getLowCodePluginContext({
|
yield this.editorView?.init(this.innerPlugins._getLowCodePluginContext({
|
||||||
pluginName: 'any',
|
pluginName: 'any',
|
||||||
}));
|
}));
|
||||||
yield this.plugins.init();
|
yield this.innerPlugins.init();
|
||||||
this.isInit = true;
|
this.isInit = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -96,4 +96,8 @@ export class EditorWindow {
|
|||||||
get designer() {
|
get designer() {
|
||||||
return this.editorView?.designer;
|
return this.editorView?.designer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get innerPlugins() {
|
||||||
|
return this.editorView?.innerPlugins;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user