@cloudbase/cals 1.0.3-alpha.14 → 1.0.3-alpha.16

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.
Files changed (35) hide show
  1. package/lib/parser/.DS_Store +0 -0
  2. package/lib/parser/cals/.DS_Store +0 -0
  3. package/lib/parser/cals/index.d.ts +1 -1
  4. package/lib/parser/cals/index.d.ts.map +1 -1
  5. package/lib/parser/cals/index.js +27 -13
  6. package/lib/parser/cals/utils/.DS_Store +0 -0
  7. package/lib/parser/cals/utils/block/index.d.ts.map +1 -1
  8. package/lib/parser/cals/utils/block/index.js +7 -3
  9. package/lib/parser/cals/utils/code/index.d.ts.map +1 -1
  10. package/lib/parser/cals/utils/code/index.js +18 -12
  11. package/lib/parser/cals/utils/runtime.d.ts.map +1 -1
  12. package/lib/parser/cals/utils/runtime.js +5 -2
  13. package/lib/parser/cals/utils/style.d.ts.map +1 -1
  14. package/lib/parser/cals/utils/style.js +7 -3
  15. package/lib/parser/cals/utils/version/common.d.ts.map +1 -1
  16. package/lib/parser/cals/utils/version/common.js +16 -33
  17. package/lib/parser/cals/utils/version/parses.d.ts.map +1 -1
  18. package/lib/parser/cals/utils/version/parses.js +18 -36
  19. package/lib/parser/cals/utils/version/utils.js +5 -2
  20. package/lib/parser/plugins/postcss-rpx2clac.js +2 -2
  21. package/lib/types/index.d.ts +1 -1
  22. package/lib/types/index.d.ts.map +1 -1
  23. package/lib/types/index.js +14 -1
  24. package/lib/types/lcds.d.ts +324 -211
  25. package/lib/types/lcds.d.ts.map +1 -1
  26. package/lib/utils/build.js +3 -3
  27. package/lib/utils/dts/auto-generated.d.ts +1 -1
  28. package/lib/utils/dts/auto-generated.d.ts.map +1 -1
  29. package/lib/utils/dts/auto-generated.js +1227 -35
  30. package/lib/utils/dts/build.js +1 -4
  31. package/lib/utils/dts/index.d.ts +41 -4
  32. package/lib/utils/dts/index.d.ts.map +1 -1
  33. package/lib/utils/dts/index.js +361 -66
  34. package/lib/utils/version/migrations/version4.js +2 -2
  35. package/package.json +2 -1
@@ -8,8 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.compileJSONToDTS = exports.jsonToDTSWorkerCode = exports.transpileToDTS = exports.workerCode = exports.generateWeDaAppDTS = exports.WeDaDTS = exports.IInputDataType = void 0;
16
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
17
+ const pick_1 = __importDefault(require("lodash/pick"));
18
+ const set_1 = __importDefault(require("lodash/set"));
19
+ const json_easy_filter_1 = __importDefault(require("json-easy-filter"));
13
20
  const auto_generated_1 = require("./auto-generated");
14
21
  var IInputDataType;
15
22
  (function (IInputDataType) {
@@ -26,6 +33,7 @@ var IInputDataType;
26
33
  IInputDataType["usedComponents"] = "usedComponents";
27
34
  IInputDataType["usedWidgets"] = "usedWidgets";
28
35
  IInputDataType["repeaterScope"] = "repeaterScope";
36
+ IInputDataType["redefineAnyType"] = "redefineAnyType";
29
37
  })(IInputDataType = exports.IInputDataType || (exports.IInputDataType = {}));
