@cloudbase/cals 1.0.50 → 1.0.52-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 (93) hide show
  1. package/lib/parser/cals/index.d.ts.map +1 -1
  2. package/lib/parser/cals/index.js +8 -6
  3. package/lib/parser/cals/utils/block/index.js +151 -0
  4. package/lib/parser/cals/utils/code/index.js +393 -0
  5. package/lib/parser/cals/utils/common.js +268 -0
  6. package/lib/parser/cals/utils/getUsedResources.d.ts +10 -0
  7. package/lib/parser/cals/utils/getUsedResources.d.ts.map +1 -0
  8. package/lib/parser/cals/utils/getUsedResources.js +128 -0
  9. package/lib/parser/cals/utils/runtime.js +268 -0
  10. package/lib/parser/cals/utils/spinoff/index.d.ts.map +1 -1
  11. package/lib/parser/cals/utils/spinoff/index.js +5 -3
  12. package/lib/parser/cals/utils/style.js +472 -0
  13. package/lib/parser/cals/utils/version/common.js +385 -0
  14. package/lib/parser/cals/utils/version/config.d.ts +16 -0
  15. package/lib/parser/cals/utils/version/config.d.ts.map +1 -0
  16. package/lib/parser/cals/utils/version/config.js +244 -0
  17. package/lib/parser/cals/utils/version/index.js +96 -0
  18. package/lib/parser/cals/utils/version/parses.js +581 -0
  19. package/lib/parser/cals/utils/version/utils.d.ts +14 -0
  20. package/lib/parser/cals/utils/version/utils.d.ts.map +1 -0
  21. package/lib/parser/cals/utils/version/utils.js +148 -0
  22. package/lib/parser/dependiencies/index.d.ts +116 -0
  23. package/lib/parser/dependiencies/index.d.ts.map +1 -0
  24. package/lib/parser/dependiencies/index.js +674 -0
  25. package/lib/parser/expression/index.d.ts +123 -0
  26. package/lib/parser/expression/index.d.ts.map +1 -0
  27. package/lib/parser/expression/index.js +301 -0
  28. package/lib/parser/index.d.ts +2 -1
  29. package/lib/parser/index.d.ts.map +1 -1
  30. package/lib/parser/index.js +3 -1
  31. package/lib/parser/plugins/postcss-rpx2clac.d.ts +18 -0
  32. package/lib/parser/plugins/postcss-rpx2clac.d.ts.map +1 -0
  33. package/lib/parser/plugins/postcss-rpx2clac.js +68 -0
  34. package/lib/types/basic/app.d.ts +73 -0
  35. package/lib/types/basic/app.d.ts.map +1 -0
  36. package/lib/types/basic/app.js +2 -0
  37. package/lib/types/basic/common.d.ts +93 -0
  38. package/lib/types/basic/common.d.ts.map +1 -0
  39. package/lib/types/basic/common.js +2 -0
  40. package/lib/types/basic/component.d.ts +211 -0
  41. package/lib/types/basic/component.d.ts.map +1 -0
  42. package/lib/types/basic/component.js +2 -0
  43. package/lib/types/basic/datasource.d.ts +50 -0
  44. package/lib/types/basic/datasource.d.ts.map +1 -0
  45. package/lib/types/basic/datasource.js +2 -0
  46. package/lib/types/index.js +42 -0
  47. package/lib/types/lcds.js +25 -0
  48. package/lib/types/platform/app.js +11 -0
  49. package/lib/types/platform/common.d.ts +181 -0
  50. package/lib/types/platform/common.d.ts.map +1 -0
  51. package/lib/types/platform/common.js +87 -0
  52. package/lib/types/platform/component.d.ts +139 -0
  53. package/lib/types/platform/component.d.ts.map +1 -0
  54. package/lib/types/platform/component.js +11 -0
  55. package/lib/types/platform/datasource.d.ts +467 -0
  56. package/lib/types/platform/datasource.d.ts.map +1 -0
  57. package/lib/types/platform/datasource.js +2 -0
  58. package/lib/types/platform/eventFlow.d.ts +20 -0
  59. package/lib/types/platform/eventFlow.d.ts.map +1 -0
  60. package/lib/types/platform/eventFlow.js +2 -0
  61. package/lib/types/platform/query.d.ts +67 -0
  62. package/lib/types/platform/query.d.ts.map +1 -0
  63. package/lib/types/platform/query.js +2 -0
  64. package/lib/types/platform/theme.js +2 -0
  65. package/lib/types/platform/widget/form.d.ts +5 -0
  66. package/lib/types/platform/widget/form.d.ts.map +1 -0
  67. package/lib/types/platform/widget/form.js +5 -0
  68. package/lib/types/platform/widget/meta.d.ts +60 -0
  69. package/lib/types/platform/widget/meta.d.ts.map +1 -0
  70. package/lib/types/platform/widget/meta.js +6 -0
  71. package/lib/utils/CSSProperty.d.ts +64 -0
  72. package/lib/utils/CSSProperty.d.ts.map +1 -0
  73. package/lib/utils/CSSProperty.js +89 -0
  74. package/lib/utils/build.d.ts +2 -0
  75. package/lib/utils/build.d.ts.map +1 -0
  76. package/lib/utils/build.js +75 -0
  77. package/lib/utils/constant.d.ts +19 -0
  78. package/lib/utils/constant.d.ts.map +1 -1
  79. package/lib/utils/constant.js +24 -1
  80. package/lib/utils/dts/auto-generated.d.ts +2 -0
  81. package/lib/utils/dts/auto-generated.d.ts.map +1 -0
  82. package/lib/utils/dts/auto-generated.js +1796 -0
  83. package/lib/utils/dts/build.d.ts +2 -0
  84. package/lib/utils/dts/build.d.ts.map +1 -0
  85. package/lib/utils/dts/build.js +136 -0
  86. package/lib/utils/dts/index.js +1008 -0
  87. package/lib/utils/index.js +27 -0
  88. package/lib/utils/version/common.d.ts +3 -0
  89. package/lib/utils/version/common.d.ts.map +1 -0
  90. package/lib/utils/version/common.js +27 -0
  91. package/lib/utils/version/featureChecker.js +35 -0
  92. package/lib/utils/version/migrations/version4.js +199 -0
  93. package/package.json +4 -4
