forked from alibaba/lowcode-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.tsx
More file actions
279 lines (251 loc) · 7.71 KB
/
plugin.tsx
File metadata and controls
279 lines (251 loc) · 7.71 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import React from 'react';
import {
ILowCodePluginContext,
plugins,
skeleton,
project,
setters,
} from '@alilc/lowcode-engine';
import AliLowCodeEngineExt from '@alilc/lowcode-engine-ext';
import { Button } from '@alifd/next';
import UndoRedoPlugin from '@alilc/lowcode-plugin-undo-redo';
import ComponentsPane from '@alilc/lowcode-plugin-components-pane';
import ZhEnPlugin from '@alilc/lowcode-plugin-zh-en';
import CodeGenPlugin from '@alilc/lowcode-plugin-code-generator';
import DataSourcePanePlugin from '@alilc/lowcode-plugin-datasource-pane';
import SchemaPlugin from '@alilc/lowcode-plugin-schema';
import CodeEditor from "@alilc/lowcode-plugin-code-editor";
import ManualPlugin from "@alilc/lowcode-plugin-manual";
import Inject, { injectAssets } from '@alilc/lowcode-plugin-inject';
import SimulatorResizer from '@alilc/lowcode-plugin-simulator-select';
// 注册到引擎
import TitleSetter from '@alilc/lowcode-setter-title';
import BehaviorSetter from '../setters/behavior-setter';
import CustomSetter from '../setters/custom-setter';
import Logo from '../sample-plugins/logo';
import { deleteHiddenTransducer } from '../sample-plugins/delete-hidden-transducer';
import {
loadIncrementalAssets,
getPageSchema,
saveSchema,
resetSchema,
preview,
} from './utils';
import assets from './assets.json'
import { registerRefProp } from 'src/sample-plugins/set-ref-prop';
export default async function registerPlugins() {
await plugins.register(ManualPlugin);
await plugins.register(Inject);
await plugins.register(registerRefProp);
await plugins.register(deleteHiddenTransducer);
// plugin API 见 https://yuque.antfin.com/ali-lowcode/docs/cdukce
SchemaPlugin.pluginName = 'SchemaPlugin';
await plugins.register(SchemaPlugin);
SimulatorResizer.pluginName = 'SimulatorResizer';
plugins.register(SimulatorResizer);
const editorInit = (ctx: ILowCodePluginContext) => {
return {
name: 'editor-init',
async init() {
// 修改面包屑组件的分隔符属性setter
// const assets = await (
// await fetch(
// `https://alifd.alicdn.com/npm/@alilc/lowcode-materials/build/lowcode/assets-prod.json`
// )
// ).json();
// 设置物料描述
const { material, project } = ctx;
await material.setAssets(await injectAssets(assets));
const schema = await getPageSchema();
// 加载 schema
project.openDocument(schema);
},
};
}
editorInit.pluginName = 'editorInit';
await plugins.register(editorInit);
const builtinPluginRegistry = (ctx: ILowCodePluginContext) => {
return {
name: 'builtin-plugin-registry',
async init() {
const { skeleton } = ctx;
// 注册 logo 面板
skeleton.add({
area: 'topArea',
type: 'Widget',
name: 'logo',
content: Logo,
contentProps: {
logo: 'https://img.alicdn.com/imgextra/i4/O1CN013w2bmQ25WAIha4Hx9_!!6000000007533-55-tps-137-26.svg',
href: 'https://lowcode-engine.cn',
},
props: {
align: 'left',
},
});
// 注册组件面板
const componentsPane = skeleton.add({
area: 'leftArea',
type: 'PanelDock',
name: 'componentsPane',
content: ComponentsPane,
contentProps: {},
props: {
align: 'top',
icon: 'zujianku',
description: '组件库',
},
});
componentsPane?.disable?.();
project.onSimulatorRendererReady(() => {
componentsPane?.enable?.();
})
},
};
}
builtinPluginRegistry.pluginName = 'builtinPluginRegistry';
await plugins.register(builtinPluginRegistry);
// 设置内置 setter 和事件绑定、插件绑定面板
const setterRegistry = (ctx: ILowCodePluginContext) => {
const { setterMap, pluginMap } = AliLowCodeEngineExt;
return {
name: 'ext-setters-registry',
async init() {
const { setters, skeleton } = ctx;
// 注册setterMap
setters.registerSetter(setterMap);
// 注册插件
// 注册事件绑定面板
skeleton.add({
area: 'centerArea',
type: 'Widget',
content: pluginMap.EventBindDialog,
name: 'eventBindDialog',
props: {},
});
// 注册变量绑定面板
skeleton.add({
area: 'centerArea',
type: 'Widget',
content: pluginMap.VariableBindDialog,
name: 'variableBindDialog',
props: {},
});
},
};
}
setterRegistry.pluginName = 'setterRegistry';
await plugins.register(setterRegistry);
// 注册回退/前进
await plugins.register(UndoRedoPlugin);
// 注册中英文切换
await plugins.register(ZhEnPlugin);
const loadAssetsSample = (ctx: ILowCodePluginContext) => {
return {
name: 'loadAssetsSample',
async init() {
const { skeleton } = ctx;
skeleton.add({
name: 'loadAssetsSample',
area: 'topArea',
type: 'Widget',
props: {
align: 'right',
width: 80,
},
content: (
<Button onClick={loadIncrementalAssets}>
异步加载资源
</Button>
),
});
},
};
};
loadAssetsSample.pluginName = 'loadAssetsSample';
await plugins.register(loadAssetsSample);
// 注册保存面板
const saveSample = (ctx: ILowCodePluginContext) => {
return {
name: 'saveSample',
async init() {
const { skeleton, hotkey } = ctx;
skeleton.add({
name: 'saveSample',
area: 'topArea',
type: 'Widget',
props: {
align: 'right',
},
content: (
<Button onClick={() => saveSchema()}>
保存到本地
</Button>
),
});
skeleton.add({
name: 'resetSchema',
area: 'topArea',
type: 'Widget',
props: {
align: 'right',
},
content: (
<Button onClick={() => resetSchema()}>
重置页面
</Button>
),
});
hotkey.bind('command+s', (e) => {
e.preventDefault();
saveSchema();
});
},
};
}
saveSample.pluginName = 'saveSample';
await plugins.register(saveSample);
DataSourcePanePlugin.pluginName = 'DataSourcePane';
await plugins.register(DataSourcePanePlugin);
CodeEditor.pluginName = 'CodeEditor';
await plugins.register(CodeEditor);
// 注册出码插件
CodeGenPlugin.pluginName = 'CodeGenPlugin';
await plugins.register(CodeGenPlugin);
const previewSample = (ctx: ILowCodePluginContext) => {
return {
name: 'previewSample',
async init() {
const { skeleton } = ctx;
skeleton.add({
name: 'previewSample',
area: 'topArea',
type: 'Widget',
props: {
align: 'right',
},
content: (
<Button type="primary" onClick={() => preview()}>
预览
</Button>
),
});
},
};
};
previewSample.pluginName = 'previewSample';
await plugins.register(previewSample);
const customSetter = (ctx: ILowCodePluginContext) => {
return {
name: '___registerCustomSetter___',
async init() {
const { setters } = ctx;
setters.registerSetter('TitleSetter', TitleSetter);
setters.registerSetter('BehaviorSetter', BehaviorSetter);
setters.registerSetter('CustomSetter', CustomSetter);
},
};
}
customSetter.pluginName = 'customSetter';
await plugins.register(customSetter);
};