@cloudbase/cals 1.0.3-alpha.9 → 1.0.4-alpha.0

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 (112) hide show
  1. package/lib/parser/cals/index.d.ts +1 -9
  2. package/lib/parser/cals/index.d.ts.map +1 -1
  3. package/lib/parser/cals/index.js +21 -75
  4. package/lib/parser/cals/utils/block/index.d.ts +0 -0
  5. package/lib/parser/cals/utils/block/index.d.ts.map +1 -1
  6. package/lib/parser/cals/utils/block/index.js +7 -3
  7. package/lib/parser/cals/utils/code/index.d.ts +0 -0
  8. package/lib/parser/cals/utils/code/index.d.ts.map +1 -1
  9. package/lib/parser/cals/utils/code/index.js +18 -12
  10. package/lib/parser/cals/utils/common.d.ts +0 -0
  11. package/lib/parser/cals/utils/common.d.ts.map +0 -0
  12. package/lib/parser/cals/utils/common.js +0 -0
  13. package/lib/parser/cals/utils/runtime.d.ts +0 -0
  14. package/lib/parser/cals/utils/runtime.d.ts.map +1 -1
  15. package/lib/parser/cals/utils/runtime.js +5 -2
  16. package/lib/parser/cals/utils/spinoff/index.d.ts +0 -0
  17. package/lib/parser/cals/utils/spinoff/index.d.ts.map +0 -0
  18. package/lib/parser/cals/utils/spinoff/index.js +0 -0
  19. package/lib/parser/cals/utils/style.d.ts +0 -0
  20. package/lib/parser/cals/utils/style.d.ts.map +1 -1
  21. package/lib/parser/cals/utils/style.js +7 -3
  22. package/lib/parser/cals/utils/template.d.ts +0 -0
  23. package/lib/parser/cals/utils/template.d.ts.map +0 -0
  24. package/lib/parser/cals/utils/template.js +0 -0
  25. package/lib/parser/cals/utils/version/common.d.ts +0 -0
  26. package/lib/parser/cals/utils/version/common.d.ts.map +1 -1
  27. package/lib/parser/cals/utils/version/common.js +16 -33
  28. package/lib/parser/cals/utils/version/config.d.ts +0 -0
  29. package/lib/parser/cals/utils/version/config.d.ts.map +0 -0
  30. package/lib/parser/cals/utils/version/config.js +0 -0
  31. package/lib/parser/cals/utils/version/index.d.ts +0 -0
  32. package/lib/parser/cals/utils/version/index.d.ts.map +0 -0
  33. package/lib/parser/cals/utils/version/index.js +0 -0
  34. package/lib/parser/cals/utils/version/parses.d.ts +0 -0
  35. package/lib/parser/cals/utils/version/parses.d.ts.map +1 -1
  36. package/lib/parser/cals/utils/version/parses.js +18 -36
  37. package/lib/parser/cals/utils/version/utils.d.ts +0 -0
  38. package/lib/parser/cals/utils/version/utils.d.ts.map +0 -0
  39. package/lib/parser/cals/utils/version/utils.js +5 -2
  40. package/lib/parser/expression/index.d.ts +0 -0
  41. package/lib/parser/expression/index.d.ts.map +0 -0
  42. package/lib/parser/expression/index.js +0 -0
  43. package/lib/parser/index.d.ts +0 -0
  44. package/lib/parser/index.d.ts.map +0 -0
  45. package/lib/parser/index.js +0 -0
  46. package/lib/parser/plugins/postcss-rpx2clac.js +2 -2
  47. package/lib/types/basic/app.d.ts +0 -0
  48. package/lib/types/basic/app.d.ts.map +0 -0
  49. package/lib/types/basic/app.js +0 -0
  50. package/lib/types/basic/common.d.ts +1 -1
  51. package/lib/types/basic/common.d.ts.map +1 -1
  52. package/lib/types/basic/common.js +0 -0
  53. package/lib/types/basic/component.d.ts +0 -5
  54. package/lib/types/basic/component.d.ts.map +1 -1
  55. package/lib/types/basic/component.js +0 -0
  56. package/lib/types/basic/datasource.d.ts +0 -0
  57. package/lib/types/basic/datasource.d.ts.map +0 -0
  58. package/lib/types/basic/datasource.js +0 -0
  59. package/lib/types/index.d.ts +1 -2
  60. package/lib/types/index.d.ts.map +1 -1
  61. package/lib/types/index.js +14 -1
  62. package/lib/types/lcds.d.ts +324 -211
  63. package/lib/types/lcds.d.ts.map +1 -1
  64. package/lib/types/lcds.js +0 -0
  65. package/lib/types/platform/app.d.ts +0 -0
  66. package/lib/types/platform/app.d.ts.map +0 -0
  67. package/lib/types/platform/app.js +0 -0
  68. package/lib/types/platform/common.d.ts +1 -11
  69. package/lib/types/platform/common.d.ts.map +1 -1
  70. package/lib/types/platform/common.js +0 -0
  71. package/lib/types/platform/component.d.ts +0 -5
  72. package/lib/types/platform/component.d.ts.map +1 -1
  73. package/lib/types/platform/component.js +0 -0
  74. package/lib/types/platform/datasource.d.ts +0 -0
  75. package/lib/types/platform/datasource.d.ts.map +0 -0
  76. package/lib/types/platform/datasource.js +0 -0
  77. package/lib/types/platform/widget/form.d.ts +0 -0
  78. package/lib/types/platform/widget/form.d.ts.map +0 -0
  79. package/lib/types/platform/widget/form.js +0 -0
  80. package/lib/types/platform/widget/meta.d.ts +0 -0
  81. package/lib/types/platform/widget/meta.d.ts.map +0 -0
  82. package/lib/types/platform/widget/meta.js +0 -0
  83. package/lib/utils/CSSProperty.d.ts +0 -0
  84. package/lib/utils/CSSProperty.d.ts.map +0 -0
  85. package/lib/utils/CSSProperty.js +0 -0
  86. package/lib/utils/build.d.ts +0 -0
  87. package/lib/utils/build.d.ts.map +0 -0
  88. package/lib/utils/build.js +3 -3
  89. package/lib/utils/constant.d.ts +0 -0
  90. package/lib/utils/constant.d.ts.map +0 -0
  91. package/lib/utils/constant.js +0 -0
  92. package/lib/utils/dts/auto-generated.d.ts +1 -1
  93. package/lib/utils/dts/auto-generated.d.ts.map +1 -1
  94. package/lib/utils/dts/auto-generated.js +1227 -35
  95. package/lib/utils/dts/build.js +1 -4
  96. package/lib/utils/dts/index.d.ts +41 -4
  97. package/lib/utils/dts/index.d.ts.map +1 -1
  98. package/lib/utils/dts/index.js +384 -66
  99. package/lib/utils/index.d.ts +0 -0
  100. package/lib/utils/index.d.ts.map +0 -0
  101. package/lib/utils/index.js +0 -0
  102. package/lib/utils/version/migrations/version4.js +2 -2
  103. package/package.json +2 -1
  104. package/lib/parser/constants.d.ts +0 -2
  105. package/lib/parser/constants.d.ts.map +0 -1
  106. package/lib/parser/constants.js +0 -4
  107. package/lib/types/platform/eventFlow.d.ts +0 -20
  108. package/lib/types/platform/eventFlow.d.ts.map +0 -1
  109. package/lib/types/platform/eventFlow.js +0 -2
  110. package/lib/types/platform/query.d.ts +0 -58
  111. package/lib/types/platform/query.d.ts.map +0 -1
  112. package/lib/types/platform/query.js +0 -2
