Skip to content

Commit 9d83b8b

Browse files
JackLianliujuping
authored andcommitted
docs: improve doc for plugin related apis
1 parent 36d1d3b commit 9d83b8b

File tree

6 files changed

+98
-28
lines changed

6 files changed

+98
-28
lines changed

docs/docs/api/plugins.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ import { IPublicModelPluginContext } from '@alilc/lowcode-types';
118118
const BuiltinPluginRegistry = (ctx: IPublicModelPluginContext, options: any) => {
119119
return {
120120
async init() {
121-
// 1.0.4 之后的传值方式,通过 register(xxx, options)
122-
// 取值通过 options
121+
// 直接传值方式:
122+
// 通过 register(xxx, options) 传入
123+
// 通过 options 取出
123124
124-
// 1.0.4 之前的传值方式,通过 init(..., preference)
125-
// 取值通过 ctx.preference.getValue()
125+
// 引擎初始化时也可以设置某插件的全局配置项:
126+
// 通过 engine.init(..., preference) 传入
127+
// 通过 ctx.preference.getValue() 取出
126128
},
127129
};
128130
}
@@ -155,7 +157,6 @@ BuiltinPluginRegistry.meta = {
155157
},
156158
}
157159
158-
// 从 1.0.4 开始,支持直接在 pluginCreator 的第二个参数 options 获取入参
159160
await plugins.register(BuiltinPluginRegistry, { key1: 'abc', key5: 'willNotPassToPlugin' });
160161
```
161162

@@ -164,8 +165,11 @@ await plugins.register(BuiltinPluginRegistry, { key1: 'abc', key5: 'willNotPassT
164165
获取指定插件
165166

166167
```typescript
167-
function get(pluginName: string): IPublicModelPluginInstance;
168-
168+
/**
169+
* 获取指定插件
170+
* get plugin instance by name
171+
*/
172+
get(pluginName: string): IPublicModelPluginInstance | null;
169173
```
170174

171175
关联模型 [IPublicModelPluginInstance](./model/plugin-instance)
@@ -175,8 +179,11 @@ function get(pluginName: string): IPublicModelPluginInstance;
175179
获取所有的插件实例
176180

177181
```typescript
178-
function getAll(): IPublicModelPluginInstance[];
179-
182+
/**
183+
* 获取所有的插件实例
184+
* get all plugin instances
185+
*/
186+
getAll(): IPublicModelPluginInstance[];
180187
```
181188

182189
关联模型 [IPublicModelPluginInstance](./model/plugin-instance)
@@ -186,17 +193,37 @@ function getAll(): IPublicModelPluginInstance[];
186193
判断是否有指定插件
187194

188195
```typescript
189-
function has(pluginName: string): boolean;
190-
196+
/**
197+
* 判断是否有指定插件
198+
* check if plugin with certain name exists
199+
*/
200+
has(pluginName: string): boolean;
191201
```
192202

193203
### delete
194204

195205
删除指定插件
196206

197207
```typescript
198-
function delete(pluginName: string): void;
208+
/**
209+
* 删除指定插件
210+
* delete plugin instance by name
211+
*/
212+
delete(pluginName: string): void;
213+
```
199214

215+
### getPluginPreference
216+
217+
引擎初始化时可以提供全局配置给到各插件,通过这个方法可以获得本插件对应的配置
218+
219+
```typescript
220+
/**
221+
* 引擎初始化时可以提供全局配置给到各插件,通过这个方法可以获得本插件对应的配置
222+
* use this to get preference config for this plugin when engine.init() called
223+
*/
224+
getPluginPreference(
225+
pluginName: string,
226+
): Record<string, IPublicTypePreferenceValueType> | null | undefined;
200227
```
201228

202229
## 相关类型定义

packages/designer/src/plugin/plugin-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export interface ILowCodePluginRuntimeCore {
2626
disabled: boolean;
2727
config: IPublicTypePluginConfig;
2828
logger: IPublicApiLogger;
29+
meta: IPublicTypePluginMeta;
2930
init(forceInit?: boolean): void;
3031
isInited(): boolean;
3132
destroy(): void;
3233
toProxy(): any;
3334
setDisabled(flag: boolean): void;
34-
meta: IPublicTypePluginMeta;
3535
}
3636

3737
interface ILowCodePluginRuntimeExportsAccessor {

packages/shell/src/model/plugin-instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ export class PluginInstance implements IPublicModelPluginInstance {
2828
get meta() {
2929
return this[pluginInstanceSymbol].meta;
3030
}
31-
}
31+
}

packages/types/src/shell/api/plugins.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,34 @@ export interface IPublicApiPlugins {
2020
): Promise<void>;
2121

2222
/**
23-
* @deprecated use options instead
23+
* 引擎初始化时可以提供全局配置给到各插件,通过这个方法可以获得本插件对应的配置
24+
* use this to get preference config for this plugin when engine.init() called
2425
*/
2526
getPluginPreference(
2627
pluginName: string,
2728
): Record<string, IPublicTypePreferenceValueType> | null | undefined;
2829

29-
/** 获取指定插件 */
30+
/**
31+
* 获取指定插件
32+
* get plugin instance by name
33+
*/
3034
get(pluginName: string): IPublicModelPluginInstance | null;
3135

32-
/** 获取所有的插件实例 */
36+
/**
37+
* 获取所有的插件实例
38+
* get all plugin instances
39+
*/
3340
getAll(): IPublicModelPluginInstance[];
3441

35-
/** 判断是否有指定插件 */
42+
/**
43+
* 判断是否有指定插件
44+
* check if plugin with certain name exists
45+
*/
3646
has(pluginName: string): boolean;
3747

38-
/** 删除指定插件 */
48+
/**
49+
* 删除指定插件
50+
* delete plugin instance by name
51+
*/
3952
delete(pluginName: string): void;
40-
}
53+
}

packages/types/src/shell/model/plugin-context.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,26 @@ import {
1414
import { IPublicModelEngineConfig } from './';
1515

1616
export interface IPublicModelPluginContext {
17+
18+
/**
19+
* 对于插件开发者来说,可以在 context 挂载自定义的内容,作为插件内全局上下文使用
20+
*
21+
* for plugin developers, costom properties can be add to plugin context
22+
* from inside plugin for convenience.
23+
*/
24+
[key: string]: any;
25+
26+
/**
27+
* 可通过该对象读取插件初始化配置
28+
* by using this, init options can be accessed from inside plugin
29+
*/
30+
preference: IPluginPreferenceMananger;
1731
get skeleton(): IPublicApiSkeleton;
1832
get hotkey(): IPublicApiHotkey;
1933
get setters(): IPublicApiSetters;
2034
get config(): IPublicModelEngineConfig;
2135
get material(): IPublicApiMaterial;
36+
2237
/**
2338
* this event works globally, can be used between plugins and engine.
2439
*/
@@ -33,8 +48,6 @@ export interface IPublicModelPluginContext {
3348
*/
3449
get pluginEvent(): IPublicApiEvent;
3550
get canvas(): IPublicApiCanvas;
36-
preference: IPluginPreferenceMananger;
37-
[key: string]: any;
3851
}
3952

4053
/**
@@ -44,4 +57,4 @@ export interface IPublicModelPluginContext {
4457
*/
4558
export interface ILowCodePluginContext extends IPublicModelPluginContext {
4659

47-
}
60+
}
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
import { IPublicTypePluginMeta } from '../type/plugin-meta';
22

33
export interface IPublicModelPluginInstance {
4-
pluginName: string;
5-
6-
dep: string[];
74

5+
/**
6+
* 是否 disable
7+
* current plugin instance is disabled or not
8+
*/
89
disabled: boolean;
910

10-
meta: IPublicTypePluginMeta;
11-
}
11+
/**
12+
* 插件名称
13+
* plugin name
14+
*/
15+
get pluginName(): string;
16+
17+
/**
18+
* 依赖信息,依赖的其他插件
19+
* depenency info
20+
*/
21+
get dep(): string[];
22+
23+
/**
24+
* 插件配置元数据
25+
* meta info of this plugin
26+
*/
27+
get meta(): IPublicTypePluginMeta;
28+
}

0 commit comments

Comments
 (0)