forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.ts
More file actions
37 lines (30 loc) · 922 Bytes
/
tree.ts
File metadata and controls
37 lines (30 loc) · 922 Bytes
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
import { DocumentModel, Node } from '@alilc/lowcode-designer';
import { computed, makeObservable } from '@alilc/lowcode-editor-core';
import TreeNode from './tree-node';
export class Tree {
private treeNodesMap = new Map<string, TreeNode>();
readonly id: string;
@computed get root(): TreeNode | null {
if (this.document.focusNode) {
return this.getTreeNode(this.document.focusNode!);
}
return null;
}
constructor(readonly document: DocumentModel) {
makeObservable(this);
this.id = document.id;
}
getTreeNode(node: Node): TreeNode {
if (this.treeNodesMap.has(node.id)) {
const tnode = this.treeNodesMap.get(node.id)!;
tnode.setNode(node);
return tnode;
}
const treeNode = new TreeNode(this, node);
this.treeNodesMap.set(node.id, treeNode);
return treeNode;
}
getTreeNodeById(id: string) {
return this.treeNodesMap.get(id);
}
}