@@ -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,17 +357,36 @@ 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* () {
368
+ // 组件系统属性(在 framework/weda-framework.d.ts 的 UserWidget 中筛选一部分)
369
+ const commonProperties = {
370
+ id: {
371
+ type: 'string',
372
+ title: '组件 ID',
373
+ describe: '组件 ID,微搭中一般由编辑器生成'
374
+ },
375
+ module: {
376
+ type: 'string',
377
+ title: '组件库名',
378
+ },
379
+ component: {
380
+ type: 'string',
381
+ title: '组件名',
382
+ }
383
+ };
204
384
  const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
205
385
  // 属性
206
386
  let exportPropertiesDTS = '';
207
387
  if (item.exportProperties) {
208
- exportPropertiesDTS = yield _compile(item.exportProperties);
388
+ const handledProperties = _handleComment(item.exportProperties);
389
+ exportPropertiesDTS = yield _compile(handledProperties);
209
390
  }
210
391
  // 方法
211
392
  let exportMethodsDTS = '';
@@ -238,8 +419,25 @@ function _generateOneItemDTS(inputData, itemType) {
238
419
  // ${exportMethodsDTS}
239
420
  // }
240
421
  // `
422
+ const interfaceName = _genCompInterfaceName(item.module, item.component);
423
+ if (!item.exportProperties) {
424
+ item.exportProperties = {
425
+ type: 'object',
426
+ properties: {}
427
+ };
428
+ }
429
+ item.exportProperties.properties = Object.assign({}, commonProperties, item.exportProperties.properties);
241
430
  return `
242
- declare class ${_genCompInterfaceName(item.module, item.component)} extends UserWidget {
431
+ /**
432
+ ${genWeDaCodeComment({
433
+ fieldName: interfaceName,
434
+ schema: item.exportProperties,
435
+ })
436
+ .split('\n')
437
+ .map((item) => `* ${item}`)
438
+ .join('\n')}
439
+ */
440
+ declare class ${interfaceName} extends UserWidget {
243
441
 
244
442
  ${exportPropertiesDTS}
245
443
 
@@ -251,21 +449,162 @@ function _generateOneItemDTS(inputData, itemType) {
251
449
  });
252
450
  },
253
451
  [IInputDataType.usedWidgets]: function (inputData) {
254
- return inputData.map(item => {
452
+ return inputData
453
+ .map((item) => {
255
454
  if (item.idList && item.idList.length > 0) {
256
455
  const interfaceName = _genCompInterfaceName(item.module, item.component);
257
- return item.idList.map(id => `const ${id}: ${interfaceName}`).join('\n');
456
+ return item.idList
457
+ .map((id) => `
458
+ /**
459
+ ${genWeDaCodeComment({
460
+ fieldName: id,
461
+ title: '',
462
+ description: '',
463
+ group: GroupEnum.COMPONENT,
464
+ type: 'component',
465
+ baseClass: interfaceName,
466
+ datasource: `$${id}_start$ $${id}_end$`,
467
+ })
468
+ .split('\n')
469
+ .map((item) => `* ${item}`)
470
+ .join('\n')}
471
+ */
472
+ const ${id}: ${interfaceName}`)
473
+ .join('\n');
258
474
  }
259
475
  return '';
260
- }).join('\n');
476
+ })
477
+ .join('\n');
261
478
  },
262
479
  [IInputDataType.repeaterScope]: function (inputData) {
263
480
  return __awaiter(this, void 0, void 0, function* () {
264
481
  const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
265
- let itemDataDTS = yield _compile(item.itemData, true);
482
+ let itemDataDTS = '';
483
+ if (item.itemData.title) {
484
+ // 特殊场景:数据字段
485
+ const handledInputData = _handleComment(item.itemData, GroupEnum.DATA_FIELD);
486
+ itemDataDTS = yield _compile(handledInputData, true);
487
+ }
488
+ else {
489
+ // 普通的循环项数据
490
+ itemDataDTS = yield _compile(item.itemData, true);
491
+ }
266
492
  return `
493
+ /**
494
+ ${genWeDaCodeComment({
495
+ fieldName: item.currentItemAlias,
496
+ title: '当前项值',
497
+ description: '',
498
+ group: GroupEnum.REPEATER,
499
+ type: getDisplayReturnType(itemDataDTS),
500
+ schema: item.itemData,
501
+ subGroup: item.widgetId,
502
+ })
503
+ .split('\n')
504
+ .map((item) => `* ${item}`)
505
+ .join('\n')}
506
+ */
267
507
  const ${item.currentItemAlias}: ${itemDataDTS}
508
+ /**
509
+ ${genWeDaCodeComment({
510
+ fieldName: item.currentIndexAlias,
511
+ title: '当前下标',
512
+ description: '',
513
+ group: GroupEnum.REPEATER,
514
+ type: 'number',
515
+ subGroup: item.widgetId,
516
+ })
517
+ .split('\n')
518
+ .map((item) => `* ${item}`)
519
+ .join('\n')}
520
+ */
268
521
  const ${item.currentIndexAlias}: number
522
+ `;
523
+ })));
524
+ return results.join('\n');
525
+ });
526
+ },
527
+ [IInputDataType.redefineAnyType]: function (inputData) {
528
+ return __awaiter(this, void 0, void 0, function* () {
529
+ const results = yield Promise.all(inputData.map((item) => __awaiter(this, void 0, void 0, function* () {
530
+ const compInterfaceName = _genCompInterfaceName(item.module, item.component);
531
+ const widgetInterfaceName = `${item.widgetId}_${compInterfaceName}`;
532
+ /**
533
+ * 更新 widget 的类型名
534
+ */
535
+ replaceRules.push({
536
+ from: new RegExp(`(const ${item.widgetId}): .*`),
537
+ to: `$1: ${widgetInterfaceName}`,
538
+ });
539
+ /**
540
+ * 增加类
541
+ */
542
+ const datasources = {};
543
+ const propDefinitions = yield Promise.all(item.updateProps.map((prop) => __awaiter(this, void 0, void 0, function* () {
544
+ const properties = _handleComment(prop.widgetPropTypeSchema, GroupEnum.DATA_FIELD);
545
+ const widgetPropTypeDTS = yield _compile(Object.assign(Object.assign({}, prop.widgetPropTypeSchema), properties), true);
546
+ // 同个数据源,有可能是数组类型,所以需要区分开
547
+ const id = `${prop.datasource.name}_${prop.widgetPropTypeSchema.type}`;
548
+ if (!datasources[id]) {
549
+ datasources[id] = {
550
+ fields: [{ name: prop.widgetPropName, title: prop.widgetPropTitle }],
551
+ schema: prop.widgetPropTypeSchema,
552
+ name: prop.datasource.name,
553
+ title: prop.datasource.title,
554
+ id: prop.datasource.id,
555
+ type: prop.datasource.type,
556
+ };
557
+ }
558
+ else {
559
+ datasources[id].fields.push({ name: prop.widgetPropName, title: prop.widgetPropTitle });
560
+ }
561
+ // 是否是多层级字段,如 "a.b"
562
+ // FIXME: 当前只支持 a.b 这种形式,不支持 a[].b
563
+ const multiLevelField = prop.widgetPropName.includes('.');
564
+ let multiLevelFields = [];
565
+ let multiLevelFieldObj = {};
566
+ let firstField = '';
567
+ let othersFields = [];
568
+ if (multiLevelField) {
569
+ multiLevelFields = prop.widgetPropName.split('.');
570
+ (0, set_1.default)(multiLevelFieldObj, prop.widgetPropName, '$$schema$$');
571
+ const [_firstField, ..._othersFields] = multiLevelFields;
572
+ firstField = _firstField;
573
+ othersFields = _othersFields;
574
+ }
575
+ return `
576
+ /**
577
+ ${genWeDaCodeComment({
578
+ fieldName: prop.widgetPropName,
579
+ title: prop.widgetPropTypeSchema.title,
580
+ description: prop.widgetPropTypeSchema.description,
581
+ group: undefined,
582
+ type: getDisplayReturnType(widgetPropTypeDTS),
583
+ })
584
+ .split('\n')
585
+ .map((item) => `* ${item}`)
586
+ .join('\n')}
587
+ */
588
+ ${multiLevelField
589
+ ? `${firstField}: Omit<${compInterfaceName}['${firstField}'], '${othersFields.join('.')}'> & ${JSON.stringify(multiLevelFieldObj[firstField]).replace('"$$schema$$"', widgetPropTypeDTS)}`
590
+ : `${prop.widgetPropName}: ${widgetPropTypeDTS}`}
591
+ `;
592
+ })));
593
+ /**
594
+ * 更新数据源信息
595
+ */
596
+ const datasourceInfoList = Object.values(datasources);
597
+ if (datasourceInfoList.length > 0) {
598
+ replaceRules.push({
599
+ from: new RegExp(`(\\$${item.widgetId}_start\\$).*(\\$${item.widgetId}_end\\$)`),
600
+ // encodeURIComponent 是为了能正常 parse 成 JSON
601
+ to: `$1${encodeURIComponent(JSON.stringify(datasourceInfoList))}$2`,
602
+ });
603
+ }
604
+ return `
605
+ declare class ${widgetInterfaceName} extends ${compInterfaceName} {
606
+ ${propDefinitions.join('\n')}
607
+ }
269
608
  `;
270
609
  })));
271
610
  return results.join('\n');
@@ -274,33 +613,14 @@ function _generateOneItemDTS(inputData, itemType) {
274
613
  };
275
614
  let dts = '';
276
615
  if (!inputData)
277
- return dts;
616
+ return [dts, replaceRules];
278
617
  const handler = hanlderMap[itemType];
279
618
  // 优先判断是否有独立的处理逻辑
280
619
  if (handler) {
281
620
  dts = yield handler.call(hanlderMap, inputData);
282
621
  }
283
622
  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
- }
623
+ return [dts, replaceRules];
304
624
  });
305
625
  }
306
626
  // 仅仅为了与 unittest 共享,外部请不要使用
@@ -380,20 +700,18 @@ function TypescriptWorker(workerId, workerCode) {
380
700
  typescriptWorker.onmessage = function (event) {
381
701
  const { action } = event.data;
382
702
  if (action === 'dts_back') {
383
- const { data: { id, dts } } = event.data;
703
+ const { data: { id, dts }, } = event.data;
384
704
  sendMessageCallbackFn[id] && sendMessageCallbackFn[id](dts);
385
705
  }
386
706
  };
387
707
  typescriptWorkerMap[workerId] = {
388
708
  typescriptWorker,
389
- sendMessageCallbackFn
709
+ sendMessageCallbackFn,
390
710
  };
391
711
  }
392
712
  function sendMessage(msgData, callbackFn) {
393
713
  const { typescriptWorker, sendMessageCallbackFn } = typescriptWorkerMap[workerId];
394
- const id = Math.random()
395
- .toString(36)
396
- .substring(2, 5);
714
+ const id = Math.random().toString(36).substring(2, 5);
397
715
  msgData.data.id = id;
398
716
  sendMessageCallbackFn[id] = callbackFn;
399
717
  typescriptWorker.postMessage(msgData);
@@ -402,22 +720,22 @@ function TypescriptWorker(workerId, workerCode) {
402
720
  };
403
721
  }
404
722
  /**
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
- */
723
+ * 使用:
724
+ * const typescriptWorker = getTypescriptWorker();
725
+ * typescriptWorker.sendMessage({ action: 'dts', data: { code } }, dts => {
726
+ *
727
+ * })
728
+ * // 以下暂未实现
729
+ * typescriptWorker.sendMessage({ action: 'ts', data: { code } }, ts => {
730
+ *
731
+ * })
732
+ */
415
733
  const getTypescriptWorker = TypescriptWorker('transpileToDTS', exports.workerCode);
416
734
  /**
417
735
  * 通过 js/ts 代码生成 dts
418
736
  */
419
737
  function transpileToDTS(code) {
420
- return new Promise(resolve => {
738
+ return new Promise((resolve) => {
421
739
  const typescriptWorker = getTypescriptWorker();
422
740
  typescriptWorker.sendMessage({ action: 'dts', data: { code } }, (dts) => {
423
741
  resolve(dts);
File without changes
File without changes
File without changes
@@ -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.9",
3
+ "version": "1.0.4-alpha.0",
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",
@@ -1,2 +0,0 @@
1
- export declare const OFFICIAL_LIB_KEY = "gsd-h5-react";
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/parser/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,iBAAiB,CAAC"}
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OFFICIAL_LIB_KEY = void 0;
4
- exports.OFFICIAL_LIB_KEY = 'gsd-h5-react';