From 0a2427354b447a6c479ee950548b49b868cce1ab Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 29 Dec 2022 18:30:07 +0800 Subject: [PATCH] feat: plugin add get\getAll\has\delete api --- docs/docs/api/model/plugin-instance.md | 54 +++++++++++++++++++ docs/docs/api/plugins.md | 41 ++++++++++++++ packages/designer/src/plugin/plugin-types.ts | 1 + packages/designer/src/plugin/plugin.ts | 2 +- packages/shell/src/api/plugins.ts | 23 ++++++++ packages/shell/src/model/plugin-instance.ts | 31 +++++++++++ packages/shell/src/symbols.ts | 3 +- packages/types/src/shell/api/plugins.ts | 14 ++++- packages/types/src/shell/model/index.ts | 1 + .../types/src/shell/model/plugin-instance.ts | 11 ++++ 10 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 docs/docs/api/model/plugin-instance.md create mode 100644 packages/shell/src/model/plugin-instance.ts create mode 100644 packages/types/src/shell/model/plugin-instance.ts diff --git a/docs/docs/api/model/plugin-instance.md b/docs/docs/api/model/plugin-instance.md new file mode 100644 index 000000000..9ca872a4f --- /dev/null +++ b/docs/docs/api/model/plugin-instance.md @@ -0,0 +1,54 @@ +--- +title: plugin-instance +sidebar_position: 12 +--- + +> **@types** [IPublicModelPluginInstance](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/plugin-instance.ts)
+> **@since** v1.1.0 + + +## 基本介绍 + +插件实例 + +## 属性 + +### pluginName + +插件名字 + +```typescript +get name(): string; +``` + +### dep + +插件依赖 + +```typescript +get dep(): string[]; +``` + +### disabled + +插件是否禁用 + +```typescript +get disabled(): boolean + +set disabled(disabled: boolean): void; + +``` + +### meta + +插件 meta 信息 + +```typescript +get meta(): IPublicTypePluginMeta + +``` + +- [IPublicTypePluginMeta](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/plugin-meta.ts) + + diff --git a/docs/docs/api/plugins.md b/docs/docs/api/plugins.md index 06b558369..1b20bdabe 100644 --- a/docs/docs/api/plugins.md +++ b/docs/docs/api/plugins.md @@ -159,10 +159,51 @@ BuiltinPluginRegistry.meta = { await plugins.register(BuiltinPluginRegistry, { key1: 'abc', key5: 'willNotPassToPlugin' }); ``` +### get + +获取指定插件 + +```typescript +function get(pluginName: string): IPublicModelPluginInstance; + +``` + +关联模型 [IPublicModelPluginInstance](./model/plugin-instance) + +### getAll + +获取所有的插件实例 + +```typescript +function getAll(): IPublicModelPluginInstance[]; + +``` + +关联模型 [IPublicModelPluginInstance](./model/plugin-instance) + +### has + +判断是否有指定插件 + +```typescript +function has(pluginName: string): boolean; + +``` + +### delete + +删除指定插件 + +```typescript +function delete(pluginName: string): void; + +``` + ## 相关类型定义 - [IPublicModelPluginContext](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/plugin-context.ts) - [IPublicTypePluginConfig](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/plugin-config.ts) +- [IPublicModelPluginInstance](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/plugin-instance.ts) ## 插件元数据工程转化示例 your-plugin/package.json diff --git a/packages/designer/src/plugin/plugin-types.ts b/packages/designer/src/plugin/plugin-types.ts index 7ecfc7c35..8c246a5d2 100644 --- a/packages/designer/src/plugin/plugin-types.ts +++ b/packages/designer/src/plugin/plugin-types.ts @@ -31,6 +31,7 @@ export interface ILowCodePluginRuntimeCore { destroy(): void; toProxy(): any; setDisabled(flag: boolean): void; + meta: IPublicTypePluginMeta; } interface ILowCodePluginRuntimeExportsAccessor { diff --git a/packages/designer/src/plugin/plugin.ts b/packages/designer/src/plugin/plugin.ts index 5bbaaa745..dd57325fc 100644 --- a/packages/designer/src/plugin/plugin.ts +++ b/packages/designer/src/plugin/plugin.ts @@ -20,7 +20,7 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime { private pluginName: string; - private meta: IPublicTypePluginMeta; + meta: IPublicTypePluginMeta; /** * 标识插件状态,是否被 disabled diff --git a/packages/shell/src/api/plugins.ts b/packages/shell/src/api/plugins.ts index 8a0a506e5..681628515 100644 --- a/packages/shell/src/api/plugins.ts +++ b/packages/shell/src/api/plugins.ts @@ -4,10 +4,12 @@ import { import { globalContext } from '@alilc/lowcode-editor-core'; import { IPublicApiPlugins, + IPublicModelPluginInstance, IPublicTypePlugin, IPublicTypePluginRegisterOptions, IPublicTypePreferenceValueType, } from '@alilc/lowcode-types'; +import { PluginInstance } from '../model/plugin-instance'; import { pluginsSymbol } from '../symbols'; const innerPluginsSymbol = Symbol('plugin'); @@ -45,6 +47,27 @@ export class Plugins implements IPublicApiPlugins { return this[pluginsSymbol].getPluginPreference(pluginName); } + get(pluginName: string): IPublicModelPluginInstance | null { + const instance = this[pluginsSymbol].get(pluginName); + if (instance) { + return new PluginInstance(instance); + } + + return null; + } + + getAll() { + return this[pluginsSymbol].getAll()?.map(d => new PluginInstance(d)); + } + + has(pluginName: string) { + return this[pluginsSymbol].has(pluginName); + } + + delete(pluginName: string) { + this[pluginsSymbol].delete(pluginName); + } + toProxy() { return new Proxy(this, { get(target, prop, receiver) { diff --git a/packages/shell/src/model/plugin-instance.ts b/packages/shell/src/model/plugin-instance.ts new file mode 100644 index 000000000..47a619482 --- /dev/null +++ b/packages/shell/src/model/plugin-instance.ts @@ -0,0 +1,31 @@ +import { ILowCodePluginRuntime } from '@alilc/lowcode-designer'; +import { IPublicModelPluginInstance } from '@alilc/lowcode-types'; +import { pluginInstanceSymbol } from '../symbols'; + +export class PluginInstance implements IPublicModelPluginInstance { + private readonly [pluginInstanceSymbol]: ILowCodePluginRuntime; + + constructor(pluginInstance: ILowCodePluginRuntime) { + this[pluginInstanceSymbol] = pluginInstance; + } + + get pluginName(): string { + return this[pluginInstanceSymbol].name; + } + + get dep(): string[] { + return this[pluginInstanceSymbol].dep; + } + + get disabled(): boolean { + return this[pluginInstanceSymbol].disabled; + } + + set disabled(disabled: boolean) { + this[pluginInstanceSymbol].setDisabled(disabled); + } + + get meta() { + return this[pluginInstanceSymbol].meta; + } +} \ No newline at end of file diff --git a/packages/shell/src/symbols.ts b/packages/shell/src/symbols.ts index 44c241b28..6e0924893 100644 --- a/packages/shell/src/symbols.ts +++ b/packages/shell/src/symbols.ts @@ -28,4 +28,5 @@ export const designerCabinSymbol = Symbol('designerCabin'); export const hotkeySymbol = Symbol('hotkey'); export const pluginsSymbol = Symbol('plugins'); export const workspaceSymbol = Symbol('workspace'); -export const windowSymbol = Symbol('window'); \ No newline at end of file +export const windowSymbol = Symbol('window'); +export const pluginInstanceSymbol = Symbol('plugin-instance'); \ No newline at end of file diff --git a/packages/types/src/shell/api/plugins.ts b/packages/types/src/shell/api/plugins.ts index 2797ba071..32e13c3b6 100644 --- a/packages/types/src/shell/api/plugins.ts +++ b/packages/types/src/shell/api/plugins.ts @@ -1,4 +1,4 @@ -import { IPublicTypePlugin } from '../model'; +import { IPublicModelPluginInstance, IPublicTypePlugin } from '../model'; import { IPublicTypePreferenceValueType } from '../type'; import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options'; @@ -25,4 +25,16 @@ export interface IPublicApiPlugins { getPluginPreference( pluginName: string, ): Record | null | undefined; + + /** 获取指定插件 */ + get(pluginName: string): IPublicModelPluginInstance | null; + + /** 获取所有的插件实例 */ + getAll(): IPublicModelPluginInstance[]; + + /** 判断是否有指定插件 */ + has(pluginName: string): boolean; + + /** 删除指定插件 */ + delete(pluginName: string): void; } \ No newline at end of file diff --git a/packages/types/src/shell/model/index.ts b/packages/types/src/shell/model/index.ts index c9d8f3a98..e1daf63a0 100644 --- a/packages/types/src/shell/model/index.ts +++ b/packages/types/src/shell/model/index.ts @@ -26,3 +26,4 @@ export * from './setting-target'; export * from './engine-config'; export * from './editor'; export * from './preference'; +export * from './plugin-instance'; \ No newline at end of file diff --git a/packages/types/src/shell/model/plugin-instance.ts b/packages/types/src/shell/model/plugin-instance.ts new file mode 100644 index 000000000..7855d903b --- /dev/null +++ b/packages/types/src/shell/model/plugin-instance.ts @@ -0,0 +1,11 @@ +import { IPublicTypePluginMeta } from '../type/plugin-meta'; + +export interface IPublicModelPluginInstance { + pluginName: string; + + dep: string[]; + + disabled: boolean; + + meta: IPublicTypePluginMeta; +} \ No newline at end of file