forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.ts
More file actions
475 lines (453 loc) · 10 KB
/
metadata.ts
File metadata and controls
475 lines (453 loc) · 10 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
import { ReactNode, ComponentType, ReactElement } from 'react';
import { IconType } from './icon';
import { TipContent } from './tip';
import { TitleContent } from './title';
import { PropConfig, PropType } from './prop-config';
import { NpmInfo } from './npm';
import { FieldConfig } from './field-config';
import { NodeSchema, NodeData, ComponentSchema } from './schema';
import { SettingTarget } from './setting-target';
import { I18nData } from './i18n';
/**
* 嵌套控制函数
*/
export type NestingFilter = (testNode: any, currentNode: any) => boolean;
/**
* 嵌套控制
* 防止错误的节点嵌套,比如 a 嵌套 a, FormField 只能在 Form 容器下,Column 只能在 Table 下等
*/
export interface NestingRule {
/**
* 子级白名单
*/
childWhitelist?: string[] | string | RegExp | NestingFilter;
/**
* 父级白名单
*/
parentWhitelist?: string[] | string | RegExp | NestingFilter;
/**
* 后裔白名单
*/
descendantWhitelist?: string[] | string | RegExp | NestingFilter;
/**
* 后裔黑名单
*/
descendantBlacklist?: string[] | string | RegExp | NestingFilter;
/**
* 祖先白名单 可用来做区域高亮
*/
ancestorWhitelist?: string[] | string | RegExp | NestingFilter;
}
/**
* 组件能力配置
*/
export interface ComponentConfigure {
/**
* 是否容器组件
*/
isContainer?: boolean;
/**
* 组件是否带浮层,浮层组件拖入设计器时会遮挡画布区域,此时应当辅助一些交互以防止阻挡
*/
isModal?: boolean;
/**
* 是否存在渲染的根节点
*/
isNullNode?: boolean;
/**
* 组件树描述信息
*/
descriptor?: string;
/**
* 嵌套控制:防止错误的节点嵌套
* 比如 a 嵌套 a, FormField 只能在 Form 容器下,Column 只能在 Table 下等
*/
nestingRule?: NestingRule;
/**
* 是否是最小渲染单元
* 最小渲染单元下的组件渲染和更新都从单元的根节点开始渲染和更新。如果嵌套了多层最小渲染单元,渲染会从最外层的最小渲染单元开始渲染。
*/
isMinimalRenderUnit?: boolean;
/**
* 组件选中框的 cssSelector
*/
rootSelector?: string;
/**
* 禁用的行为,可以为 `'copy'`, `'move'`, `'remove'` 或它们组成的数组
*/
disableBehaviors?: string[] | string;
/**
* 用于详细配置上述操作项的内容
*/
actions?: ComponentAction[];
}
/**
* 可用片段
*
* 内容为组件不同状态下的低代码 schema (可以有多个),用户从组件面板拖入组件到设计器时会向页面 schema 中插入 snippets 中定义的组件低代码 schema
*/
export interface Snippet {
/**
* 组件分类title
*/
title?: string;
/**
* snippet 截图
*/
screenshot?: string;
/**
* snippet 打标
*
* @deprecated 暂未使用
*/
label?: string;
/**
* 待插入的 schema
*/
schema?: NodeSchema;
}
export interface InitialItem {
name: string;
initial: (target: SettingTarget, currentValue: any) => any;
}
export interface FilterItem {
name: string;
filter: (target: SettingTarget | null, currentValue: any) => any;
}
export interface AutorunItem {
name: string;
autorun: (target: SettingTarget) => any;
}
/**
* 高级特性配置
*/
export interface Advanced {
/**
* @todo 待补充文档
*/
context?: { [contextInfoName: string]: any };
/**
* @deprecated 使用组件 metadata 上的 snippets 字段即可
*/
snippets?: Snippet[];
/**
* @todo 待补充文档
*/
view?: ComponentType<any>;
/**
* @todo 待补充文档
*/
transducers?: any;
/**
* @deprecated 用于动态初始化拖拽到设计器里的组件的 prop 的值
*/
initials?: InitialItem[];
/**
* @todo 待补充文档
*/
filters?: FilterItem[];
/**
* @todo 待补充文档
*/
autoruns?: AutorunItem[];
/**
* 配置 callbacks 可捕获引擎抛出的一些事件,例如 onNodeAdd、onResize 等
*/
callbacks?: Callbacks;
/**
* 拖入容器时,自动带入 children 列表
*/
initialChildren?: NodeData[] | ((target: SettingTarget) => NodeData[]);
/**
* @todo 待补充文档
*/
isAbsoluteLayoutContainer?: boolean;
/**
* @todo 待补充文档
*/
hideSelectTools?: boolean;
/**
* 样式 及 位置,handle上必须有明确的标识以便事件路由判断,或者主动设置事件独占模式
* NWSE 是交给引擎计算放置位置,ReactElement 必须自己控制初始位置
*/
/**
* 用于配置设计器中组件 resize 操作工具的样式和内容
* - hover 时控制柄高亮
* - mousedown 时请求独占
* - dragstart 请求通用 resizing 控制 请求 hud 显示
* - drag 时 计算并设置效果,更新控制柄位置
*/
getResizingHandlers?: (
currentNode: any,
) => (
| Array<{
type: 'N' | 'W' | 'S' | 'E' | 'NW' | 'NE' | 'SE' | 'SW';
content?: ReactElement;
propTarget?: string;
appearOn?: 'mouse-enter' | 'mouse-hover' | 'selected' | 'always';
}>
| ReactElement[]
);
/**
* Live Text Editing:如果 children 内容是纯文本,支持双击直接编辑
*/
liveTextEditing?: LiveTextEditingConfig[];
/**
* @deprecated 暂未使用
*/
isTopFixed?: boolean;
}
// thinkof Array
/**
* Live Text Editing(如果 children 内容是纯文本,支持双击直接编辑)的可配置项目
*/
export interface LiveTextEditingConfig {
/**
* @todo 待补充文档
*/
propTarget: string;
/**
* @todo 待补充文档
*/
selector?: string;
/**
* 编辑模式 纯文本|段落编辑|文章编辑(默认纯文本,无跟随工具条)
* @default 'plaintext'
*/
mode?: 'plaintext' | 'paragraph' | 'article';
/**
* 从 contentEditable 获取内容并设置到属性
*/
onSaveContent?: (content: string, prop: any) => any;
}
export type ConfigureSupportEvent = string | {
name: string;
propType?: PropType;
description?: string;
};
/**
* 通用扩展面板支持性配置
*/
export interface ConfigureSupport {
/**
* 支持事件列表
*/
events?: ConfigureSupportEvent[];
/**
* 支持 className 设置
*/
className?: boolean;
/**
* 支持样式设置
*/
style?: boolean;
/**
* 支持生命周期设置
*/
lifecycles?: any[];
// general?: boolean;
/**
* 支持循环设置
*/
loop?: boolean;
/**
* 支持条件式渲染设置
*/
condition?: boolean;
}
/**
* 编辑体验配置
*/
export interface Configure {
/**
* 属性面板配置
*/
props?: FieldConfig[];
/**
* 组件能力配置
*/
component?: ComponentConfigure;
/**
* 通用扩展面板支持性配置
*/
supports?: ConfigureSupport;
/**
* 高级特性配置
*/
advanced?: Advanced;
}
/**
* 动作描述
*/
export interface ActionContentObject {
/**
* 图标
*/
icon?: IconType;
/**
* 描述
*/
title?: TipContent;
/**
* 执行动作
*/
action?: (currentNode: any) => void;
}
/**
* @todo 工具条动作
*/
export interface ComponentAction {
/**
* behaviorName
*/
name: string;
/**
* 菜单名称
*/
content: string | ReactNode | ActionContentObject;
/**
* 子集
*/
items?: ComponentAction[];
/**
* 显示与否
* always: 无法禁用
*/
condition?: boolean | ((currentNode: any) => boolean) | 'always';
/**
* 显示在工具条上
*/
important?: boolean;
}
export function isActionContentObject(obj: any): obj is ActionContentObject {
return obj && typeof obj === 'object';
}
/**
* 组件 meta 配置
*/
export interface ComponentMetadata {
/**
* 组件名
*/
componentName: string;
/**
* unique id
*/
uri?: string;
/**
* title or description
*/
title?: TitleContent;
/**
* svg icon for component
*/
icon?: IconType;
/**
* 组件标签
*/
tags?: string[];
/**
* 组件描述
*/
description?: string;
/**
* 组件文档链接
*/
docUrl?: string;
/**
* 组件快照
*/
screenshot?: string;
/**
* 组件研发模式
*/
devMode?: 'procode' | 'lowcode';
/**
* npm 源引入完整描述对象
*/
npm?: NpmInfo;
/**
* 组件属性信息
*/
props?: PropConfig[];
/**
* 编辑体验增强
*/
configure?: FieldConfig[] | Configure;
/**
* @deprecated, use advanced instead
*/
experimental?: Advanced;
/**
* @todo 待补充文档
*/
schema?: ComponentSchema;
/**
* 可用片段
*/
snippets?: Snippet[];
/**
* 一级分组
*/
group?: string | I18nData;
/**
* 二级分组
*/
category?: string | I18nData;
/**
* 组件优先级排序
*/
priority?: number;
}
/**
* @todo 待补充文档
*/
export interface TransformedComponentMetadata extends ComponentMetadata {
configure: Configure & { combined?: FieldConfig[] };
}
/**
* handleResizing
*/
/**
* 配置 callbacks 可捕获引擎抛出的一些事件,例如 onNodeAdd、onResize 等
*/
export interface Callbacks {
// hooks
onMouseDownHook?: (e: MouseEvent, currentNode: any) => any;
onDblClickHook?: (e: MouseEvent, currentNode: any) => any;
onClickHook?: (e: MouseEvent, currentNode: any) => any;
// onLocateHook?: (e: any, currentNode: any) => any;
// onAcceptHook?: (currentNode: any, locationData: any) => any;
onMoveHook?: (currentNode: any) => boolean;
// thinkof 限制性拖拽
onHoverHook?: (currentNode: any) => boolean;
onChildMoveHook?: (childNode: any, currentNode: any) => boolean;
// events
onNodeRemove?: (removedNode: any, currentNode: any) => void;
onNodeAdd?: (addedNode: any, currentNode: any) => void;
onSubtreeModified?: (currentNode: any, options: any) => void;
onResize?: (
e: MouseEvent & {
trigger: string;
deltaX?: number;
deltaY?: number;
},
currentNode: any,
) => void;
onResizeStart?: (
e: MouseEvent & {
trigger: string;
deltaX?: number;
deltaY?: number;
},
currentNode: any,
) => void;
onResizeEnd?: (
e: MouseEvent & {
trigger: string;
deltaX?: number;
deltaY?: number;
},
currentNode: any,
) => void;
}