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
97 lines (78 loc) · 1.78 KB
/
node.ts
File metadata and controls
97 lines (78 loc) · 1.78 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
import { IPublicTypePropChangeOptions } from "@ali/lowcode-designer";
import EventEmitter from "events";
export default class Node {
private emitter: EventEmitter;
schema: any = {
props: {},
};
componentMeta = {};
parent;
hasLoop = () => this._hasLoop;
id;
_isRoot: false;
_hasLoop: false;
constructor(schema: any, info: any = {}) {
this.emitter = new EventEmitter();
const {
componentMeta,
parent,
isRoot,
hasLoop,
} = info;
this.schema = {
props: {},
...schema,
};
this.componentMeta = componentMeta || {};
this.parent = parent;
this.id = schema.id;
this._isRoot = isRoot;
this._hasLoop = hasLoop;
}
isRoot = () => this._isRoot;
get isRootNode () {
return this._isRoot;
};
// componentMeta() {
// return this.componentMeta;
// }
// mockLoop() {
// // this.hasLoop = true;
// }
onChildrenChange(fn: any) {
this.emitter.on('onChildrenChange', fn);
return () => {
this.emitter.off('onChildrenChange', fn);
}
}
emitChildrenChange() {
this.emitter?.emit('onChildrenChange', {});
}
onPropChange(fn: any) {
this.emitter.on('onPropChange', fn);
return () => {
this.emitter.off('onPropChange', fn);
}
}
emitPropChange(val: IPublicTypePropChangeOptions, skip?: boolean) {
if (!skip) {
this.schema.props = {
...this.schema.props,
[val.key + '']: val.newValue,
}
}
this.emitter?.emit('onPropChange', val);
}
onVisibleChange(fn: any) {
this.emitter.on('onVisibleChange', fn);
return () => {
this.emitter.off('onVisibleChange', fn);
}
}
emitVisibleChange(val: boolean) {
this.emitter?.emit('onVisibleChange', val);
}
export() {
return this.schema;
}
}