@cicctencent/low-code-simulate-base 0.0.0-stage → 1.1.9-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/__tests__/plugin.spec.ts +40 -0
- package/__tests__/utils.transform.test.ts +37 -0
- package/api-extractor.json +36 -0
- package/build/md.js +25 -0
- package/dist/VCComponent.d.ts +5 -0
- package/dist/VCComponent.js +91 -0
- package/dist/domain/BaseProjectDomain.d.ts +349 -0
- package/dist/domain/BaseProjectDomain.js +1305 -0
- package/dist/domain/ComponentManager.d.ts +78 -0
- package/dist/domain/ComponentManager.js +293 -0
- package/dist/domain/DataHistoryDomain.d.ts +53 -0
- package/dist/domain/DataHistoryDomain.js +110 -0
- package/dist/domain/PreviewDomain.d.ts +208 -0
- package/dist/domain/PreviewDomain.js +492 -0
- package/dist/domain/ProjectDomain.d.ts +209 -0
- package/dist/domain/ProjectDomain.js +138 -0
- package/dist/event/generateEventHandler.d.ts +21 -0
- package/dist/event/generateEventHandler.js +218 -0
- package/dist/event/generateEventSchema.d.ts +123 -0
- package/dist/event/generateEventSchema.js +342 -0
- package/dist/event/register.d.ts +56 -0
- package/dist/event/register.js +207 -0
- package/dist/index.d.ts +1330 -0
- package/dist/index.js +28 -0
- package/dist/plugin/onH5PageValidate.d.ts +7 -0
- package/dist/plugin/onH5PageValidate.js +178 -0
- package/dist/plugin/onPlaceholder.d.ts +6 -0
- package/dist/plugin/onPlaceholder.js +68 -0
- package/dist/plugin/subscribeInsertUploadList.d.ts +6 -0
- package/dist/plugin/subscribeInsertUploadList.js +49 -0
- package/dist/plugin/subscribeSetTitle.d.ts +6 -0
- package/dist/plugin/subscribeSetTitle.js +16 -0
- package/dist/plugin/subscribeTransformComponentMeta.d.ts +14 -0
- package/dist/plugin/subscribeTransformComponentMeta.js +31 -0
- package/dist/plugin/subscribeValidateField.d.ts +7 -0
- package/dist/plugin/subscribeValidateField.js +57 -0
- package/dist/plugin/subscribeValidateUpload.d.ts +6 -0
- package/dist/plugin/subscribeValidateUpload.js +92 -0
- package/dist/utils/base64.d.ts +14 -0
- package/dist/utils/base64.js +14 -0
- package/dist/utils/buildInVariable.d.ts +61 -0
- package/dist/utils/buildInVariable.js +216 -0
- package/dist/utils/dom.d.ts +14 -0
- package/dist/utils/dom.js +19 -0
- package/dist/utils/index.d.ts +55 -0
- package/dist/utils/index.js +201 -0
- package/dist/utils/transform.d.ts +39 -0
- package/dist/utils/transform.js +191 -0
- package/dist/utils/validate.d.ts +7 -0
- package/dist/utils/validate.js +18 -0
- package/docs/.api/low-code-simulate-base.api.json +8450 -0
- package/jest.config.ts +20 -0
- package/package.json +44 -4
- package/src/VCComponent.ts +118 -0
- package/src/domain/BaseProjectDomain.ts +1341 -0
- package/src/domain/ComponentManager.ts +241 -0
- package/src/domain/DataHistoryDomain.ts +102 -0
- package/src/domain/PreviewDomain.ts +424 -0
- package/src/domain/ProjectDomain.ts +244 -0
- package/src/event/generateEventHandler.ts +162 -0
- package/src/event/generateEventSchema.ts +371 -0
- package/src/event/register.ts +181 -0
- package/src/index.ts +61 -0
- package/src/plugin/onH5PageValidate.ts +179 -0
- package/src/plugin/onPlaceholder.ts +71 -0
- package/src/plugin/subscribeInsertUploadList.ts +51 -0
- package/src/plugin/subscribeSetTitle.ts +18 -0
- package/src/plugin/subscribeTransformComponentMeta.ts +38 -0
- package/src/plugin/subscribeValidateField.ts +65 -0
- package/src/plugin/subscribeValidateUpload.ts +116 -0
- package/src/utils/base64.ts +17 -0
- package/src/utils/buildInVariable.ts +157 -0
- package/src/utils/dom.ts +30 -0
- package/src/utils/index.ts +194 -0
- package/src/utils/transform.ts +171 -0
- package/src/utils/validate.ts +19 -0
- package/temp/low-code-simulate-base.api.md +597 -0
- package/test/plugin.test.ts +4 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +9 -0
- package/tsconfig.test.json +14 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 占位词映射表 key为占位词 value为占位词对应的真实数据
|
|
28
|
+
*/
|
|
29
|
+
var flagWordMap = {};
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
* 转化每个表单项的配置
|
|
33
|
+
* @param item - item
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export function transformItem(item) {
|
|
37
|
+
var result = {};
|
|
38
|
+
var _loop_1 = function (key) {
|
|
39
|
+
if (key === 'properties') {
|
|
40
|
+
result[key] = transformProperties(item[key], flagWordMap);
|
|
41
|
+
}
|
|
42
|
+
else if (key === 'items') {
|
|
43
|
+
result[key] = item[key];
|
|
44
|
+
// 处理对象数组
|
|
45
|
+
if ('properties' in item[key]) {
|
|
46
|
+
result[key].properties = transformProperties(item[key].properties, flagWordMap);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (key === 'x-component-props') {
|
|
50
|
+
result[key] = {};
|
|
51
|
+
// 处理x-component-props里的占位词
|
|
52
|
+
Object.keys(item[key]).forEach(function (prop) {
|
|
53
|
+
// 判断是否为占位词
|
|
54
|
+
if (typeof item[key][prop] === 'string' &&
|
|
55
|
+
item[key][prop].startsWith('$')) {
|
|
56
|
+
// 若映射表里有占位词对应的数据 则替换 否则隐藏这一项
|
|
57
|
+
if (Object.keys(flagWordMap).includes(item[key][prop])) {
|
|
58
|
+
result[key][prop] = flagWordMap["".concat(item[key][prop])];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
result['x-hidden'] = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result[key][prop] = item[key][prop];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// 目前除了配置项中properties属性 所有字段都保持不动
|
|
71
|
+
result[key] = item[key];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// 修改或忽略原有字段
|
|
75
|
+
for (var key in item) {
|
|
76
|
+
_loop_1(key);
|
|
77
|
+
}
|
|
78
|
+
// 修改转化后的字段或添加新字段
|
|
79
|
+
if (result['x-component'] === 'Select') {
|
|
80
|
+
// 占位词替换
|
|
81
|
+
if (typeof result['enum'] === 'string' && result['enum'].startsWith('$')) {
|
|
82
|
+
if (Object.keys(flagWordMap).includes(result['enum'])) {
|
|
83
|
+
result['enum'] = flagWordMap["".concat(item['enum'])];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
result['x-hidden'] = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @public
|
|
94
|
+
* 转化全部配置(formily的业务相关转化逻辑搬过来后使用)
|
|
95
|
+
* @param config - schema配置
|
|
96
|
+
* @param map - 占位词映射表
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
export function transform(config, map) {
|
|
100
|
+
if (!config) {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
flagWordMap = map;
|
|
104
|
+
var result = {};
|
|
105
|
+
Object.keys(config).forEach(function (key) {
|
|
106
|
+
result[key] = transformItem(config[key]);
|
|
107
|
+
});
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
* @param schema - schema
|
|
114
|
+
* @param fillData - fillData
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
export function transformSchemaToForm(schema, fillData) {
|
|
118
|
+
try {
|
|
119
|
+
var data_1 = {};
|
|
120
|
+
Object.keys(schema).forEach(function (key) {
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
if ('properties' in schema[key] && ((_a = schema[key]) === null || _a === void 0 ? void 0 : _a.type) === 'object') {
|
|
123
|
+
var result = transformSchemaToForm(schema[key].properties, fillData);
|
|
124
|
+
if (Object.keys(result).length) {
|
|
125
|
+
data_1[key] = result;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// void类型
|
|
129
|
+
if ('properties' in schema[key] && ((_b = schema[key]) === null || _b === void 0 ? void 0 : _b.type) === 'void') {
|
|
130
|
+
Object.keys(schema[key].properties || {}).forEach(function (it) {
|
|
131
|
+
var result = transformSchemaToForm(schema[key].properties, fillData);
|
|
132
|
+
Object.assign(data_1, result);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// 填充值
|
|
136
|
+
var xData = ((_c = schema[key]) === null || _c === void 0 ? void 0 : _c['x-data']) || {};
|
|
137
|
+
if ('autoFillFieldData' in xData) {
|
|
138
|
+
var templateStr = xData.autoFillFieldData || '';
|
|
139
|
+
var value = templateStr.replace(/\${{(.*?)}}/g, function ($1, $2) {
|
|
140
|
+
console.log('autoFillFieldData $1', $1);
|
|
141
|
+
return fillData[$2];
|
|
142
|
+
});
|
|
143
|
+
data_1[key] = value;
|
|
144
|
+
}
|
|
145
|
+
// 默认值
|
|
146
|
+
if (schema[key].default) {
|
|
147
|
+
data_1[key] = schema[key].default;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return data_1;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.log('transformSchemaToForm error', String(error));
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @public
|
|
159
|
+
* 转化properties对象
|
|
160
|
+
* @param properties - properties
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
export function transformProperties(properties, map) {
|
|
164
|
+
flagWordMap = map;
|
|
165
|
+
var result = {};
|
|
166
|
+
for (var key in properties) {
|
|
167
|
+
result[key] = transformItem(properties[key]);
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @public
|
|
173
|
+
* 获取遍历对象的path数组
|
|
174
|
+
* @param obj - 对象
|
|
175
|
+
* @param prefix - 前缀,父路径
|
|
176
|
+
* @param visited - 用于跟踪已经访问过的对象,避免死循环
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
export function getObjectPath(obj, prefix, visited) {
|
|
180
|
+
if (prefix === void 0) { prefix = ''; }
|
|
181
|
+
if (visited === void 0) { visited = new Set(); }
|
|
182
|
+
if (!obj || typeof obj !== 'object' || visited.has(obj)) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
visited.add(obj);
|
|
186
|
+
return Object.keys(obj).reduce(function (acc, key) {
|
|
187
|
+
var currentPath = "".concat(prefix).concat(key);
|
|
188
|
+
var childPaths = getObjectPath(obj[key], "".concat(currentPath, "."), visited);
|
|
189
|
+
return acc.concat.apply(acc, __spreadArray([currentPath], __read(childPaths), false));
|
|
190
|
+
}, []);
|
|
191
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cloneDeep } from '@jt/ark-util';
|
|
2
|
+
import { FormilyValidate } from '@jt/low-code-validate';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
* @param component - 组件配置
|
|
6
|
+
* @param validateData - 校验数据
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function formilyValidate(component, validateData) {
|
|
10
|
+
var data = cloneDeep((component === null || component === void 0 ? void 0 : component.formData) || {});
|
|
11
|
+
var config = cloneDeep((component === null || component === void 0 ? void 0 : component.config) || {});
|
|
12
|
+
var formilyValidate = new FormilyValidate({
|
|
13
|
+
data: data,
|
|
14
|
+
schema: config,
|
|
15
|
+
validateData: validateData,
|
|
16
|
+
});
|
|
17
|
+
return formilyValidate === null || formilyValidate === void 0 ? void 0 : formilyValidate.validate();
|
|
18
|
+
}
|