forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-types.ts
More file actions
146 lines (128 loc) · 4.44 KB
/
plugin-types.ts
File metadata and controls
146 lines (128 loc) · 4.44 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { CompositeObject, ComponentAction } from '@alilc/lowcode-types';
import Logger from 'zen-logger';
import {
Hotkey,
Skeleton,
Project,
Event, Material,
} from '@alilc/lowcode-shell';
import { EngineConfig } from '@alilc/lowcode-editor-core';
import { MetadataTransducer } from '@alilc/lowcode-designer';
import { Setters } from '../types';
export type PreferenceValueType = string | number | boolean;
export interface ILowCodePluginPreferenceDeclarationProperty {
// shape like 'name' or 'group.name' or 'group.subGroup.name'
key: string;
// must have either one of description & markdownDescription
description: string;
// value in 'number', 'string', 'boolean'
type: string;
// default value
// NOTE! this is only used in configuration UI, won`t affect runtime
default?: PreferenceValueType;
// only works when type === 'string', default value false
useMultipleLineTextInput?: boolean;
// enum values, only works when type === 'string'
enum?: any[];
// descriptions for enum values
enumDescriptions?: string[];
// message that describing deprecation of this property
deprecationMessage?: string;
}
/**
* declaration of plugin`s preference
* when strictPluginMode === true, only declared preference can be obtained from inside plugin.
*
* @export
* @interface ILowCodePluginPreferenceDeclaration
*/
export interface ILowCodePluginPreferenceDeclaration {
// this will be displayed on configuration UI, can be plugin name
title: string;
properties: ILowCodePluginPreferenceDeclarationProperty[];
}
export type PluginPreference = Map<string, Record<string, PreferenceValueType>>;
export interface ILowCodePluginConfig {
dep?: string | string[];
init?(): void;
destroy?(): void;
exports?(): any;
}
export interface ILowCodePluginConfigMetaEngineConfig {
lowcodeEngine?: string;
}
export interface ILowCodePluginConfigMeta {
preferenceDeclaration?: ILowCodePluginPreferenceDeclaration;
// 依赖插件名
dependencies?: string[];
engines?: ILowCodePluginConfigMetaEngineConfig;
}
export interface ILowCodePluginCore {
name: string;
dep: string[];
disabled: boolean;
config: ILowCodePluginConfig;
logger: Logger;
on(event: string | symbol, listener: (...args: any[]) => void): any;
emit(event: string | symbol, ...args: any[]): boolean;
removeAllListeners(event?: string | symbol): this;
init(forceInit?: boolean): void;
isInited(): boolean;
destroy(): void;
toProxy(): any;
setDisabled(flag: boolean): void;
}
interface ILowCodePluginExportsAccessor {
[propName: string]: any;
}
export type ILowCodePlugin = ILowCodePluginCore & ILowCodePluginExportsAccessor;
export interface IDesignerCabin {
registerMetadataTransducer: (transducer: MetadataTransducer, level: number, id?: string) => void;
addBuiltinComponentAction: (action: ComponentAction) => void;
removeBuiltinComponentAction: (actionName: string) => void;
}
export interface IPluginPreferenceMananger {
// eslint-disable-next-line max-len
getPreferenceValue: (key: string, defaultValue?: PreferenceValueType) => PreferenceValueType | undefined ;
}
export interface ILowCodePluginContext {
skeleton: Skeleton;
hotkey: Hotkey;
logger: Logger;
plugins: ILowCodePluginManager;
setters: Setters;
config: EngineConfig;
material: Material;
event: Event;
project: Project;
preference: IPluginPreferenceMananger;
}
interface ILowCodePluginManagerPluginAccessor {
[pluginName: string]: ILowCodePlugin | any;
}
export interface ILowCodePluginManagerCore {
register(
pluginConfigCreator: (ctx: ILowCodePluginContext, pluginOptions?: any) => ILowCodePluginConfig,
pluginOptions?: any,
options?: CompositeObject,
): Promise<void>;
init(pluginPreference?: Map<string, Record<string, PreferenceValueType>>): Promise<void>;
get(pluginName: string): ILowCodePlugin | undefined;
getAll(): ILowCodePlugin[];
has(pluginName: string): boolean;
delete(pluginName: string): any;
setDisabled(pluginName: string, flag: boolean): void;
dispose(): void;
}
export type ILowCodePluginManager = ILowCodePluginManagerCore & ILowCodePluginManagerPluginAccessor;
export function isLowCodeRegisterOptions(opts: any): opts is ILowCodeRegisterOptions {
return opts && ('autoInit' in opts || 'override' in opts);
}
export interface ILowCodeRegisterOptions {
autoInit?: boolean;
// allow overriding existing plugin with same name when override === true
override?: boolean;
}
export interface IPluginContextOptions {
pluginName: string;
}