forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
230 lines (213 loc) · 4.59 KB
/
schema.ts
File metadata and controls
230 lines (213 loc) · 4.59 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import { InterpretDataSource as DataSource } from '@alilc/lowcode-datasource-types';
import { ComponentsMap } from './npm';
import {
CompositeValue,
JSExpression,
JSFunction,
CompositeObject,
JSONObject,
} from './value-type';
import { I18nMap } from './i18n';
import { UtilsMap } from './utils';
import { AppConfig } from './app-config';
// 转换成一个 .jsx 文件内 React Class 类 render 函数返回的 jsx 代码
/**
* 搭建基础协议 - 单个组件树节点描述
*/
export interface NodeSchema {
id?: string;
/**
* 组件名称 必填、首字母大写
*/
componentName: string;
/**
* 组件属性对象
*/
props?: {
children?: NodeData[];
} & PropsMap;// | PropsList;
/**
* 组件属性对象
*/
leadingComponents?: string;
/**
* 渲染条件
*/
condition?: CompositeValue;
/**
* 循环数据
*/
loop?: CompositeValue;
/**
* 循环迭代对象、索引名称 ["item", "index"]
*/
loopArgs?: [string, string];
/**
* 子节点
*/
children?: NodeData | NodeData[];
/**
* 是否锁定
*/
isLocked?: boolean;
// @todo
// ------- future support -----
conditionGroup?: string;
title?: string;
ignore?: boolean;
locked?: boolean;
hidden?: boolean;
isTopFixed?: boolean;
/** @experimental 编辑态内部使用 */
__ctx?: any;
/** @experimental 编辑态内部使用 */
__ignoreParse?: any[];
}
export type PropsMap = CompositeObject;
export type PropsList = Array<{
spread?: boolean;
name?: string;
value: CompositeValue;
}>;
export type NodeData = NodeSchema | JSExpression | DOMText;
export type NodeDataType = NodeData | NodeData[];
export function isDOMText(data: any): data is DOMText {
return typeof data === 'string';
}
export type DOMText = string;
/**
* 容器结构描述
*/
export interface ContainerSchema extends NodeSchema {
/**
* 'Block' | 'Page' | 'Component';
*/
componentName: string;
/**
* 文件名称
*/
fileName: string;
/**
* @todo 待文档定义
*/
meta?: Record<string, unknown>;
/**
* 容器初始数据
*/
state?: {
[key: string]: CompositeValue;
};
/**
* 自定义方法设置
*/
methods?: {
[key: string]: JSExpression | JSFunction;
};
/**
* 生命周期对象
*/
lifeCycles?: {
// @todo 生命周期对象建议改为闭合集合
[key: string]: JSExpression | JSFunction;
};
/**
* 样式文件
*/
css?: string;
/**
* 异步数据源配置
*/
dataSource?: DataSource;
/**
* 低代码业务组件默认属性
*/
defaultProps?: CompositeObject;
// @todo propDefinitions
}
/**
* 页面容器
* @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5
*/
export interface PageSchema extends ContainerSchema {
componentName: 'Page';
}
/**
* 低代码业务组件容器
* @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5
*/
export interface ComponentSchema extends ContainerSchema {
componentName: 'Component';
}
/**
* 区块容器
* @see https://yuque.antfin-inc.com/mo/spec/spec-low-code-building-schema#XMeF5
*/
export interface BlockSchema extends ContainerSchema {
componentName: 'Block';
}
/**
* @todo
*/
export type RootSchema = PageSchema | ComponentSchema | BlockSchema;
/**
* Slot schema 描述
*/
export interface SlotSchema extends NodeSchema {
componentName: 'Slot';
name?: string;
params?: string[];
}
/**
* 应用描述
*/
export interface ProjectSchema {
id?: string;
/**
* 当前应用协议版本号
*/
version: string;
/**
* 当前应用所有组件映射关系
*/
componentsMap: ComponentsMap;
/**
* 描述应用所有页面、低代码组件的组件树
* 低代码业务组件树描述
* 是长度固定为1的数组, 即数组内仅包含根容器的描述(低代码业务组件容器类型)
*/
componentsTree: RootSchema[];
/**
* 国际化语料
*/
i18n?: I18nMap;
/**
* 应用范围内的全局自定义函数或第三方工具类扩展
*/
utils?: UtilsMap;
/**
* 应用范围内的全局常量
*/
constants?: JSONObject;
/**
* 应用范围内的全局样式
*/
css?: string;
/**
* 当前应用的公共数据源
*/
dataSource?: DataSource;
/**
* 当前应用配置信息
*/
config?: AppConfig | Record<string, any>;
/**
* 当前应用元数据信息
*/
meta?: Record<string, any>;
}
export function isNodeSchema(data: any): data is NodeSchema {
return data && data.componentName;
}
export function isProjectSchema(data: any): data is ProjectSchema {
return data && data.componentsTree;
}