forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprops.ts
More file actions
118 lines (104 loc) · 3.1 KB
/
props.ts
File metadata and controls
118 lines (104 loc) · 3.1 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
import { IProps as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
import { IPublicTypeCompositeValue, IPublicModelProps, IPublicModelNode, IPublicModelProp } from '@alilc/lowcode-types';
import { propsSymbol } from '../symbols';
import { Node as ShellNode } from './node';
import { Prop as ShellProp } from './prop';
export class Props implements IPublicModelProps {
private readonly [propsSymbol]: InnerProps;
constructor(props: InnerProps) {
this[propsSymbol] = props;
}
static create(props: InnerProps | undefined | null): IPublicModelProps | null {
if (!props) {
return null;
}
return new Props(props);
}
/**
* id
*/
get id(): string {
return this[propsSymbol].id;
}
/**
* 返回当前 props 的路径
*/
get path(): string[] {
return this[propsSymbol].path;
}
/**
* 返回所属的 node 实例
*/
get node(): IPublicModelNode | null {
return ShellNode.create(this[propsSymbol].getNode());
}
/**
* 获取指定 path 的属性模型实例
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getProp(path: string): IPublicModelProp | null {
return ShellProp.create(this[propsSymbol].getProp(path));
}
/**
* 获取指定 path 的属性模型实例值
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getPropValue(path: string): any {
return this.getProp(path)?.getValue();
}
/**
* 获取指定 path 的属性模型实例,
* 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getExtraProp(path: string): IPublicModelProp | null {
return ShellProp.create(this[propsSymbol].getProp(getConvertedExtraKey(path)));
}
/**
* 获取指定 path 的属性模型实例值
* 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getExtraPropValue(path: string): any {
return this.getExtraProp(path)?.getValue();
}
/**
* 设置指定 path 的属性模型实例值
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param value 值
* @returns
*/
setPropValue(path: string, value: IPublicTypeCompositeValue): void {
return this.getProp(path)?.setValue(value);
}
/**
* 设置指定 path 的属性模型实例值
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param value 值
* @returns
*/
setExtraPropValue(path: string, value: IPublicTypeCompositeValue): void {
return this.getExtraProp(path)?.setValue(value);
}
/**
* test if the specified key is existing or not.
* @param key
* @returns
*/
has(key: string): boolean {
return this[propsSymbol].has(key);
}
/**
* add a key with given value
* @param value
* @param key
* @returns
*/
add(value: IPublicTypeCompositeValue, key?: string | number | undefined): any {
return this[propsSymbol].add(value, key);
}
}