mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
feat: plugin add get\getAll\has\delete api
This commit is contained in:
parent
1f8d91f85f
commit
0a2427354b
54
docs/docs/api/model/plugin-instance.md
Normal file
54
docs/docs/api/model/plugin-instance.md
Normal file
@ -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)
|
||||||
|
|
||||||
|
|
||||||
@ -159,10 +159,51 @@ BuiltinPluginRegistry.meta = {
|
|||||||
await plugins.register(BuiltinPluginRegistry, { key1: 'abc', key5: 'willNotPassToPlugin' });
|
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)
|
- [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)
|
- [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
|
your-plugin/package.json
|
||||||
|
|||||||
@ -31,6 +31,7 @@ export interface ILowCodePluginRuntimeCore {
|
|||||||
destroy(): void;
|
destroy(): void;
|
||||||
toProxy(): any;
|
toProxy(): any;
|
||||||
setDisabled(flag: boolean): void;
|
setDisabled(flag: boolean): void;
|
||||||
|
meta: IPublicTypePluginMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ILowCodePluginRuntimeExportsAccessor {
|
interface ILowCodePluginRuntimeExportsAccessor {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export class LowCodePluginRuntime implements ILowCodePluginRuntime {
|
|||||||
|
|
||||||
private pluginName: string;
|
private pluginName: string;
|
||||||
|
|
||||||
private meta: IPublicTypePluginMeta;
|
meta: IPublicTypePluginMeta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标识插件状态,是否被 disabled
|
* 标识插件状态,是否被 disabled
|
||||||
|
|||||||
@ -4,10 +4,12 @@ import {
|
|||||||
import { globalContext } from '@alilc/lowcode-editor-core';
|
import { globalContext } from '@alilc/lowcode-editor-core';
|
||||||
import {
|
import {
|
||||||
IPublicApiPlugins,
|
IPublicApiPlugins,
|
||||||
|
IPublicModelPluginInstance,
|
||||||
IPublicTypePlugin,
|
IPublicTypePlugin,
|
||||||
IPublicTypePluginRegisterOptions,
|
IPublicTypePluginRegisterOptions,
|
||||||
IPublicTypePreferenceValueType,
|
IPublicTypePreferenceValueType,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
|
import { PluginInstance } from '../model/plugin-instance';
|
||||||
import { pluginsSymbol } from '../symbols';
|
import { pluginsSymbol } from '../symbols';
|
||||||
|
|
||||||
const innerPluginsSymbol = Symbol('plugin');
|
const innerPluginsSymbol = Symbol('plugin');
|
||||||
@ -45,6 +47,27 @@ export class Plugins implements IPublicApiPlugins {
|
|||||||
return this[pluginsSymbol].getPluginPreference(pluginName);
|
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() {
|
toProxy() {
|
||||||
return new Proxy(this, {
|
return new Proxy(this, {
|
||||||
get(target, prop, receiver) {
|
get(target, prop, receiver) {
|
||||||
|
|||||||
31
packages/shell/src/model/plugin-instance.ts
Normal file
31
packages/shell/src/model/plugin-instance.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,3 +29,4 @@ export const hotkeySymbol = Symbol('hotkey');
|
|||||||
export const pluginsSymbol = Symbol('plugins');
|
export const pluginsSymbol = Symbol('plugins');
|
||||||
export const workspaceSymbol = Symbol('workspace');
|
export const workspaceSymbol = Symbol('workspace');
|
||||||
export const windowSymbol = Symbol('window');
|
export const windowSymbol = Symbol('window');
|
||||||
|
export const pluginInstanceSymbol = Symbol('plugin-instance');
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { IPublicTypePlugin } from '../model';
|
import { IPublicModelPluginInstance, IPublicTypePlugin } from '../model';
|
||||||
import { IPublicTypePreferenceValueType } from '../type';
|
import { IPublicTypePreferenceValueType } from '../type';
|
||||||
import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options';
|
import { IPublicTypePluginRegisterOptions } from '../type/plugin-register-options';
|
||||||
|
|
||||||
@ -25,4 +25,16 @@ export interface IPublicApiPlugins {
|
|||||||
getPluginPreference(
|
getPluginPreference(
|
||||||
pluginName: string,
|
pluginName: string,
|
||||||
): Record<string, IPublicTypePreferenceValueType> | null | undefined;
|
): Record<string, IPublicTypePreferenceValueType> | null | undefined;
|
||||||
|
|
||||||
|
/** 获取指定插件 */
|
||||||
|
get(pluginName: string): IPublicModelPluginInstance | null;
|
||||||
|
|
||||||
|
/** 获取所有的插件实例 */
|
||||||
|
getAll(): IPublicModelPluginInstance[];
|
||||||
|
|
||||||
|
/** 判断是否有指定插件 */
|
||||||
|
has(pluginName: string): boolean;
|
||||||
|
|
||||||
|
/** 删除指定插件 */
|
||||||
|
delete(pluginName: string): void;
|
||||||
}
|
}
|
||||||
@ -26,3 +26,4 @@ export * from './setting-target';
|
|||||||
export * from './engine-config';
|
export * from './engine-config';
|
||||||
export * from './editor';
|
export * from './editor';
|
||||||
export * from './preference';
|
export * from './preference';
|
||||||
|
export * from './plugin-instance';
|
||||||
11
packages/types/src/shell/model/plugin-instance.ts
Normal file
11
packages/types/src/shell/model/plugin-instance.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { IPublicTypePluginMeta } from '../type/plugin-meta';
|
||||||
|
|
||||||
|
export interface IPublicModelPluginInstance {
|
||||||
|
pluginName: string;
|
||||||
|
|
||||||
|
dep: string[];
|
||||||
|
|
||||||
|
disabled: boolean;
|
||||||
|
|
||||||
|
meta: IPublicTypePluginMeta;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user