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
97 lines (85 loc) · 2.47 KB
/
props.ts
File metadata and controls
97 lines (85 loc) · 2.47 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 { Props as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
import { CompositeValue, TransformStage } from '@alilc/lowcode-types';
import { propsSymbol } from './symbols';
import Node from './node';
import Prop from './prop';
export default class Props {
private readonly [propsSymbol]: InnerProps;
constructor(props: InnerProps) {
this[propsSymbol] = props;
}
static create(props: InnerProps | undefined | null) {
if (!props) return null;
return new Props(props);
}
/**
* id
*/
get id() {
return this[propsSymbol].id;
}
/**
* 返回当前 props 的路径
*/
get path() {
return this[propsSymbol].path;
}
/**
* 返回所属的 node 实例
*/
get node(): Node | null {
return Node.create(this[propsSymbol].getNode());
}
/**
* 获取指定 path 的属性模型实例
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getProp(path: string): Prop | null {
return Prop.create(this[propsSymbol].getProp(path));
}
/**
* 获取指定 path 的属性模型实例值
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getPropValue(path: string) {
return this.getProp(path)?.getValue();
}
/**
* 获取指定 path 的属性模型实例,
* 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getExtraProp(path: string): Prop | null {
return Prop.create(this[propsSymbol].getProp(getConvertedExtraKey(path)));
}
/**
* 获取指定 path 的属性模型实例值
* 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @returns
*/
getExtraPropValue(path: string) {
return this.getExtraProp(path)?.getValue();
}
/**
* 设置指定 path 的属性模型实例值
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param value 值
* @returns
*/
setPropValue(path: string, value: CompositeValue) {
return this.getProp(path)?.setValue(value);
}
/**
* 设置指定 path 的属性模型实例值
* @param path 属性路径,支持 a / a.b / a.0 等格式
* @param value 值
* @returns
*/
setExtraPropValue(path: string, value: CompositeValue) {
return this.getExtraProp(path)?.setValue(value);
}
}