forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.ts
More file actions
88 lines (76 loc) · 2.45 KB
/
plugins.ts
File metadata and controls
88 lines (76 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {
LowCodePluginManager,
} from '@alilc/lowcode-designer';
import { globalContext } from '@alilc/lowcode-editor-core';
import {
IPublicApiPlugins,
IPublicModelPluginInstance,
IPublicTypePlugin,
IPublicTypePluginRegisterOptions,
IPublicTypePreferenceValueType,
} from '@alilc/lowcode-types';
import { PluginInstance as ShellPluginInstance } from '../model';
import { pluginsSymbol } from '../symbols';
const innerPluginsSymbol = Symbol('plugin');
export class Plugins implements IPublicApiPlugins {
private readonly [innerPluginsSymbol]: LowCodePluginManager;
get [pluginsSymbol](): LowCodePluginManager {
if (this.workspaceMode) {
return this[innerPluginsSymbol];
}
const workspace = globalContext.get('workspace');
if (workspace.isActive) {
return workspace.window.innerPlugins;
}
return this[innerPluginsSymbol];
}
constructor(plugins: LowCodePluginManager, public workspaceMode: boolean = false) {
this[innerPluginsSymbol] = plugins;
}
async register(
pluginModel: IPublicTypePlugin,
options?: any,
registerOptions?: IPublicTypePluginRegisterOptions,
): Promise<void> {
await this[pluginsSymbol].register(pluginModel, options, registerOptions);
}
async init(registerOptions: any) {
await this[pluginsSymbol].init(registerOptions);
}
getPluginPreference(
pluginName: string,
): Record<string, IPublicTypePreferenceValueType> | null | undefined {
return this[pluginsSymbol].getPluginPreference(pluginName);
}
get(pluginName: string): IPublicModelPluginInstance | null {
const instance = this[pluginsSymbol].get(pluginName);
if (instance) {
return new ShellPluginInstance(instance);
}
return null;
}
getAll() {
return this[pluginsSymbol].getAll()?.map((d) => new ShellPluginInstance(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) {
const _target = target[pluginsSymbol];
if (_target.pluginsMap.has(prop as string)) {
// 禁用态的插件,直接返回 undefined
if (_target.pluginsMap.get(prop as string)!.disabled) {
return undefined;
}
return _target.pluginsMap.get(prop as string)?.toProxy();
}
return Reflect.get(target, prop, receiver);
},
});
}
}