30
38
  const DtsPlaceholder = {
31
39
  [IInputDataType.globalState]: "// Global State 全局变量 - Don't touch me",
@@ -40,23 +48,34 @@ const DtsPlaceholder = {
40
48
  [IInputDataType.compPropEvents]: "// Comp Prop Events 组件事件 - Don't touch me",
41
49
  [IInputDataType.usedComponents]: "// Used Components - Don't touch me",
42
50
  [IInputDataType.usedWidgets]: "// used widgets - Don't touch me",
43
- [IInputDataType.repeaterScope]: "// repeater scope - Don't touch me"
51
+ [IInputDataType.repeaterScope]: "// repeater scope - Don't touch me",
52
+ [IInputDataType.redefineAnyType]: "// Redefine Any Type - Don't touch me",
44
53
  };
45
54
  const DtsInnerSign = {
46
- [IInputDataType.globalState]: "Global State Inner",
47
- [IInputDataType.pageState]: "Page State Inner",
48
- [IInputDataType.compState]: "Comp State Inner",
49
- [IInputDataType.pageParams]: "Page Param Inner",
50
- [IInputDataType.forState]: "Global For Inner",
51
- [IInputDataType.globalCommonCodes]: "Global Common Inner",
52
- [IInputDataType.pageHandlerCodes]: "Page Handler Inner",
53
- [IInputDataType.compHandlerCodes]: "Comp Handler Inner",
54
- [IInputDataType.compPropData]: "Comp Prop Data Inner",
55
- [IInputDataType.compPropEvents]: "Comp Prop Events Inner",
56
- [IInputDataType.usedComponents]: "Used Components Inner",
57
- [IInputDataType.usedWidgets]: "used widgets Inner",
58
- [IInputDataType.repeaterScope]: "repeater scope Inner"
55
+ [IInputDataType.globalState]: 'Global State Inner',
56
+ [IInputDataType.pageState]: 'Page State Inner',
57
+ [IInputDataType.compState]: 'Comp State Inner',
58
+ [IInputDataType.pageParams]: 'Page Param Inner',
59
+ [IInputDataType.forState]: 'Global For Inner',
60
+ [IInputDataType.globalCommonCodes]: 'Global Common Inner',
61
+ [IInputDataType.pageHandlerCodes]: 'Page Handler Inner',
62
+ [IInputDataType.compHandlerCodes]: 'Comp Handler Inner',
63
+ [IInputDataType.compPropData]: 'Comp Prop Data Inner',
64
+ [IInputDataType.compPropEvents]: 'Comp Prop Events Inner',
65
+ [IInputDataType.usedComponents]: 'Used Components Inner',
66
+ [IInputDataType.usedWidgets]: 'used widgets Inner',
67
+ [IInputDataType.repeaterScope]: 'repeater scope Inner',
68
+ [IInputDataType.redefineAnyType]: 'Redefine Any Type Inner',
59
69
  };
70
+ var GroupEnum;
71
+ (function (GroupEnum) {
72
+ GroupEnum["GLOBAL_VAR"] = "globalVar";
73
+ GroupEnum["PAGE_VAR"] = "pageVar";
74
+ GroupEnum["PAGE_PARAM"] = "pageParam";
75
+ GroupEnum["COMPONENT"] = "component";
76
+ GroupEnum["REPEATER"] = "repeater";
77
+ GroupEnum["DATA_FIELD"] = "dataField";
78
+ })(GroupEnum || (GroupEnum = {}));
60
79
  /**
61
80
  * 通过该类可以共享同个dts。
62
81
  * 场景:在 weda 中,低代码的变更会通知更改 dts,而低码编辑器和表达式编辑器对 dts 的需求是不一样的,这样不同的 dts 共享的是同一份全的 dts。如果直接调用 generateWeDaAppDTS 会导致 dts 重复地解析
@@ -75,19 +94,25 @@ class WeDaDTS {
75
94
  */
76
95
  static updateDTSPartial(inputData, itemType, options = { setEmptyIfError: false }) {
77
96
  return __awaiter(this, void 0, void 0, function* () {
78
- let dts = '';
79
97
  try {
80
- dts = yield _generateOneItemDTS(inputData, itemType);
98
+ const [dts, replaceRules] = yield _generateOneItemDTS(inputData, itemType);
99
+ replaceRules.forEach((rule) => {
100
+ WeDaDTS._dts = WeDaDTS._dts.replace(rule.from, rule.to);
101
+ });
81
102
  WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
82
103
  }
83
104
  catch (e) {
84
105
  if (options.setEmptyIfError) {
85
- WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${dts}\n$2`);
106
+ WeDaDTS._dts = WeDaDTS._dts.replace(new RegExp(`^(\\s*\\/\\/ ${DtsInnerSign[itemType]} Begin)[\\s\\S]*(^\\s*\\/\\/ ${DtsInnerSign[itemType]} End)`, 'm'), `$1\n${''}\n$2`);
86
107
  }
87
108
  }
88
109
  });
89
110
  }
90
- static getDTS(options = { needGlobalFormula: false, needGlobalFor: false, needRepeaterScope: false }) {
111
+ static getDTS(options = {
112
+ needGlobalFormula: false,
113
+ needGlobalFor: false,
114
+ needRepeaterScope: false,
115
+ }) {
91
116
  let resultDts = WeDaDTS._dts;
92
117
  if (!options.needGlobalFormula) {
93
118
  resultDts = resultDts.replace(/^\/\/ Global Formula Begin[\s\S]*^\/\/ Global Formula End$/m, '');
@@ -114,8 +139,11 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
114
139
  if (placeholder) {
115
140
  // 防止某项错误导致全部都错误
116
141
  try {
117
- const dts = yield _generateOneItemDTS(inputData[key], key);
118
- resultDts = resultDts.replace(placeholder, dts + placeholder);
142
+ const [dts, replaceRules] = yield _generateOneItemDTS(inputData[key], key);
143
+ replaceRules.forEach((rule) => {
144
+ resultDts = resultDts.replace(rule.from, rule.to);
145
+ });
146
+ resultDts = resultDts.replace(placeholder, dts + '\n' + placeholder);
119
147
  }
120
148
  catch (e) {
121
149
  console.error(e);
@@ -141,17 +169,151 @@ function generateWeDaAppDTS(inputData = {}, options = { isCompMode: false, needG
141
169
  if (!(options === null || options === void 0 ? void 0 : options.needRepeaterScope)) {
142
170
  resultDts = resultDts.replace(/\/\/ repeater scope Inner Begin[\s\S]*\/\/ repeater scope Inner End$/m, '');
143
171
  }
144
- // console.log(resultDts)
145
172
  return resultDts;
146
173
  });
147
174
  }
148
175
  exports.generateWeDaAppDTS = generateWeDaAppDTS;
176
+ /**
177
+ * 生成 weda 专有的注释信息
178
+ */
179
+ function genWeDaCodeComment({ fieldName, title, description, type, dataFieldInfo, group, schema, subGroup, baseClass, datasource, }) {
180
+ const desc = title || fieldName ? `${title || fieldName}\n${description || ''}` : '';
181
+ return (desc +
182
+ `\n@privateForWeDa\n${JSON.stringify({
183
+ group,
184
+ displayType: type,
185
+ displayName: title || '',
186
+ schema,
187
+ subGroup,
188
+ baseClass,
189
+ datasource,
190
+ dataFieldInfo,
191
+ })}`);
192
+ }
149
193
  /**
150
194
  * 生成指定类型的 DTS
151
195
  */
152
196
  function _generateOneItemDTS(inputData, itemType) {
153
197
  return __awaiter(this, void 0, void 0, function* () {
198
+ const replaceRules = [];
199
+ /**
200
+ * 获取数据字段的类型
201
+ */
202
+ function getDataFieldDisplayType(format) {
203
+ const nameMap = {
204
+ email: 'email',
205
+ url: 'url',
206
+ tel: 'tel',
207
+ phone: 'phone',
208
+ 'x-image': 'image',
209
+ 'x-rtf': 'rtf',
210
+ datetime: 'datetime',
211
+ date: 'date',
212
+ time: 'time',
213
+ 'x-enum': 'enum',
214
+ 'x-location': 'location',
215
+ 'x-file': 'file',
216
+ related: 'related',
217
+ 'father-son': 'father-son',
218
+ 'x-autonumber': 'autonumber',
219
+ 'x-area-code': 'area-code',
220
+ function: 'function',
221
+ };
222
+ return nameMap[format];
223
+ }
224
+ /**
225
+ * 处理注释信息
226
+ */
227
+ function _handleComment(inputData, group, needKeepSchema) {
228
+ const _inputData = (0, cloneDeep_1.default)(inputData);
229
+ json_easy_filter_1.default.traverse(_inputData, function (key, value, path) {
230
+ var _a;
231
+ if ((value === null || value === void 0 ? void 0 : value.type) && !((_a = value === null || value === void 0 ? void 0 : value.type) === null || _a === void 0 ? void 0 : _a.type)) {
232
+ // value?.type?.type 有值,则证明 type 是自定义的字段,而非 JSONSchema 中的 type
233
+ let schema = null;
234
+ if (needKeepSchema) {
235
+ const isFirstLevel = path.length === 2 && (path === null || path === void 0 ? void 0 : path[0]) === 'properties';
236
+ if (isFirstLevel) {
237
+ // 只需要第一级属性需要保存,且只保存子信息(对象或数组的子项)
238
+ schema = value.properties || value.items ? value : null;
239
+ }
240
+ }
241
+ // 特殊处理数据字段的类型
242
+ let type = value.type;
243
+ if (group === GroupEnum.DATA_FIELD) {
244
+ type = getDataFieldDisplayType(value.format) || type;
245
+ }
246
+ value.description = genWeDaCodeComment({
247
+ fieldName: key,
248
+ title: value.title,
249
+ description: value.description,
250
+ group,
251
+ type,
252
+ dataFieldInfo: (0, pick_1.default)(value, ['type', 'format', 'x-system']),
253
+ schema,
254
+ });
255
+ }
256
+ });
257
+ _inputData.description = ''; // 避免第一层出现注释
258
+ return _inputData;
259
+ }
260
+ /**
261
+ * 获取用于显示的数据类型(仅有 number, string , boolean, array, object 等内置基础类型)
262
+ */
263
+ function getDisplayReturnType(typeStr) {
264
+ let displayType = typeStr.trim();
265
+ if (displayType.endsWith('[]')) {
266
+ displayType = 'array';
267
+ }
268
+ else if (displayType.endsWith('}')) {
269
+ displayType = 'object';
270
+ }
271
+ return displayType;
272
+ }
273
+ /**
274
+ * 获取组件接口定义名称
275
+ */
276
+ function _genCompInterfaceName(module, component) {
277
+ return `${module.replace(/-/g, '_')}_${component}`;
278
+ }
279
+ function _compile(jsonschema, isObjNeedWrapper = false) {
280
+ return __awaiter(this, void 0, void 0, function* () {
281
+ let dts = yield compileJSONToDTS(jsonschema);
282
+ if (dts.search(/^export interface IWeDa/) >= 0) {
283
+ dts = dts.replace(/^export interface.*$/m, '');
284
+ dts = dts.substring(0, dts.length - 2);
285
+ if (isObjNeedWrapper) {
286
+ dts = `{${dts}}`;
287
+ }
288
+ }
289
+ else {
290
+ dts = dts.replace(/^export type IWeDa =/m, '');
291
+ }
292
+ return dts;
293
+ });
294
+ }
154
295
  const hanlderMap = {
296
+ [IInputDataType.globalState]: function (inputData) {
297
+ return __awaiter(this, void 0, void 0, function* () {
298
+ // 完善注释信息
299
+ const handledInputData = _handleComment(inputData, GroupEnum.GLOBAL_VAR, true);
300
+ return yield _compile(handledInputData);
301
+ });
302
+ },
303
+ [IInputDataType.pageState]: function (inputData) {
304
+ return __awaiter(this, void 0, void 0, function* () {
305
+ // 完善注释信息
306
+ const handledInputData = _handleComment(inputData, GroupEnum.PAGE_VAR, true);
307
+ return yield _compile(handledInputData);
308
+ });
309
+ },
310
+ [IInputDataType.pageParams]: function (inputData) {
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ // 完善注释信息
313
+ const handledInputData = _handleComment(inputData, GroupEnum.PAGE_PARAM);
314
+ return yield _compile(handledInputData);
315
+ });
316
+ },
155
317
  [IInputDataType.globalCommonCodes]: function (inputData) {
156
318
  return __awaiter(this, void 0, void 0, function* () {
157
319
  const dts = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
@@ -195,9 +357,11 @@ function _generateOneItemDTS(inputData, itemType) {
195
357
  },
196
358
  [IInputDataType.compPropEvents]: function (inputData) {
197
359
  const IData = `any`;
198
- return inputData.map(eventName => {
360
+ return inputData
361
+ .map((eventName) => {
199
362
  return `function ${eventName}(data?: ${IData}): void`;
200
- }).join('\n');
363
+ })
364
+ .join('\n');
201
365
  },
202
366
  [IInputDataType.usedComponents]: function (inputData) {
203
367
  return __awaiter(this, void 0, void 0, function* () {
@@ -205,7 +369,8 @@ function _generateOneItemDTS(inputData, itemType) {
205
369
  // 属性
206
370
  let exportPropertiesDTS = '';
207
371
  if (item.exportProperties) {
208
- exportPropertiesDTS = yield _compile(item.exportProperties);
372
+ const handledProperties = _handleComment(item.exportProperties);
373
+ exportPropertiesDTS = yield _compile(handledProperties);
209
374
  }
210
375
  // 方法
211
376
  let exportMethodsDTS = '';
@@ -238,8 +403,18 @@ function _generateOneItemDTS(inputData, itemType) {
238
403
  // ${exportMethodsDTS}
239
404
  // }
240
405
  // `
406
+ const interfaceName = _genCompInterfaceName(item.module, item.component);
241
407
  return `
242
- declare class ${_genCompInterfaceName(item.module, item.component)} extends UserWidget {
408
+ /**
409
+ ${genWeDaCodeComment({
410
+ fieldName: interfaceName,
411
+ schema: item.exportProperties,
412
+ })
413
+ .split('\n')
414
+ .map((item) => `* ${item}`)
415
+ .join('\n')}
416
+ */
417
+ declare class ${interfaceName} extends UserWidget {
243
418
 
244
419
  ${exportPropertiesDTS}
245
420
 
@@ -251,21 +426,162 @@ function _generateOneItemDTS(inputData, itemType) {
251
426
  });
252
427
  },
253
428
  [IInputDataType.usedWidgets]: function (inputData) {
254
- return inputData.map(item => {
429
+ return inputData
430
+ .map((item) => {
255
431
  if (item.idList && item.idList.length > 0) {
256
432
  const interfaceName = _genCompInterfaceName(item.module, item.component);
257
- return item.idList.map(id => `const ${id}: ${interfaceName}`).join('\n');
433
+ return item.idList
434
+ .map((id) => `
435
+ /**
436
+ ${genWeDaCodeComment({
437
+ fieldName: id,
438
+ title: '',
439
+ description: '',
440
+ group: GroupEnum.COMPONENT,
441
+ type: 'component',
442
+ baseClass: interfaceName,
443
+ datasource: `$${id}_start$ $${id}_end$`,
444
+ })
445
+ .split('\n')
446
+ .map((item) => `* ${item}`)
447
+ .join('\n')}
448
+ */
449
+ const ${id}: ${interfaceName}`)
450
+ .join('\n');
258
451
  }
259
452
  return '';
260
- }).join('\n');
453
+ })
454
+ .join('\n');
261
455
  },
262
456
  [IInputDataType.repeaterScope]: function (inputData) {
263
457
  return __awaiter(this, void 0, void 0, function* () {
264
458
  const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
265
- let itemDataDTS = yield _compile(item.itemData, true);
459
+ let itemDataDTS = '';
460
+ if (item.itemData.title) {
461
+ // 特殊场景:数据字段
462
+ const handledInputData = _handleComment(item.itemData, GroupEnum.DATA_FIELD);
463
+ itemDataDTS = yield _compile(handledInputData, true);
464
+ }
465
+ else {
466
+ // 普通的循环项数据
467
+ itemDataDTS = yield _compile(item.itemData, true);
468
+ }
266
469
  return `
470
+ /**
471
+ ${genWeDaCodeComment({
472
+ fieldName: item.currentItemAlias,
473
+ title: '当前项值',
474
+ description: '',
475
+ group: GroupEnum.REPEATER,
476
+ type: getDisplayReturnType(itemDataDTS),
477
+ schema: item.itemData,
478
+ subGroup: item.widgetId,
479
+ })
480
+ .split('\n')
481
+ .map((item) => `* ${item}`)
482
+ .join('\n')}
483
+ */
267
484
  const ${item.currentItemAlias}: ${itemDataDTS}
485
+ /**
486
+ ${genWeDaCodeComment({
487
+ fieldName: item.currentIndexAlias,
488
+ title: '当前下标',
489
+ description: '',
490
+ group: GroupEnum.REPEATER,
491
+ type: 'number',
492
+ subGroup: item.widgetId,
493
+ })
494
+ .split('\n')
495
+ .map((item) => `* ${item}`)
496
+ .join('\n')}
497
+ */
268
498
  const ${item.currentIndexAlias}: number
499
+ `;
500
+ })));
501
+ return results.join('\n');
502
+ });
503
+ },
504
+ [IInputDataType.redefineAnyType]: function (inputData) {
505
+ return __awaiter(this, void 0, void 0, function* () {
506
+ const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
507
+ const compInterfaceName = _genCompInterfaceName(item.module, item.component);
508
+ const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
509
+ /**
510
+ * 更新 widget 的类型名
511
+ */
512
+ replaceRules.push({
513
+ from: new RegExp(`(const ${item.widgetId}): .*`),
514
+ to: `$1: ${widgetInterfaceName}`,
515
+ });
516
+ /**
517
+ * 增加类
518
+ */
519
+ const datasources = {};
520
+ const propDefinitions = yield Promise.all(item.updateProps.map((prop) => __awaiter(this, void 0, void 0, function* () {
521
+ const properties = _handleComment(prop.widgetPropTypeSchema, GroupEnum.DATA_FIELD);
522
+ const widgetPropTypeDTS = yield _compile(Object.assign(Object.assign({}, prop.widgetPropTypeSchema), properties), true);
523
+ // 同个数据源,有可能是数组类型,所以需要区分开
524
+ const id = `${prop.datasource.name}_${prop.widgetPropTypeSchema.type}`;
525
+ if (!datasources[id]) {
526
+ datasources[id] = {
527
+ fields: [{ name: prop.widgetPropName, title: prop.widgetPropTitle }],
528
+ schema: prop.widgetPropTypeSchema,
529
+ name: prop.datasource.name,
530
+ title: prop.datasource.title,
531
+ id: prop.datasource.id,
532
+ type: prop.datasource.type,
533
+ };
534
+ }
535
+ else {
536
+ datasources[id].fields.push({ name: prop.widgetPropName, title: prop.widgetPropTitle });
537
+ }
538
+ // 是否是多层级字段,如 "a.b"
539
+ // FIXME: 当前只支持 a.b 这种形式,不支持 a[].b
540
+ const multiLevelField = prop.widgetPropName.includes('.');
541
+ let multiLevelFields = [];
542
+ let multiLevelFieldObj = {};
543
+ let firstField = '';
544
+ let othersFields = [];
545
+ if (multiLevelField) {
546
+ multiLevelFields = prop.widgetPropName.split('.');
547
+ (0, set_1.default)(multiLevelFieldObj, prop.widgetPropName, '$$schema$$');
548
+ const [_firstField, ..._othersFields] = multiLevelFields;
549
+ firstField = _firstField;
550
+ othersFields = _othersFields;
551
+ }
552
+ return `
553
+ /**
554
+ ${genWeDaCodeComment({
555
+ fieldName: prop.widgetPropName,
556
+ title: prop.widgetPropTypeSchema.title,
557
+ description: prop.widgetPropTypeSchema.description,
558
+ group: undefined,
559
+ type: getDisplayReturnType(widgetPropTypeDTS),
560
+ })
561
+ .split('\n')
562
+ .map((item) => `* ${item}`)
563
+ .join('\n')}
564
+ */
565
+ ${multiLevelField
566
+ ? `${firstField}: Omit<${compInterfaceName}['${firstField}'], '${othersFields.join('.')}'> & ${JSON.stringify(multiLevelFieldObj[firstField]).replace('"$$schema$$"', widgetPropTypeDTS)}`
567
+ : `${prop.widgetPropName}: ${widgetPropTypeDTS}`}
568
+ `;
569
+ })));
570
+ /**
571
+ * 更新数据源信息
572
+ */
573
+ const datasourceInfoList = Object.values(datasources);
574
+ if (datasourceInfoList.length > 0) {
575
+ replaceRules.push({
576
+ from: new RegExp(`(\\$${item.widgetId}_start\\$).*(\\$${item.widgetId}_end\\$)`),
577
+ // encodeURIComponent 是为了能正常 parse 成 JSON
578
+ to: `$1${encodeURIComponent(JSON.stringify(datasourceInfoList))}$2`,
579
+ });
580
+ }
581
+ return `
582
+ declare class ${widgetInterfaceName} extends ${compInterfaceName} {
583
+ ${propDefinitions.join('\n')}
584
+ }
269
585
  `;
270
586
  })));
271
587
  return results.join('\n');
@@ -274,33 +590,14 @@ function _generateOneItemDTS(inputData, itemType) {
274
590
  };
275
591
  let dts = '';
276
592
  if (!inputData)
277
- return dts;
593
+ return [dts, replaceRules];
278
594
  const handler = hanlderMap[itemType];
279
595
  // 优先判断是否有独立的处理逻辑
280
596
  if (handler) {
281
597
  dts = yield handler.call(hanlderMap, inputData);
282
598
  }
283
599
  dts = dts || (yield _compile(inputData));
284
- return dts;
285
- function _genCompInterfaceName(module, component) {
286
- return `${module.replace(/-/g, '_')}_${component}`;
287
- }
288
- function _compile(jsonschema, isObjNeedWrapper = false) {
289
- return __awaiter(this, void 0, void 0, function* () {
290
- let dts = yield compileJSONToDTS(jsonschema);
291
- if (dts.search(/^export interface IWeDa/) >= 0) {
292
- dts = dts.replace(/^export interface.*$/m, '');
293
- dts = dts.substring(0, dts.length - 2);
294
- if (isObjNeedWrapper) {
295
- dts = `{${dts}}`;
296
- }
297
- }
298
- else {
299
- dts = dts.replace(/^export type IWeDa =/m, '');
300
- }
301
- return dts;
302
- });
303
- }
600
+ return [dts, replaceRules];
304
601
  });
305
602
  }
306
603
  // 仅仅为了与 unittest 共享,外部请不要使用
@@ -380,20 +677,18 @@ function TypescriptWorker(workerId, workerCode) {
380
677
  typescriptWorker.onmessage = function (event) {
381
678
  const { action } = event.data;
382
679
  if (action === 'dts_back') {
383
- const { data: { id, dts } } = event.data;
680
+ const { data: { id, dts }, } = event.data;
384
681
  sendMessageCallbackFn[id] && sendMessageCallbackFn[id](dts);
385
682
  }
386
683
  };
387
684
  typescriptWorkerMap[workerId] = {
388
685
  typescriptWorker,
389
- sendMessageCallbackFn
686
+ sendMessageCallbackFn,
390
687
  };
391
688
  }
392
689
  function sendMessage(msgData, callbackFn) {
393
690
  const { typescriptWorker, sendMessageCallbackFn } = typescriptWorkerMap[workerId];
394
- const id = Math.random()
395
- .toString(36)
396
- .substring(2, 5);
691
+ const id = Math.random().toString(36).substring(2, 5);
397
692
  msgData.data.id = id;
398
693
  sendMessageCallbackFn[id] = callbackFn;
399
694
  typescriptWorker.postMessage(msgData);
@@ -402,22 +697,22 @@ function TypescriptWorker(workerId, workerCode) {
402
697
  };
403
698
  }
404
699
  /**
405
- * 使用:
406
- * const typescriptWorker = getTypescriptWorker();
407
- * typescriptWorker.sendMessage({ action: 'dts', data: { code } }, dts => {
408
- *
409
- * })
410
- * // 以下暂未实现
411
- * typescriptWorker.sendMessage({ action: 'ts', data: { code } }, ts => {
412
- *
413
- * })
414
- */
700
+ * 使用:
701
+ * const typescriptWorker = getTypescriptWorker();
702
+ * typescriptWorker.sendMessage({ action: 'dts', data: { code } }, dts => {
703
+ *
704
+ * })
705
+ * // 以下暂未实现
706
+ * typescriptWorker.sendMessage({ action: 'ts', data: { code } }, ts => {
707
+ *
708
+ * })
709
+ */
415
710
  const getTypescriptWorker = TypescriptWorker('transpileToDTS', exports.workerCode);
416
711
  /**
417
712
  * 通过 js/ts 代码生成 dts
418
713
  */
419
714
  function transpileToDTS(code) {
420
- return new Promise(resolve => {
715
+ return new Promise((resolve) => {
421
716
  const typescriptWorker = getTypescriptWorker();
422
717
  typescriptWorker.sendMessage({ action: 'dts', data: { code } }, (dts) => {
423
718
  resolve(dts);
@@ -15,7 +15,7 @@ exports.version4 = version4;
15
15
  const transformPxLowcodeCompAndSourceComp = (cals, isUpgrade, setSchemaVersionCallback) => {
16
16
  var _a, _b, _c, _d;
17
17
  {
18
- function transformCals(items, isUpgradeToPx) {
18
+ const transformCals = (items, isUpgradeToPx) => {
19
19
  return items.map((item) => {
20
20
  var _a;
21
21
  // 对于表单操作区的按钮组件的父容器添加.wd-form__action, 兼容组件规范化按钮升级样式
@@ -52,7 +52,7 @@ const transformPxLowcodeCompAndSourceComp = (cals, isUpgrade, setSchemaVersionCa
52
52
  }
53
53
  return item;
54
54
  });
55
- }
55
+ };
56
56
  let pages = cals['items'];
57
57
  let isDivision;
58
58
  if (isUpgrade && (0, common_1.semverComp)((_a = cals['schemaVersion']) !== null && _a !== void 0 ? _a : '3.0.0', '4.0.0') < 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "1.0.3-alpha.14",
3
+ "version": "1.0.3-alpha.16",
4
4
  "description": "Common application specifications",
5
5
  "main": "lib/utils/index.js",
6
6
  "source": "src/utils/index.ts",
@@ -30,6 +30,7 @@
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
32
  "acorn": "^8.0.4",
33
+ "json-easy-filter": "^0.3.1",
33
34
  "json-schema-to-typescript-for-browser": "^11.0.3",
34
35
  "lodash": "^4.17.20",
35
36
  "postcss": "^8.4.20",