forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue-type.ts
More file actions
145 lines (132 loc) · 2.65 KB
/
value-type.ts
File metadata and controls
145 lines (132 loc) · 2.65 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { NodeSchema, NodeData } from './schema';
/**
* 变量表达式
*
* 表达式内通过 this 对象获取上下文
*/
export interface JSExpression {
type: 'JSExpression';
/**
* 表达式字符串
*/
value: string;
/**
* 模拟值
*
* @todo 待标准描述
*/
mock?: any;
/**
* 源码
*
* @todo 待标准描述
*/
compiled?: string;
}
/**
* 事件函数类型
* @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#feHTW
*
* 保留与原组件属性、生命周期( React / 小程序)一致的输入参数,并给所有事件函数 binding 统一一致的上下文(当前组件所在容器结构的 this 对象)
*/
export interface JSFunction {
type: 'JSFunction';
/**
* 函数定义,或直接函数表达式
*/
value: string;
/**
* 源码
*
* @todo 待标准描述
*/
compiled?: string;
/**
* 模拟值
*
* @todo 待标准描述
*/
mock?: any;
/**
* 额外扩展属性,如 extType、events
*
* @todo 待标准描述
*/
[key: string]: any;
}
/**
* Slot 函数类型
*
* 通常用于描述组件的某一个属性为 ReactNode 或 Function return ReactNode 的场景。
*/
export interface JSSlot {
type: 'JSSlot';
/**
* @todo 待标准描述
*/
title?: string;
/**
* 组件的某一个属性为 Function return ReactNode 时,函数的入参
*
* 其子节点可以通过this[参数名] 来获取对应的参数。
*/
params?: string[];
/**
* 具体的值。
*/
value?: NodeData[] | NodeData;
/**
* @todo 待标准描述
*/
name?: string;
}
/**
* @deprecated
*
* @todo 待文档描述
*/
export interface JSBlock {
type: 'JSBlock';
value: NodeSchema;
}
/**
* JSON 基本类型
*/
export type JSONValue =
| boolean
| string
| number
| null
| undefined
| JSONArray
| JSONObject;
export type JSONArray = JSONValue[];
export interface JSONObject {
[key: string]: JSONValue;
}
/**
* 复合类型
*/
export type CompositeValue =
| JSONValue
| JSExpression
| JSFunction
| JSSlot
| CompositeArray
| CompositeObject;
export type CompositeArray = CompositeValue[];
export interface CompositeObject {
[key: string]: CompositeValue;
}
export function isJSExpression(data: any): data is JSExpression {
return data && data.type === 'JSExpression';
}
export function isJSFunction(x: any): x is JSFunction {
return typeof x === 'object' && x && x.type === 'JSFunction';
}
export function isJSSlot(data: any): data is JSSlot {
return data && data.type === 'JSSlot';
}
export function isJSBlock(data: any): data is JSBlock {
return data && data.type === 'JSBlock';
}