GeezerVison is showing github.com — feat: plugin add get\getAll\has\delete api · li55/lowcode-engine@0a24273
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +54Lines changed: 54 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +title: plugin-instance | | 3 | +sidebar_position: 12 | | 4 | +--- | | 5 | + | | 6 | +> **@types** [IPublicModelPluginInstance](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/plugin-instance.ts)<br/> | | 7 | +> **@since** v1.1.0 | | 8 | +
| | 9 | + | | 10 | +## 基本介绍 | | 11 | + | | 12 | +插件实例 | | 13 | + | | 14 | +## 属性 | | 15 | + | | 16 | +### pluginName | | 17 | + | | 18 | +插件名字 | | 19 | + | | 20 | +```typescript | | 21 | +get name(): string; | | 22 | +``` | | 23 | + | | 24 | +### dep | | 25 | + | | 26 | +插件依赖 | | 27 | + | | 28 | +```typescript | | 29 | +get dep(): string[]; | | 30 | +``` | | 31 | + | | 32 | +### disabled | | 33 | + | | 34 | +插件是否禁用 | | 35 | + | | 36 | +```typescript | | 37 | +get disabled(): boolean | | 38 | + | | 39 | +set disabled(disabled: boolean): void; | | 40 | + | | 41 | +``` | | 42 | + | | 43 | +### meta | | 44 | + | | 45 | +插件 meta 信息 | | 46 | + | | 47 | +```typescript | | 48 | +get meta(): IPublicTypePluginMeta | | 49 | + | | 50 | +``` | | 51 | + | | 52 | +- [IPublicTypePluginMeta](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/plugin-meta.ts) | | 53 | + | | 54 | + |
Collapse file Copy file name to clipboardExpand all lines: docs/docs/api/plugins.md +41Lines changed: 41 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -159,10 +159,51 @@ BuiltinPluginRegistry.meta = { | 159 | 159 | await plugins.register(BuiltinPluginRegistry, { key1: 'abc', key5: 'willNotPassToPlugin' }); | 160 | 160 | ``` | 161 | 161 |
| | 162 | +### get | | 163 | + | | 164 | +获取指定插件 | | 165 | + | | 166 | +```typescript | | 167 | +function get(pluginName: string): IPublicModelPluginInstance; | | 168 | +
| | 169 | +``` | | 170 | + | | 171 | +关联模型 [IPublicModelPluginInstance](./model/plugin-instance) | | 172 | + | | 173 | +### getAll | | 174 | + | | 175 | +获取所有的插件实例 | | 176 | + | | 177 | +```typescript | | 178 | +function getAll(): IPublicModelPluginInstance[]; | | 179 | +
| | 180 | +``` | | 181 | + | | 182 | +关联模型 [IPublicModelPluginInstance](./model/plugin-instance) | | 183 | + | | 184 | +### has | | 185 | + | | 186 | +判断是否有指定插件 | | 187 | + | | 188 | +```typescript | | 189 | +function has(pluginName: string): boolean; | | 190 | +
| | 191 | +``` | | 192 | + | | 193 | +### delete | | 194 | + | | 195 | +删除指定插件 | | 196 | + | | 197 | +```typescript | | 198 | +function delete(pluginName: string): void; | | 199 | +
| | 200 | +``` | | 201 | + | 162 | 202 | ## 相关类型定义 | 163 | 203 |
| 164 | 204 | - [IPublicModelPluginContext](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/plugin-context.ts) | 165 | 205 | - [IPublicTypePluginConfig](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/plugin-config.ts) | | 206 | +- [IPublicModelPluginInstance](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/plugin-instance.ts) | 166 | 207 |
| 167 | 208 | ## 插件元数据工程转化示例 | 168 | 209 | your-plugin/package.json | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/plugin/plugin-types.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,7 @@ export interface ILowCodePluginRuntimeCore { | 31 | 31 | destroy(): void; | 32 | 32 | toProxy(): any; | 33 | 33 | setDisabled(flag: boolean): void; | | 34 | + meta: IPublicTypePluginMeta; | 34 | 35 | } | 35 | 36 |
| 36 | 37 | interface ILowCodePluginRuntimeExportsAccessor { | |
Collapse file Copy file name to clipboardExpand all lines: packages/designer/src/plugin/plugin.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,7 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime { | 20 | 20 |
| 21 | 21 | private pluginName: string; | 22 | 22 |
| 23 | | - private meta: IPublicTypePluginMeta; | | 23 | + meta: IPublicTypePluginMeta; | 24 | 24 |
| 25 | 25 | /** | 26 | 26 | * 标识插件状态,是否被 disabled | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/api/plugins.ts +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,10 +4,12 @@ import { | 4 | 4 | import { globalContext } from '@alilc/lowcode-editor-core'; | 5 | 5 | import { | 6 | 6 | IPublicApiPlugins, | | 7 | + IPublicModelPluginInstance, | 7 | 8 | IPublicTypePlugin, | 8 | 9 | IPublicTypePluginRegisterOptions, | 9 | 10 | IPublicTypePreferenceValueType, | 10 | 11 | } from '@alilc/lowcode-types'; | | 12 | +import { PluginInstance } from '../model/plugin-instance'; | 11 | 13 | import { pluginsSymbol } from '../symbols'; | 12 | 14 |
| 13 | 15 | const innerPluginsSymbol = Symbol('plugin'); | @@ -45,6 +47,27 @@ export class Plugins implements IPublicApiPlugins { | 45 | 47 | return this[pluginsSymbol].getPluginPreference(pluginName); | 46 | 48 | } | 47 | 49 |
| | 50 | + get(pluginName: string): IPublicModelPluginInstance | null { | | 51 | + const instance = this[pluginsSymbol].get(pluginName); | | 52 | + if (instance) { | | 53 | + return new PluginInstance(instance); | | 54 | + } | | 55 | + | | 56 | + return null; | | 57 | + } | | 58 | + | | 59 | + getAll() { | | 60 | + return this[pluginsSymbol].getAll()?.map(d => new PluginInstance(d)); | | 61 | + } | | 62 | + | | 63 | + has(pluginName: string) { | | 64 | + return this[pluginsSymbol].has(pluginName); | | 65 | + } | | 66 | + | | 67 | + delete(pluginName: string) { | | 68 | + this[pluginsSymbol].delete(pluginName); | | 69 | + } | | 70 | + | 48 | 71 | toProxy() { | 49 | 72 | return new Proxy(this, { | 50 | 73 | get(target, prop, receiver) { | |
Collapse file Copy file name to clipboard +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { ILowCodePluginRuntime } from '@alilc/lowcode-designer'; | | 2 | +import { IPublicModelPluginInstance } from '@alilc/lowcode-types'; | | 3 | +import { pluginInstanceSymbol } from '../symbols'; | | 4 | + | | 5 | +export class PluginInstance implements IPublicModelPluginInstance { | | 6 | + private readonly [pluginInstanceSymbol]: ILowCodePluginRuntime; | | 7 | + | | 8 | + constructor(pluginInstance: ILowCodePluginRuntime) { | | 9 | + this[pluginInstanceSymbol] = pluginInstance; | | 10 | + } | | 11 | + | | 12 | + get pluginName(): string { | | 13 | + return this[pluginInstanceSymbol].name; | | 14 | + } | | 15 | + | | 16 | + get dep(): string[] { | | 17 | + return this[pluginInstanceSymbol].dep; | | 18 | + } | | 19 | + | | 20 | + get disabled(): boolean { | | 21 | + return this[pluginInstanceSymbol].disabled; | | 22 | + } | | 23 | + | | 24 | + set disabled(disabled: boolean) { | | 25 | + this[pluginInstanceSymbol].setDisabled(disabled); | | 26 | + } | | 27 | + | | 28 | + get meta() { | | 29 | + return this[pluginInstanceSymbol].meta; | | 30 | + } | | 31 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/symbols.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,4 +28,5 @@ export const designerCabinSymbol = Symbol('designerCabin'); | 28 | 28 | export const hotkeySymbol = Symbol('hotkey'); | 29 | 29 | export const pluginsSymbol = Symbol('plugins'); | 30 | 30 | export const workspaceSymbol = Symbol('workspace'); | 31 | | -export const windowSymbol = Symbol('window'); | | 31 | +export const windowSymbol = Symbol('window'); | | 32 | +export const pluginInstanceSymbol = Symbol('plugin-instance'); |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/api/plugins.ts +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { IPublicTypePlugin } from '../model'; | | 1 | +import { IPublicModelPluginInstance, IPublicTypePlugin } from '../model'; | 2 | 2 | import { IPublicTypePreferenceValueType } from '../type'; | 3 | 3 | import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options'; | 4 | 4 |
| @@ -25,4 +25,16 @@ export interface IPublicApiPlugins { | 25 | 25 | getPluginPreference( | 26 | 26 | pluginName: string, | 27 | 27 | ): Record<string, IPublicTypePreferenceValueType> | null | undefined; | | 28 | + | | 29 | + /** 获取指定插件 */ | | 30 | + get(pluginName: string): IPublicModelPluginInstance | null; | | 31 | + | | 32 | + /** 获取所有的插件实例 */ | | 33 | + getAll(): IPublicModelPluginInstance[]; | | 34 | + | | 35 | + /** 判断是否有指定插件 */ | | 36 | + has(pluginName: string): boolean; | | 37 | + | | 38 | + /** 删除指定插件 */ | | 39 | + delete(pluginName: string): void; | 28 | 40 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/model/index.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,3 +26,4 @@ export * from './setting-target'; | 26 | 26 | export * from './engine-config'; | 27 | 27 | export * from './editor'; | 28 | 28 | export * from './preference'; | | 29 | +export * from './plugin-instance'; |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { IPublicTypePluginMeta } from '../type/plugin-meta'; | | 2 | + | | 3 | +export interface IPublicModelPluginInstance { | | 4 | + pluginName: string; | | 5 | + | | 6 | + dep: string[]; | | 7 | + | | 8 | + disabled: boolean; | | 9 | + | | 10 | + meta: IPublicTypePluginMeta; | | 11 | +} |
|