forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.ts
More file actions
495 lines (423 loc) · 10.9 KB
/
node.ts
File metadata and controls
495 lines (423 loc) · 10.9 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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
import { ReactElement } from 'react';
import { IPublicTypeNodeSchema, IPublicTypeIconType, IPublicTypeI18nData, IPublicTypeCompositeValue, IPublicTypePropsMap, IPublicTypePropsList } from '../type';
import { IPublicEnumTransformStage } from '../enum';
import { IPublicModelNodeChildren, IPublicModelComponentMeta, IPublicModelProp, IPublicModelProps, IPublicModelSettingTopEntry, IPublicModelDocumentModel, IPublicModelExclusiveGroup } from './';
export interface IBaseModelNode<
Document = IPublicModelDocumentModel,
Node = IPublicModelNode,
NodeChildren = IPublicModelNodeChildren,
ComponentMeta = IPublicModelComponentMeta,
SettingTopEntry = IPublicModelSettingTopEntry,
Props = IPublicModelProps,
Prop = IPublicModelProp,
ExclusiveGroup = IPublicModelExclusiveGroup
> {
/**
* 节点 id
* node id
*/
id: string;
/**
* 节点标题
* title of node
*/
get title(): string | IPublicTypeI18nData | ReactElement;
/**
* @deprecated please use isContainerNode
*/
get isContainer(): boolean;
/**
* 是否为「容器型」节点
* check if node is a container type node
* @since v1.1.0
*/
get isContainerNode(): boolean;
/**
* @deprecated please use isRootNode
*/
get isRoot(): boolean;
/**
* 是否为根节点
* check if node is root in the tree
* @since v1.1.0
*/
get isRootNode(): boolean;
/**
* @deprecated please use isEmptyNode
*/
get isEmpty(): boolean;
/**
* 是否为空节点(无 children 或者 children 为空)
* check if current node is empty, which means no children or children is empty
* @since v1.1.0
*/
get isEmptyNode(): boolean;
/**
* @deprecated please use isPageNode
* 是否为 Page 节点
*/
get isPage(): boolean;
/**
* 是否为 Page 节点
* check if node is Page
* @since v1.1.0
*/
get isPageNode(): boolean;
/**
* @deprecated please use isComponentNode
*/
get isComponent(): boolean;
/**
* 是否为 Component 节点
* check if node is Component
* @since v1.1.0
*/
get isComponentNode(): boolean;
/**
* @deprecated please use isModalNode
*/
get isModal(): boolean;
/**
* 是否为「模态框」节点
* check if node is Modal
* @since v1.1.0
*/
get isModalNode(): boolean;
/**
* @deprecated please use isSlotNode
*/
get isSlot(): boolean;
/**
* 是否为插槽节点
* check if node is a Slot
* @since v1.1.0
*/
get isSlotNode(): boolean;
/**
* @deprecated please use isParentalNode
*/
get isParental(): boolean;
/**
* 是否为父类/分支节点
* check if node a parental node
* @since v1.1.0
*/
get isParentalNode(): boolean;
/**
* @deprecated please use isLeafNode
*/
get isLeaf(): boolean;
/**
* 是否为叶子节点
* check if node is a leaf node in tree
* @since v1.1.0
*/
get isLeafNode(): boolean;
/**
* 获取当前节点的锁定状态
* check if current node is locked
* @since v1.0.16
*/
get isLocked(): boolean;
/**
* @deprecated please use isRGLContainerNode
*/
set isRGLContainer(flag: boolean);
/**
* @deprecated please use isRGLContainerNode
* @returns Boolean
*/
get isRGLContainer();
/**
* 设置为磁贴布局节点
* @since v1.1.0
*/
set isRGLContainerNode(flag: boolean);
/**
* 获取磁贴布局节点设置状态
* @returns Boolean
* @since v1.1.0
*/
get isRGLContainerNode();
/**
* 下标
* index
*/
get index(): number | undefined;
/**
* 图标
* get icon of this node
*/
get icon(): IPublicTypeIconType;
/**
* 节点所在树的层级深度,根节点深度为 0
* depth level of this node, value of root node is 0
*/
get zLevel(): number;
/**
* 节点 componentName
* componentName
*/
get componentName(): string;
/**
* 节点的物料元数据
* get component meta of this node
*/
get componentMeta(): ComponentMeta | null;
/**
* 获取节点所属的文档模型对象
* get documentModel of this node
*/
get document(): Document | null;
/**
* 获取当前节点的前一个兄弟节点
* get previous sibling of this node
*/
get prevSibling(): Node | null | undefined;
/**
* 获取当前节点的后一个兄弟节点
* get next sibling of this node
*/
get nextSibling(): Node | null | undefined;
/**
* 获取当前节点的父亲节点
* get parent of this node
*/
get parent(): Node | null;
/**
* 获取当前节点的孩子节点模型
* get children of this node
*/
get children(): NodeChildren | null;
/**
* 节点上挂载的插槽节点们
* get slots of this node
*/
get slots(): Node[];
/**
* 当前节点为插槽节点时,返回节点对应的属性实例
* return coresponding prop when this node is a slot node
*/
get slotFor(): Prop | null | undefined;
/**
* 返回节点的属性集
* get props
*/
get props(): Props | null;
/**
* 返回节点的属性集
* get props data
*/
get propsData(): IPublicTypePropsMap | IPublicTypePropsList | null;
/**
* get conditionGroup
*/
get conditionGroup(): ExclusiveGroup | null;
/**
* 获取符合搭建协议 - 节点 schema 结构
* get schema of this node
* @since v1.1.0
*/
get schema(): IPublicTypeNodeSchema;
/**
* 获取对应的 setting entry
* get setting entry of this node
* @since v1.1.0
*/
get settingEntry(): SettingTopEntry;
/**
* 返回节点的尺寸、位置信息
* get rect information for this node
*/
getRect(): DOMRect | null;
/**
* 是否有挂载插槽节点
* check if current node has slots
*/
hasSlots(): boolean;
/**
* 是否设定了渲染条件
* check if current node has condition value set
*/
hasCondition(): boolean;
/**
* 是否设定了循环数据
* check if loop is set for this node
*/
hasLoop(): boolean;
/**
* 获取指定 path 的属性模型实例
* get prop by path
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param createIfNone 如果不存在,是否新建,默认为 true
*/
getProp(path: string | number, createIfNone?: boolean): Prop | null;
/**
* 获取指定 path 的属性模型实例值
* get prop value by path
* @param path 属性路径,支持 a / a.b / a.0 等格式
*/
getPropValue(path: string): any;
/**
* 获取指定 path 的属性模型实例,
* 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级
*
* get extra prop by path, an extra prop means a prop not exists in the `props`
* but as siblint of the `props`
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param createIfNone 当没有属性的时候,是否创建一个属性
*/
getExtraProp(path: string, createIfNone?: boolean): Prop | null;
/**
* 获取指定 path 的属性模型实例,
* 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级
*
* get extra prop value by path, an extra prop means a prop not exists in the `props`
* but as siblint of the `props`
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getExtraPropValue(path: string): any;
/**
* 设置指定 path 的属性模型实例值
* set value for prop with path
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param value 值
*/
setPropValue(path: string | number, value: IPublicTypeCompositeValue): void;
/**
* 设置指定 path 的属性模型实例值
* set value for extra prop with path
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param value 值
*/
setExtraPropValue(path: string, value: IPublicTypeCompositeValue): void;
/**
* 导入节点数据
* import node schema
* @param data
*/
importSchema(data: IPublicTypeNodeSchema): void;
/**
* 导出节点数据
* export schema from this node
* @param stage
* @param options
*/
exportSchema(stage: IPublicEnumTransformStage, options?: any): IPublicTypeNodeSchema;
/**
* 在指定位置之前插入一个节点
* insert a node befor current node
* @param node
* @param ref
* @param useMutator
*/
insertBefore(
node: Node,
ref?: Node | undefined,
useMutator?: boolean,
): void;
/**
* 在指定位置之后插入一个节点
* insert a node after this node
* @param node
* @param ref
* @param useMutator
*/
insertAfter(
node: Node,
ref?: Node | undefined,
useMutator?: boolean,
): void;
/**
* 替换指定节点
* replace a child node with data provided
* @param node 待替换的子节点
* @param data 用作替换的节点对象或者节点描述
* @returns
*/
replaceChild(node: Node, data: any): Node | null;
/**
* 将当前节点替换成指定节点描述
* replace current node with a new node schema
* @param schema
*/
replaceWith(schema: IPublicTypeNodeSchema): any;
/**
* 选中当前节点实例
* select current node
*/
select(): void;
/**
* 设置悬停态
* set hover value for current node
* @param flag
*/
hover(flag: boolean): void;
/**
* 设置节点锁定状态
* set lock value for current node
* @param flag
* @since v1.0.16
*/
lock(flag?: boolean): void;
/**
* 删除当前节点实例
* remove current node
*/
remove(): void;
/**
* 执行新增、删除、排序等操作
* excute remove/add/sort operations on node`s children
*
* @since v1.1.0
*/
mergeChildren(
remover: (node: Node, idx: number) => boolean,
adder: (children: Node[]) => any,
sorter: (firstNode: Node, secondNode: Node) => number
): any;
/**
* 当前节点是否包含某子节点
* check if current node contains another node as a child
* @param node
* @since v1.1.0
*/
contains(node: Node): boolean;
/**
* 是否可执行某 action
* check if current node can perform certain aciton with actionName
* @param actionName action 名字
* @since v1.1.0
*/
canPerformAction(actionName: string): boolean;
/**
* 当前节点是否可见
* check if current node is visible
* @since v1.1.0
*/
get visible(): boolean;
/**
* 设置当前节点是否可见
* set visible value for current node
* @since v1.1.0
*/
set visible(value: boolean);
/**
* 获取该节点的 ConditionalVisible 值
* check if current node ConditionalVisible
* @since v1.1.0
*/
isConditionalVisible(): boolean | undefined;
/**
* 设置该节点的 ConditionalVisible 为 true
* make this node as conditionalVisible === true
* @since v1.1.0
*/
setConditionalVisible(): void;
/**
* 获取节点实例对应的 dom 节点
*/
getDOMNode(): HTMLElement;
}
export interface IPublicModelNode extends IBaseModelNode<IPublicModelDocumentModel, IPublicModelNode> {}