forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharea.ts
More file actions
78 lines (65 loc) · 1.9 KB
/
area.ts
File metadata and controls
78 lines (65 loc) · 1.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
import { obx, computed, makeObservable } from '@alilc/lowcode-editor-core';
import WidgetContainer from './widget/widget-container';
import { Skeleton } from './skeleton';
import { IWidget } from './widget/widget';
import { IWidgetBaseConfig } from './types';
export default class Area<C extends IWidgetBaseConfig = any, T extends IWidget = IWidget> {
@obx private _visible = true;
@computed get visible() {
if (this.exclusive) {
return this.container.current != null;
}
return this._visible;
}
get current() {
if (this.exclusive) {
return this.container.current;
}
return null;
}
readonly container: WidgetContainer<T, C>;
constructor(readonly skeleton: Skeleton, readonly name: string, handle: (item: T | C) => T, private exclusive?: boolean, defaultSetCurrent = false) {
makeObservable(this);
this.container = skeleton.createContainer(name, handle, exclusive, () => this.visible, defaultSetCurrent);
}
isEmpty(): boolean {
return this.container.items.length < 1;
}
add(config: T | C): T {
const item = this.container.get(config.name);
if (item) {
return item;
}
return this.container.add(config);
}
remove(config: T | string): number {
return this.container.remove(config);
}
private lastCurrent: T | null = null;
setVisible(flag: boolean) {
if (this.exclusive) {
const { current } = this.container;
if (flag && !current) {
this.container.active(this.lastCurrent || this.container.getAt(0));
} else if (current) {
this.lastCurrent = current;
this.container.unactive(current);
}
return;
}
this._visible = flag;
}
hide() {
this.setVisible(false);
}
show() {
this.setVisible(true);
}
// ========== compatible for vision ========
/**
* @deprecated
*/
removeAction(config: string): number {
return this.remove(config);
}
}