Skip to content

Commit

Permalink
feat: plugin add get\getAll\has\delete api
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Dec 29, 2022
1 parent 1f8d91f commit 0a24273
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 3 deletions.
54 changes: 54 additions & 0 deletions docs/docs/api/model/plugin-instance.md
Original file line number Diff line number Diff line change
@@ -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)<br/>
> **@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)


41 changes: 41 additions & 0 deletions docs/docs/api/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/designer/src/plugin/plugin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ILowCodePluginRuntimeCore {
destroy(): void;
toProxy(): any;
setDisabled(flag: boolean): void;
meta: IPublicTypePluginMeta;
}

interface ILowCodePluginRuntimeExportsAccessor {
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime {

private pluginName: string;

private meta: IPublicTypePluginMeta;
meta: IPublicTypePluginMeta;

/**
* 标识插件状态,是否被 disabled
Expand Down
23 changes: 23 additions & 0 deletions packages/shell/src/api/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions packages/shell/src/model/plugin-instance.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 2 additions & 1 deletion packages/shell/src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
export const windowSymbol = Symbol('window');
export const pluginInstanceSymbol = Symbol('plugin-instance');
14 changes: 13 additions & 1 deletion packages/types/src/shell/api/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPublicTypePlugin } from '../model';
import { IPublicModelPluginInstance, IPublicTypePlugin } from '../model';
import { IPublicTypePreferenceValueType } from '../type';
import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options';

Expand All @@ -25,4 +25,16 @@ export interface IPublicApiPlugins {
getPluginPreference(
pluginName: string,
): Record<string, IPublicTypePreferenceValueType> | null | undefined;

/** 获取指定插件 */
get(pluginName: string): IPublicModelPluginInstance | null;

/** 获取所有的插件实例 */
getAll(): IPublicModelPluginInstance[];

/** 判断是否有指定插件 */
has(pluginName: string): boolean;

/** 删除指定插件 */
delete(pluginName: string): void;
}
1 change: 1 addition & 0 deletions packages/types/src/shell/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './setting-target';
export * from './engine-config';
export * from './editor';
export * from './preference';
export * from './plugin-instance';
11 changes: 11 additions & 0 deletions packages/types/src/shell/model/plugin-instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IPublicTypePluginMeta } from '../type/plugin-meta';

export interface IPublicModelPluginInstance {
pluginName: string;

dep: string[];

disabled: boolean;

meta: IPublicTypePluginMeta;
}

0 comments on commit 0a24273

Please sign in to comment.