forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnode-children.ts
More file actions
190 lines (165 loc) · 3.82 KB
/
node-children.ts
File metadata and controls
190 lines (165 loc) · 3.82 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
import { IPublicTypeNodeSchema, IPublicTypeNodeData } from '../type';
import { IPublicEnumTransformStage } from '../enum';
import { IPublicModelNode } from './';
export interface IPublicModelNodeChildren<
Node = IPublicModelNode
> {
/**
* 返回当前 children 实例所属的节点实例
* get owner node of this nodeChildren
*/
get owner(): Node | null;
/**
* children 内的节点实例数
* get count of child nodes
*/
get size(): number;
/**
* @deprecated please use isEmptyNode
* 是否为空
* @returns
*/
get isEmpty(): boolean;
/**
* 是否为空
*
* @returns
*/
get isEmptyNode(): boolean;
/**
* @deprecated please use notEmptyNode
* judge if it is not empty
*/
get notEmpty(): boolean;
/**
* judge if it is not empty
*/
get notEmptyNode(): boolean;
/**
* 删除指定节点
*
* delete the node
* @param node
*/
delete(node: Node): boolean;
/**
* 插入一个节点
*
* insert a node at specific position
* @param node 待插入节点
* @param at 插入下标
* @returns
*/
insert(node: Node, at?: number | null): void;
/**
* 返回指定节点的下标
*
* get index of node in current children
* @param node
* @returns
*/
indexOf(node: Node): number;
/**
* 类似数组 splice 操作
*
* provide the same function with {Array.prototype.splice}
* @param start
* @param deleteCount
* @param node
*/
splice(start: number, deleteCount: number, node?: Node): any;
/**
* 返回指定下标的节点
*
* get node with index
* @param index
* @returns
*/
get(index: number): Node | null;
/**
* 是否包含指定节点
*
* check if node exists in current children
* @param node
* @returns
*/
has(node: Node): boolean;
/**
* 类似数组的 forEach
*
* provide the same function with {Array.prototype.forEach}
* @param fn
*/
forEach(fn: (node: Node, index: number) => void): void;
/**
* 类似数组的 reverse
*
* provide the same function with {Array.prototype.reverse}
*/
reverse(): Node[];
/**
* 类似数组的 map
*
* provide the same function with {Array.prototype.map}
* @param fn
*/
map<T = any>(fn: (node: Node, index: number) => T): T[] | null;
/**
* 类似数组的 every
* provide the same function with {Array.prototype.every}
* @param fn
*/
every(fn: (node: Node, index: number) => boolean): boolean;
/**
* 类似数组的 some
* provide the same function with {Array.prototype.some}
* @param fn
*/
some(fn: (node: Node, index: number) => boolean): boolean;
/**
* 类似数组的 filter
* provide the same function with {Array.prototype.filter}
* @param fn
*/
filter(fn: (node: Node, index: number) => boolean): any;
/**
* 类似数组的 find
* provide the same function with {Array.prototype.find}
* @param fn
*/
find(fn: (node: Node, index: number) => boolean): Node | null | undefined;
/**
* 类似数组的 reduce
*
* provide the same function with {Array.prototype.reduce}
* @param fn
*/
reduce(fn: (acc: any, cur: Node) => any, initialValue: any): void;
/**
* 导入 schema
*
* import schema
* @param data
*/
importSchema(data?: IPublicTypeNodeData | IPublicTypeNodeData[]): void;
/**
* 导出 schema
*
* export schema
* @param stage
*/
exportSchema(stage: IPublicEnumTransformStage): IPublicTypeNodeSchema;
/**
* 执行新增、删除、排序等操作
*
* excute remove/add/sort operations
* @param remover
* @param adder
* @param sorter
*/
mergeChildren(
remover: (node: Node, idx: number) => boolean,
adder: (children: Node[]) => IPublicTypeNodeData[] | null,
sorter: (firstNode: Node, secondNode: Node) => number
): any;
}