forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.ts
More file actions
80 lines (70 loc) · 1.51 KB
/
selection.ts
File metadata and controls
80 lines (70 loc) · 1.51 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
import {
DocumentModel as InnerDocumentModel,
Node as InnerNode,
Selection as InnerSelection,
} from '@alilc/lowcode-designer';
import Node from './node';
import { documentSymbol, selectionSymbol } from './symbols';
export default class Selection {
private readonly [documentSymbol]: InnerDocumentModel;
private readonly [selectionSymbol]: InnerSelection;
constructor(document: InnerDocumentModel) {
this[documentSymbol] = document;
this[selectionSymbol] = document.selection;
}
/**
* 返回选中的节点 id
*/
get selected() {
return this[selectionSymbol].selected;
}
/**
* 选中指定节点(覆盖方式)
* @param id
*/
select(id: string) {
this[selectionSymbol].select(id);
}
/**
* 批量选中指定节点们
* @param ids
*/
selectAll(ids: string[]) {
this[selectionSymbol].selectAll(ids);
}
/**
* 移除选中的指定节点
* @param id
*/
remove(id: string) {
this[selectionSymbol].remove(id);
}
/**
* 清除所有选中节点
*/
clear() {
this[selectionSymbol].clear();
}
/**
* 判断是否选中了指定节点
* @param id
* @returns
*/
has(id: string) {
return this[selectionSymbol].has(id);
}
/**
* 选中指定节点(增量方式)
* @param id
*/
add(id: string) {
this[selectionSymbol].add(id);
}
/**
* 获取选中的节点实例
* @returns
*/
getNodes() {
return this[selectionSymbol].getNodes().map((node: InnerNode) => Node.create(node));
}
}