@@ -0,0 +1,674 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _Dependencies_instances, _Dependencies_schema, _Dependencies_capiRequest, _Dependencies_lowcodeRequest, _Dependencies_cals, _Dependencies_compositeGroupId, _Dependencies_compositeComponentId, _Dependencies_options, _Dependencies_actualUsedDependencies, _Dependencies_resolveComposititeComponentData;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.Dependencies = void 0;
25
+ // import { CompositeGroupList, SharedCompositeGroupList } from './mock';
26
+ const utils_1 = require("../../utils");
27
+ const X_RUNTIME_DEFAULT = 'x-runtime-default';
28
+ // import { CONST_COMPONENT_MAP } from 'const/component';
29
+ const CONST_COMPONENT_MAP = {};
30
+ const COMPONENT_META_MAP = {};
31
+ const isSemver = (version) => {
32
+ const SERVEM_REG = /^([0-9])+\.([0-9]+)\.([0-9]+)$/;
33
+ return version.match(SERVEM_REG);
34
+ };
35
+ class Dependencies {
36
+ constructor({ request = {}, cals, compositeGroupId, compositeComponentId, }, options = {}) {
37
+ _Dependencies_instances.add(this);
38
+ _Dependencies_schema.set(this, []);
39
+ _Dependencies_capiRequest.set(this, void 0);
40
+ _Dependencies_lowcodeRequest.set(this, void 0);
41
+ _Dependencies_cals.set(this, void 0);
42
+ _Dependencies_compositeGroupId.set(this, void 0);
43
+ _Dependencies_compositeComponentId.set(this, void 0);
44
+ _Dependencies_options.set(this, void 0);
45
+ _Dependencies_actualUsedDependencies.set(this, void 0);
46
+ __classPrivateFieldSet(this, _Dependencies_cals, cals, "f");
47
+ __classPrivateFieldSet(this, _Dependencies_compositeGroupId, compositeGroupId, "f");
48
+ __classPrivateFieldSet(this, _Dependencies_compositeComponentId, compositeComponentId, "f");
49
+ __classPrivateFieldSet(this, _Dependencies_options, options, "f");
50
+ const { capiRequest, lowcodeRequest } = request;
51
+ if (capiRequest) {
52
+ __classPrivateFieldSet(this, _Dependencies_capiRequest, capiRequest, "f");
53
+ }
54
+ if (lowcodeRequest) {
55
+ __classPrivateFieldSet(this, _Dependencies_lowcodeRequest, lowcodeRequest, "f");
56
+ }
57
+ return this;
58
+ }
59
+ static diffDependencies(source, target, whiteList = []) {
60
+ const diff = {};
61
+ const rollbackDiff = {};
62
+ const sourceMap = (0, utils_1.processDependenciesVersionMap)(source);
63
+ const targetMap = (0, utils_1.processDependenciesVersionMap)(target);
64
+ whiteList === null || whiteList === void 0 ? void 0 : whiteList.forEach((libKey) => {
65
+ const current = sourceMap[`${utils_1.WEDA_OFFICIAL_NAMESPACE}${libKey}`] || sourceMap[libKey];
66
+ const target = targetMap[`${utils_1.WEDA_OFFICIAL_NAMESPACE}${libKey}`] || targetMap[libKey];
67
+ if (current && target && isSemver(current) && isSemver(target)) {
68
+ if ((0, utils_1.semverComp)(target, current) > 0) {
69
+ // 只有当版本号都是sēmver格式的时候才进行对比并根据策略提示升级否则直接升级
70
+ if (!isMajorVersionEqual(current, target)) {
71
+ diff[libKey] = utils_1.SEMVER_VERSION_TAG.MAJOR;
72
+ }
73
+ else if (!isMinorVersionEqual(current, target)) {
74
+ diff[libKey] = utils_1.SEMVER_VERSION_TAG.MINOR;
75
+ }
76
+ }
77
+ else if ((0, utils_1.semverComp)(current, target) > 0) {
78
+ // 降级的时候,判断如果拉取最新的gsd-h5-react组件版本的中版本号低于当前组件版本,不自动降级
79
+ if (!isMajorVersionEqual(current, target)) {
80
+ rollbackDiff[libKey] = utils_1.SEMVER_VERSION_TAG.MAJOR;
81
+ }
82
+ else if (!isMinorVersionEqual(current, target)) {
83
+ rollbackDiff[libKey] = utils_1.SEMVER_VERSION_TAG.MINOR;
84
+ }
85
+ }
86
+ }
87
+ });
88
+ return { diff, rollbackDiff };
89
+ }
90
+ static normalizeDependencies(dependencies) {
91
+ const prefixDep = {};
92
+ Object.keys(dependencies).forEach((key) => {
93
+ const value = dependencies[key].indexOf(`${utils_1.WEDA_COMP_DEPENDENCIES_PREFIX}`) === 0
94
+ ? dependencies[key]
95
+ : `${utils_1.WEDA_COMP_DEPENDENCIES_PREFIX}?v=${dependencies[key]}`;
96
+ // 如果是官方组件库并且没有前缀
97
+ if (utils_1.OFFICIAL_LIBS.indexOf(key) > -1 && key.indexOf(utils_1.WEDA_OFFICIAL_NAMESPACE) === -1) {
98
+ prefixDep[`${utils_1.WEDA_OFFICIAL_NAMESPACE}${key}`] = value;
99
+ }
100
+ else {
101
+ prefixDep[key] = value;
102
+ }
103
+ });
104
+ return prefixDep;
105
+ }
106
+ static loadProdMaterial({ name: materialName, title, controlJsPath, controlCssPath, components: materialComponents, isComposite = false,
107
+ // @ts-ignore
108
+ justRelyOn = false, // 不进行显示,仅仅是可显示的组件库的依赖库
109
+ }, options) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ try {
112
+ if (!isComposite) {
113
+ // 普通组件
114
+ const [{ lcds, components, plugins, actions }] = yield Promise.all([
115
+ loadProdMetaScript(materialName, controlJsPath),
116
+ loadProdMetaStyle(materialName, controlCssPath),
117
+ ]);
118
+ return handleLcdsCompPluginsActions({
119
+ materialName,
120
+ lcds,
121
+ components,
122
+ plugins,
123
+ title,
124
+ actions,
125
+ materialComponents,
126
+ });
127
+ } // 组合组件
128
+ let components = materialComponents.map((cItem) => {
129
+ const result = Object.assign(Object.assign({}, cItem), { sourceKey: `${materialName}:${cItem.name}`, materialName, name: cItem.name || cItem.meta.title, title,
130
+ // @ts-ignore
131
+ meta: Object.assign(Object.assign({}, cItem.meta), { inputProps: extractInputProps(cItem.dataForm) }), justRelyOn });
132
+ // @ts-ignore
133
+ // handleComponent(result);
134
+ return result;
135
+ });
136
+ // 如果是复合组件编辑器,过滤掉本身正在编辑的组件(即当前不支持嵌套)
137
+ components = components.filter((item) => `${item.id}` !== (options === null || options === void 0 ? void 0 : options.compositeComponentId));
138
+ // compositeComponentsMap[materialName] = components;
139
+ const ret = { components, plugins: [], actions: [], name: materialName, title };
140
+ return ret;
141
+ }
142
+ catch (e) {
143
+ return { materialName, title, error: typeof e === 'string' ? e : e.message || '', components: [] };
144
+ }
145
+ });
146
+ }
147
+ /**
148
+ * 处理 component schema
149
+ * 用于补充设计态相关字段
150
+ */
151
+ processCompnent(component) {
152
+ /**
153
+ * 如果组件层级中有 `x-runtime-default` 字段,取其值自动设置 `default` 字段
154
+ * 函数存在副作用
155
+ * 修改了component 的 item
156
+ */
157
+ recursiveTraverse(component, (item) => {
158
+ if (typeof item === 'object' && item && X_RUNTIME_DEFAULT in item && !('default' in item)) {
159
+ item.default = item[X_RUNTIME_DEFAULT];
160
+ // if (!state.meta.hasRuntimeDefault) {
161
+ // state.meta.hasRuntimeDefault = true;
162
+ // }
163
+ }
164
+ else if (typeof item === 'object' && item && item['x-component'] === 'page-params') {
165
+ item.items = {
166
+ type: 'object',
167
+ properties: {
168
+ key: {
169
+ type: 'string',
170
+ title: '参数名',
171
+ },
172
+ value: {
173
+ type: 'string',
174
+ title: '参数值',
175
+ },
176
+ },
177
+ };
178
+ item['x-title-help'] = "参数绑定格式:```[{key:'参数名',value:'参数值'}]```";
179
+ }
180
+ });
181
+ if (COMPONENT_META_MAP[component.sourceKey] && component.meta && /[a-zA-Z]/.test(component.meta.title)) {
182
+ component.meta = Object.assign(Object.assign({}, component.meta), COMPONENT_META_MAP[component.sourceKey]);
183
+ }
184
+ return component;
185
+ }
186
+ useLatestDependiencies(latestCompositeGroupList) {
187
+ var _a, _b;
188
+ return ((_b = (_a = __classPrivateFieldGet(this, _Dependencies_options, "f")).useLatestDependiencies) === null || _b === void 0 ? void 0 : _b.call(_a, latestCompositeGroupList)) || false;
189
+ }
190
+ onCalsDependenciesChange(dependencies) {
191
+ return __classPrivateFieldGet(this, _Dependencies_options, "f").onCalsDependenciesChange(dependencies);
192
+ }
193
+ /**
194
+ * 核心逻辑。获取组件物料,主要做了以下事情:
195
+ * 1、加载组件库最新列表
196
+ * 2、用户组件库立刻加载
197
+ * 2、官方组件库不加载
198
+ */
199
+ init() {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ /**
202
+ * 1. 获取最新的组件库
203
+ */
204
+ const { Data } = yield this.DescribeLatestCompositeGroupList({ WeAppId: __classPrivateFieldGet(this, _Dependencies_cals, "f").id });
205
+ const { List: latestCompositeGroupList = [] } = Data;
206
+ const OFFICIAL_LIB_SET = new Set(utils_1.OFFICIAL_LIBS);
207
+ const dependenciesVersionMap = (0, utils_1.processDependenciesVersionMap)(Object.assign(Object.assign({}, utils_1.BASE_CALS_DEPENDENCIES), __classPrivateFieldGet(this, _Dependencies_cals, "f").dependencies));
208
+ // 2、根据对比结果,获取对应组件库的组件
209
+ let compositeGroupList = [];
210
+ if (!this.useLatestDependiencies(latestCompositeGroupList)) {
211
+ // a.如果存在任意一个官方组件库不同,则加载应用的版本
212
+ // b.如果拉取最新的gsd-h5-react组件版本的中版本号低于当前组件版本,则加载应用版本
213
+ const officialCompositeGroupMeta = [];
214
+ latestCompositeGroupList.forEach((compositeGroup) => {
215
+ if (OFFICIAL_LIB_SET.has(compositeGroup.GroupName)) {
216
+ const version = dependenciesVersionMap[`${utils_1.WEDA_OFFICIAL_NAMESPACE}${compositeGroup.GroupName}`] ||
217
+ dependenciesVersionMap[compositeGroup.GroupName];
218
+ officialCompositeGroupMeta.push({ Id: compositeGroup.Id, GroupVersion: version });
219
+ }
220
+ else {
221
+ compositeGroupList.push(compositeGroup);
222
+ }
223
+ });
224
+ const { Data: { List: officialCompositeGroupMetaList = [] }, } = yield this._DescribeCompositeGroupList({ GroupList: officialCompositeGroupMeta });
225
+ if (!__classPrivateFieldGet(this, _Dependencies_options, "f").autoUpgradeToLatestPatchVersion) {
226
+ compositeGroupList.push(...officialCompositeGroupMetaList);
227
+ }
228
+ else {
229
+ const patchGroupMeta = [];
230
+ officialCompositeGroupMetaList.forEach((compGroup) => {
231
+ if (
232
+ // 有tinyPrimeVersion 并且 tinyPrimeVersion 不等于当前版本
233
+ typeof compGroup.TinyPrimeVersion === 'string' &&
234
+ compGroup.TinyPrimeVersion.length > 0 &&
235
+ compGroup.TinyPrimeVersion !== compGroup.Version) {
236
+ // 手机需要 patch 的版本
237
+ patchGroupMeta.push({ Id: compGroup.Id, GroupVersion: compGroup.TinyPrimeVersion });
238
+ }
239
+ else {
240
+ // 无需 path 直接使用查找的数据不重复查询
241
+ compositeGroupList.push(compGroup);
242
+ }
243
+ });
244
+ if (patchGroupMeta.length) {
245
+ const { Data: { List: patchGroupList = [] }, } = yield this._DescribeCompositeGroupList({ GroupList: patchGroupMeta });
246
+ compositeGroupList.push(...patchGroupList);
247
+ }
248
+ }
249
+ }
250
+ else {
251
+ compositeGroupList = latestCompositeGroupList;
252
+ }
253
+ __classPrivateFieldSet(this, _Dependencies_actualUsedDependencies, Dependencies.normalizeDependencies(compositeGroupList.reduce((acc, cur) => {
254
+ acc[cur.GroupName] = cur.Version;
255
+ return acc;
256
+ }, {})), "f");
257
+ this.onCalsDependenciesChange(__classPrivateFieldGet(this, _Dependencies_actualUsedDependencies, "f"));
258
+ let materials = yield __classPrivateFieldGet(this, _Dependencies_instances, "m", _Dependencies_resolveComposititeComponentData).call(this, __classPrivateFieldGet(this, _Dependencies_cals, "f").id, compositeGroupList, {
259
+ compositeGroupId: __classPrivateFieldGet(this, _Dependencies_compositeGroupId, "f"),
260
+ });
261
+ /**
262
+ * 3、兜底逻辑,获取 gsd-h5-react
263
+ * @deprecated
264
+ */
265
+ // if (!materials.find((m) => m.name === OFFICIAL_MATERIAL_LIB_NAME)) {
266
+ // const { materialErr, materialData } = await getOffcialMaterial();
267
+ // if (materialErr) {
268
+ // materialErr.message = `[listMaterials]${parseRequestErrorMessage(materialErr)}`;
269
+ // dispatch.common.updateLoadStatus({ materialDataLoadError: materialErr || new Error('无组件库加载成功') });
270
+ // return;
271
+ // }
272
+ // materials.push(...materialData);
273
+ // }
274
+ // 4、转换数据格式,铺平所有组件
275
+ const prodMaterialResult = yield Promise.all(materials.map((info) => Dependencies.loadProdMaterial(info, { compositeComponentId: __classPrivateFieldGet(this, _Dependencies_compositeComponentId, "f") })));
276
+ const materialResult = _getMaterialData(materials, prodMaterialResult, this.processCompnent);
277
+ __classPrivateFieldSet(this, _Dependencies_schema, materialResult.dependencies || [], "f");
278
+ return materialResult;
279
+ });
280
+ }
281
+ DescribeLatestCompositeGroupList({ WeAppId }) {
282
+ return __awaiter(this, void 0, void 0, function* () {
283
+ const [{ Data: { List: compositeGroup = [] }, }, { Data: { List: sharedCompositeGroup = [] }, },] = yield Promise.all([
284
+ this._DescribeCompositeGroupList({ WeAppId }),
285
+ this._DescribeShareCompGroups({ WeAppId }).catch((e) => {
286
+ return {
287
+ Data: { Count: 0, List: [] },
288
+ };
289
+ }),
290
+ ]);
291
+ const COMPOSITE_MAP = compositeGroup.reduce((map, item) => {
292
+ map[item.GroupName] = true;
293
+ return map;
294
+ }, {});
295
+ sharedCompositeGroup.forEach((item) => {
296
+ if (item.GroupName && !COMPOSITE_MAP[item.GroupName]) {
297
+ compositeGroup.push(item);
298
+ }
299
+ });
300
+ return { Data: { List: compositeGroup } };
301
+ });
302
+ }
303
+ get schema() {
304
+ return __classPrivateFieldGet(this, _Dependencies_schema, "f");
305
+ }
306
+ _DescribeCompositeGroupList(data, opts = undefined) {
307
+ return __awaiter(this, void 0, void 0, function* () {
308
+ throw new Error('need to impl _DescribeCompositeGroupList');
309
+ });
310
+ }
311
+ _DescribeShareCompGroups(data) {
312
+ return __awaiter(this, void 0, void 0, function* () {
313
+ throw new Error('need to impl _DescribeShareCompGroups');
314
+ // return { Data: SharedCompositeGroupList };
315
+ });
316
+ }
317
+ _DescribeCompositeContent(data) {
318
+ return __awaiter(this, void 0, void 0, function* () {
319
+ throw new Error('need to impl _DescribeCompositeContent');
320
+ });
321
+ }
322
+ }
323
+ exports.Dependencies = Dependencies;
324
+ _Dependencies_schema = new WeakMap(), _Dependencies_capiRequest = new WeakMap(), _Dependencies_lowcodeRequest = new WeakMap(), _Dependencies_cals = new WeakMap(), _Dependencies_compositeGroupId = new WeakMap(), _Dependencies_compositeComponentId = new WeakMap(), _Dependencies_options = new WeakMap(), _Dependencies_actualUsedDependencies = new WeakMap(), _Dependencies_instances = new WeakSet(), _Dependencies_resolveComposititeComponentData = function _Dependencies_resolveComposititeComponentData(appId, componentGroups, options) {
325
+ return __awaiter(this, void 0, void 0, function* () {
326
+ const { compositeGroupId } = options || {};
327
+ const compData = [];
328
+ yield Promise.all(componentGroups.map((group) => __awaiter(this, void 0, void 0, function* () {
329
+ // compositeGroup/list 只能获取到发布prod情况下的组件库信息
330
+ const { Id: id, Title, GroupName: groupName, Version: version, Content, PrivateCosPrefix: privateCosPrefix, PublicCosPrefix: publicCosPrefix, IsShare, } = group;
331
+ const obj = {
332
+ id,
333
+ version,
334
+ originName: groupName,
335
+ name: groupName,
336
+ title: Title || groupName,
337
+ components: [],
338
+ isComposite: true,
339
+ content: Content ? JSON.parse(Content) : undefined,
340
+ publicCosPrefix,
341
+ privateCosPrefix,
342
+ };
343
+ // 获取复合组件库的组件列表
344
+ // dev=true代表获取未发布的组件详情
345
+ // 目前支持在组件编辑器中,调试同一个库里的未发布的组件
346
+ // 官方组件库,在组件编辑器里,直接拉取线上,方便刷库@zijie
347
+ const dev = groupName === utils_1.OFFICIAL_COMPONENT_LIB_NAME ? false : compositeGroupId === obj.id;
348
+ let data;
349
+ try {
350
+ data = yield this._DescribeCompositeContent({
351
+ CompositeGroupId: obj.id,
352
+ WeAppId: appId,
353
+ Version: version,
354
+ IsShare,
355
+ Dev: dev,
356
+ });
357
+ }
358
+ catch (e) { }
359
+ if (data === null || data === void 0 ? void 0 : data.Count) {
360
+ let isMixed = false;
361
+ let newContent = data.Content || obj.content;
362
+ const newPublicCosPrefix = data.PublicCosPrefix || publicCosPrefix;
363
+ const newPrivateCosPrefix = data.PrivateCosPrefix || privateCosPrefix;
364
+ // 在组件编辑器,可以获取到同一个库的未发布即dev的组件
365
+ // 利用compositeComp/list 更新相关信息
366
+ Object.assign(obj, {
367
+ content: newContent,
368
+ publicCosPrefix: newPublicCosPrefix,
369
+ privateCosPrefix: newPrivateCosPrefix,
370
+ mainCssPath: `${newPublicCosPrefix}build/dist/comps.complex.main.css`,
371
+ mainJsPath: `${newPublicCosPrefix}build/dist/comps.complex.main.js`,
372
+ });
373
+ if (!newContent) {
374
+ // 纯JSON组件库,不需要进行分拆
375
+ obj.components = data.Components;
376
+ if (id === 'cg-jgjmnsvid6ot' && version === '1612432272646') {
377
+ const find = {};
378
+ // eslint-disable-next-line no-restricted-syntax
379
+ for (const index in obj.components) {
380
+ if (!isNaN(Number(index))) {
381
+ const { name, groupName } = obj.components[Number(index)];
382
+ const sourceKey = `${groupName}:${name}`;
383
+ switch (sourceKey) {
384
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormRegion`:
385
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:GridLayout`: {
386
+ if (CONST_COMPONENT_MAP[sourceKey]) {
387
+ obj.components[index] = CONST_COMPONENT_MAP[sourceKey];
388
+ find[sourceKey] = true;
389
+ }
390
+ break;
391
+ }
392
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:TabBarItem`:
393
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:Media`:
394
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:Icon`:
395
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:SlotMachine`:
396
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:Form`:
397
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormItem`:
398
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormDate`:
399
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:ItemList`:
400
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:Item`:
401
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:TabBar`:
402
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:NavBar`:
403
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormSelect`:
404
+ case `${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:Classification`: {
405
+ if (CONST_COMPONENT_MAP[sourceKey]) {
406
+ obj.components[index] = CONST_COMPONENT_MAP[sourceKey];
407
+ }
408
+ break;
409
+ }
410
+ }
411
+ }
412
+ }
413
+ if (!find[`${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:GridLayout`] &&
414
+ CONST_COMPONENT_MAP[`${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:GridLayout`]) {
415
+ obj.components.push(CONST_COMPONENT_MAP[`${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:GridLayout`]);
416
+ }
417
+ if (!find[`${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormRegion`] &&
418
+ CONST_COMPONENT_MAP[`${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormRegion`]) {
419
+ obj.components.push(CONST_COMPONENT_MAP[`${utils_1.OFFICIAL_COMPONENT_LIB_NAME}:FormRegion`]);
420
+ }
421
+ }
422
+ // 纯json库也需要加上 分库的后缀,官方组件库除外
423
+ ![utils_1.OFFICIAL_COMPONENT_LIB_NAME, 'weda_standard'].includes(groupName) && (obj.name += utils_1.SPINOFF_SUFFIX);
424
+ compData.push(obj);
425
+ }
426
+ else {
427
+ // 新版组件库,控制台入口是打平code和json组件,在编辑器runtime和builder
428
+ // 需要拆分成json和code,适配之前的模式;
429
+ const codeComp = [];
430
+ const jsonComp = [];
431
+ const { actions, manifestMap, sourceMap } = newContent;
432
+ const { controlJs, mainCss, mainJs } = manifestMap;
433
+ const { source, mpSource } = sourceMap;
434
+ const controlJsPath = newPublicCosPrefix + controlJs;
435
+ const mainCssPath = newPublicCosPrefix + mainCss;
436
+ const mainJsPath = newPublicCosPrefix + mainJs;
437
+ const mpPkgUrl = mpSource && newPrivateCosPrefix + mpSource;
438
+ const sourceZipPath = newPrivateCosPrefix + source;
439
+ const codeLibObj = Object.assign({}, obj, {
440
+ actions,
441
+ isComposite: false,
442
+ controlJsPath,
443
+ mainCssPath,
444
+ mainJsPath,
445
+ mpPkgUrl,
446
+ sourceZipPath,
447
+ });
448
+ // 组件库里有json组件和code组件,需要分拆两个库
449
+ data.Components.forEach((comp) => {
450
+ if (comp.ctype === 1) {
451
+ // code 组件
452
+ codeComp.push(comp);
453
+ }
454
+ else if (comp.ctype === 2) {
455
+ // json 组件
456
+ jsonComp.push(comp);
457
+ isMixed = true;
458
+ }
459
+ });
460
+ obj.components = jsonComp;
461
+ isMixed && (obj.name += utils_1.SPINOFF_SUFFIX);
462
+ codeLibObj.components = codeComp;
463
+ compData.push(codeLibObj);
464
+ if (jsonComp.length > 0) {
465
+ compData.push(Object.assign(Object.assign({}, obj), { mainCssPath: `${newPublicCosPrefix}build/dist/comps.complex.main.css`, mainJsPath: `${newPublicCosPrefix}build/dist/comps.complex.main.js` }));
466
+ obj.components = jsonComp;
467
+ isMixed && (obj.name += utils_1.SPINOFF_SUFFIX);
468
+ codeLibObj.components = codeComp;
469
+ compData.push(codeLibObj);
470
+ if (jsonComp.length > 0) {
471
+ compData.push(Object.assign(Object.assign({}, obj), { mainCssPath: `${newPublicCosPrefix}build/dist/comps.complex.main.css`, mainJsPath: `${newPublicCosPrefix}build/dist/comps.complex.main.js` }));
472
+ }
473
+ }
474
+ }
475
+ }
476
+ })));
477
+ return compData;
478
+ });
479
+ };
480
+ function loadProdMetaScript(bundleName, filename) {
481
+ return new Promise((resolve, reject) => {
482
+ const script = document.createElement('script');
483
+ script.setAttribute('src', filename);
484
+ script.setAttribute('class', '@weapps-materials-control');
485
+ script.addEventListener('load', () => {
486
+ const moduleName = `@weapps-materials-control-${bundleName}`;
487
+ if (Object.prototype.hasOwnProperty.call(window, moduleName)) {
488
+ const value = window[moduleName];
489
+ return resolve(value);
490
+ }
491
+ return reject(new Error(`meta bundle [${bundleName}] must build with UMD`));
492
+ });
493
+ script.addEventListener('error', (e) => reject(`meta bundle [${bundleName}] load failed: ${(e === null || e === void 0 ? void 0 : e.message) || ''}`));
494
+ document.body.appendChild(script);
495
+ });
496
+ }
497
+ function loadProdMetaStyle(bundleName, filename, entryDoc = document, isLess = false) {
498
+ if (!filename) {
499
+ return Promise.resolve();
500
+ }
501
+ return new Promise((resolve) => {
502
+ const link = document.createElement('link');
503
+ link.type = 'text/css';
504
+ link.rel = isLess ? 'stylesheet/less' : 'stylesheet';
505
+ link.className = '@weapps-materials-style';
506
+ link.href = filename;
507
+ link.addEventListener('load', () => resolve());
508
+ link.addEventListener('error', (e) => {
509
+ console.warn(`Load [${bundleName}] meta style failed, skip...`, e);
510
+ resolve();
511
+ });
512
+ entryDoc.head.appendChild(link);
513
+ });
514
+ }
515
+ function handleLcdsCompPluginsActions({ materialName, lcds, components, plugins, actions, title, materialComponents = null, }) {
516
+ components.forEach((i) => {
517
+ var _a;
518
+ i.sourceKey = `${materialName}:${i.name}`;
519
+ i.materialName = materialName;
520
+ const { icon, description } = i.meta;
521
+ if (materialComponents) {
522
+ const { platform } = i.meta;
523
+ i.meta = Object.assign(Object.assign(Object.assign({}, i.meta), (((_a = materialComponents.find((c) => c.name === i.name)) === null || _a === void 0 ? void 0 : _a.meta) || {})), { description });
524
+ i.meta.platform = platform ? platform : i.meta.platform;
525
+ i.meta.platform = i.meta.platform || [];
526
+ }
527
+ if (icon === null || icon === void 0 ? void 0 : icon.startsWith('data:')) {
528
+ i.meta.icon = icon;
529
+ }
530
+ // handleComponent(i);
531
+ });
532
+ plugins.forEach((i) => {
533
+ i.sourceKey = `${materialName}:${i.name}`;
534
+ i.materialName = materialName;
535
+ });
536
+ actions.forEach((i) => {
537
+ i.sourceKey = `${materialName}:${i.name}`;
538
+ i.materialName = materialName;
539
+ i.type = utils_1.ActionType.Material;
540
+ });
541
+ return { lcds, components, plugins, actions, title, name: materialName };
542
+ }
543
+ function _getMaterialData(materials, prodMaterialResult, processCompnent) {
544
+ var _a;
545
+ const componentMethodList = {};
546
+ let { successMaterialList: finalMaterialList } = prodMaterialResult.reduce((acc, item) => {
547
+ if (!item.error) {
548
+ acc.successMaterialList.push(item);
549
+ }
550
+ else {
551
+ console.log('pull prod material error:', item.error);
552
+ }
553
+ return acc;
554
+ }, {
555
+ successMaterialList: [],
556
+ });
557
+ finalMaterialList = finalMaterialList.map((lib) => {
558
+ lib.components = lib.components.map((comp) => {
559
+ var _a;
560
+ /**
561
+ * 副作用修改 component schema 信息
562
+ */
563
+ comp = processCompnent(comp);
564
+ if (((_a = comp === null || comp === void 0 ? void 0 : comp.methods) === null || _a === void 0 ? void 0 : _a.length) > 0) {
565
+ componentMethodList[comp.sourceKey.toLowerCase()] = comp.methods;
566
+ }
567
+ return comp;
568
+ });
569
+ return lib;
570
+ });
571
+ const components = finalMaterialList.reduce((result, material) => result.concat(material.components), []);
572
+ const componentsMap = {};
573
+ for (const item of materials) {
574
+ componentsMap[item.name] = [];
575
+ }
576
+ for (const item of components) {
577
+ (_a = componentsMap[item.materialName]) === null || _a === void 0 ? void 0 : _a.push(item);
578
+ }
579
+ return {
580
+ lcds: finalMaterialList.lcds,
581
+ compLibs: finalMaterialList.map((item) => {
582
+ return ['desc', 'name', 'title', 'version', 'isComposite'].reduce((map, key) => {
583
+ if (item[key] !== undefined) {
584
+ map[key] = item[key];
585
+ }
586
+ return map;
587
+ }, {});
588
+ }),
589
+ actions: finalMaterialList.reduce((result, material) => result.concat(material.actions), []),
590
+ components,
591
+ plugins: finalMaterialList.reduce((result, material) => result.concat(material.plugins), []),
592
+ componentMethodList,
593
+ dependencies: materials.map((m) => {
594
+ let schemaVersion;
595
+ const find = finalMaterialList.find((item) => item.name === m.name);
596
+ if (find && !m.isComposite) {
597
+ // 基础库补充schemaVersion
598
+ const { lcds = {} } = find;
599
+ if (lcds.schemaVersion) {
600
+ schemaVersion = lcds.schemaVersion;
601
+ }
602
+ }
603
+ return {
604
+ schemaVersion,
605
+ name: m.name,
606
+ originName: m.name === m.originName ? undefined : m.originName,
607
+ version: m.version,
608
+ controlJsPath: m.controlJsPath,
609
+ mainCssPath: m.mainCssPath,
610
+ mainJsPath: m.mainJsPath,
611
+ srcZipUrl: m.sourceZipPath,
612
+ mpPkgUrl: m.mpPkgUrl,
613
+ isComposite: !!m.isComposite,
614
+ components: componentsMap[m.name] || [],
615
+ };
616
+ }),
617
+ };
618
+ }
619
+ function extractInputProps(schema) {
620
+ const inputProps = {};
621
+ Object.keys(schema).map((prop) => {
622
+ if (schema[prop].inputProp) {
623
+ inputProps[prop] = schema[prop].inputProp;
624
+ }
625
+ });
626
+ return inputProps;
627
+ }
628
+ /** 版本号 major不同才认为是不同
629
+ * @param curVersion 当前版本
630
+ * @param targetVersion 需要对比的版本
631
+ * @returns boolean
632
+ */
633
+ const isMajorVersionEqual = (curVersion, targetVersion) => {
634
+ const cur = isSemver(curVersion);
635
+ const target = isSemver(targetVersion);
636
+ if (cur && target) {
637
+ return cur[1] === target[1];
638
+ }
639
+ return curVersion === targetVersion;
640
+ };
641
+ /** 版本号 minor不同才认为是不同
642
+ * @param curVersion 当前版本
643
+ * @param targetVersion 需要对比的版本
644
+ * @returns boolean
645
+ */
646
+ const isMinorVersionEqual = (curVersion, targetVersion) => {
647
+ const cur = isSemver(curVersion);
648
+ const target = isSemver(targetVersion);
649
+ if (cur && target) {
650
+ return cur[1] === target[1] && cur[2] === target[2];
651
+ }
652
+ return curVersion === targetVersion;
653
+ };
654
+ function recursiveTraverse(target, visit) {
655
+ function traverse(obj, path) {
656
+ if (Array.isArray(obj)) {
657
+ for (const [index, item] of obj.entries()) {
658
+ const currPath = path.concat(index);
659
+ traverse(item, currPath);
660
+ visit(item, currPath);
661
+ }
662
+ }
663
+ else if (typeof obj === 'object' && obj !== null) {
664
+ for (const [key, value] of Object.entries(obj)) {
665
+ const currPath = path.concat(key);
666
+ traverse(value, currPath);
667
+ visit(value, currPath);
668
+ }
669
+ }
670
+ }
671
+ traverse(target, []);
672
+ // visit target itself lastly
673
+ visit(target, []);
674
+ }