@cloudbase/cals 1.0.49 → 1.0.50

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 (87) hide show
  1. package/lib/parser/cals/utils/template.js +3 -3
  2. package/package.json +3 -3
  3. package/lib/parser/cals/utils/block/index.js +0 -151
  4. package/lib/parser/cals/utils/code/index.js +0 -393
  5. package/lib/parser/cals/utils/common.js +0 -268
  6. package/lib/parser/cals/utils/getUsedResources.d.ts +0 -10
  7. package/lib/parser/cals/utils/getUsedResources.d.ts.map +0 -1
  8. package/lib/parser/cals/utils/getUsedResources.js +0 -128
  9. package/lib/parser/cals/utils/runtime.js +0 -268
  10. package/lib/parser/cals/utils/style.js +0 -472
  11. package/lib/parser/cals/utils/version/common.js +0 -385
  12. package/lib/parser/cals/utils/version/config.d.ts +0 -16
  13. package/lib/parser/cals/utils/version/config.d.ts.map +0 -1
  14. package/lib/parser/cals/utils/version/config.js +0 -244
  15. package/lib/parser/cals/utils/version/index.js +0 -96
  16. package/lib/parser/cals/utils/version/parses.js +0 -581
  17. package/lib/parser/cals/utils/version/utils.d.ts +0 -14
  18. package/lib/parser/cals/utils/version/utils.d.ts.map +0 -1
  19. package/lib/parser/cals/utils/version/utils.js +0 -148
  20. package/lib/parser/expression/index.d.ts +0 -123
  21. package/lib/parser/expression/index.d.ts.map +0 -1
  22. package/lib/parser/expression/index.js +0 -301
  23. package/lib/parser/plugins/postcss-rpx2clac.d.ts +0 -18
  24. package/lib/parser/plugins/postcss-rpx2clac.d.ts.map +0 -1
  25. package/lib/parser/plugins/postcss-rpx2clac.js +0 -68
  26. package/lib/types/basic/app.d.ts +0 -73
  27. package/lib/types/basic/app.d.ts.map +0 -1
  28. package/lib/types/basic/app.js +0 -2
  29. package/lib/types/basic/common.d.ts +0 -93
  30. package/lib/types/basic/common.d.ts.map +0 -1
  31. package/lib/types/basic/common.js +0 -2
  32. package/lib/types/basic/component.d.ts +0 -211
  33. package/lib/types/basic/component.d.ts.map +0 -1
  34. package/lib/types/basic/component.js +0 -2
  35. package/lib/types/basic/datasource.d.ts +0 -50
  36. package/lib/types/basic/datasource.d.ts.map +0 -1
  37. package/lib/types/basic/datasource.js +0 -2
  38. package/lib/types/index.js +0 -42
  39. package/lib/types/lcds.js +0 -25
  40. package/lib/types/platform/app.js +0 -11
  41. package/lib/types/platform/common.d.ts +0 -181
  42. package/lib/types/platform/common.d.ts.map +0 -1
  43. package/lib/types/platform/common.js +0 -87
  44. package/lib/types/platform/component.d.ts +0 -139
  45. package/lib/types/platform/component.d.ts.map +0 -1
  46. package/lib/types/platform/component.js +0 -11
  47. package/lib/types/platform/datasource.d.ts +0 -467
  48. package/lib/types/platform/datasource.d.ts.map +0 -1
  49. package/lib/types/platform/datasource.js +0 -2
  50. package/lib/types/platform/eventFlow.d.ts +0 -20
  51. package/lib/types/platform/eventFlow.d.ts.map +0 -1
  52. package/lib/types/platform/eventFlow.js +0 -2
  53. package/lib/types/platform/query.d.ts +0 -67
  54. package/lib/types/platform/query.d.ts.map +0 -1
  55. package/lib/types/platform/query.js +0 -2
  56. package/lib/types/platform/theme.js +0 -2
  57. package/lib/types/platform/widget/form.d.ts +0 -5
  58. package/lib/types/platform/widget/form.d.ts.map +0 -1
  59. package/lib/types/platform/widget/form.js +0 -5
  60. package/lib/types/platform/widget/meta.d.ts +0 -60
  61. package/lib/types/platform/widget/meta.d.ts.map +0 -1
  62. package/lib/types/platform/widget/meta.js +0 -6
  63. package/lib/utils/CSSProperty.d.ts +0 -64
  64. package/lib/utils/CSSProperty.d.ts.map +0 -1
  65. package/lib/utils/CSSProperty.js +0 -89
  66. package/lib/utils/build.d.ts +0 -2
  67. package/lib/utils/build.d.ts.map +0 -1
  68. package/lib/utils/build.js +0 -75
  69. package/lib/utils/dts/auto-generated.d.ts +0 -2
  70. package/lib/utils/dts/auto-generated.d.ts.map +0 -1
  71. package/lib/utils/dts/auto-generated.js +0 -1796
  72. package/lib/utils/dts/build.d.ts +0 -2
  73. package/lib/utils/dts/build.d.ts.map +0 -1
  74. package/lib/utils/dts/build.js +0 -136
  75. package/lib/utils/dts/index.js +0 -1008
  76. package/lib/utils/index.js +0 -27
  77. package/lib/utils/version/common.d.ts +0 -3
  78. package/lib/utils/version/common.d.ts.map +0 -1
  79. package/lib/utils/version/common.js +0 -27
  80. package/lib/utils/version/featureChecker.js +0 -35
  81. package/lib/utils/version/migrations/version4.js +0 -199
  82. package/lib/utils/version-migrations/common.d.ts +0 -5
  83. package/lib/utils/version-migrations/common.d.ts.map +0 -1
  84. package/lib/utils/version-migrations/common.js +0 -29
  85. package/lib/utils/version-migrations/version4.d.ts +0 -3
  86. package/lib/utils/version-migrations/version4.d.ts.map +0 -1
  87. package/lib/utils/version-migrations/version4.js +0 -199
@@ -1,268 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUsedComps = exports.isValidClassNameListBind = exports.isValidStyleBind = exports.isEmptyObj = exports.isPlainObject = exports.camelcase = void 0;
4
- const utils_1 = require("../../../utils");
5
- const index_1 = require("../index");
6
- function camelcase(str, firstUpperCase = false) {
7
- str = str.replace(/[_-]([a-z])/g, (l) => {
8
- return l[1].toUpperCase();
9
- });
10
- if (firstUpperCase)
11
- str = str.charAt(0).toUpperCase() + str.slice(1);
12
- return str;
13
- }
14
- exports.camelcase = camelcase;
15
- function isPlainObject(src) {
16
- return Object.prototype.toString.call(src) === '[object Object]';
17
- }
18
- exports.isPlainObject = isPlainObject;
19
- const isEmptyObj = (obj) => {
20
- if (!isPlainObject(obj)) {
21
- return false;
22
- }
23
- for (const i in obj) {
24
- if (Object.prototype.hasOwnProperty.call(obj, i)) {
25
- return false;
26
- }
27
- }
28
- return true;
29
- };
30
- exports.isEmptyObj = isEmptyObj;
31
- function isValidStyleBind(styleBind) {
32
- if (!styleBind) {
33
- return false;
34
- }
35
- if (styleBind.propertyPath === 'style' && styleBind.bindDataPath) {
36
- return true;
37
- }
38
- return false;
39
- }
40
- exports.isValidStyleBind = isValidStyleBind;
41
- function isValidClassNameListBind(classNameListBind) {
42
- if (!classNameListBind) {
43
- return false;
44
- }
45
- if (classNameListBind.propertyPath === 'classNameList') {
46
- return true;
47
- }
48
- return false;
49
- }
50
- exports.isValidClassNameListBind = isValidClassNameListBind;
51
- // 递归查询属性树所使用的组件
52
- function getUsedCompsFromProperties(properties, usedMeta) {
53
- for (const id in properties) {
54
- const { xComponent, properties: children, xProps = {} } = properties[id];
55
- if (xComponent) {
56
- // 记录使用到的组件库和组件
57
- const { moduleName: libName, name: compName } = xComponent;
58
- if (!usedMeta.component[libName]) {
59
- usedMeta.component[libName] = new Set();
60
- }
61
- usedMeta.component[libName].add(compName);
62
- }
63
- for (const listener of (xProps === null || xProps === void 0 ? void 0 : xProps.listeners) || []) {
64
- if (listener.type === utils_1.ActionType.Material) {
65
- const { moduleName, name } = listener.handler || {};
66
- const libName = moduleName || utils_1.OFFICIAL_LIB_KEY;
67
- if (!usedMeta.action[libName]) {
68
- usedMeta.action[libName] = new Set();
69
- }
70
- usedMeta.action[libName].add(name);
71
- }
72
- }
73
- /**
74
- * @deprecated
75
- * generic-component 协议待定,并未启用
76
- * Handle generic component props
77
- */
78
- // Object.keys(xProps?.data || {}).map((p) => {
79
- // const { value } = xProps.data?.[p] as any;
80
- // if (/^\w+:\w+$/.test(value)) {
81
- // const [libName, name] = value.split(':');
82
- // if (!usedMeta.component[libName]) {
83
- // usedMeta.component[libName] = new Set();
84
- // }
85
- // usedMeta.component[libName].add(name);
86
- // }
87
- // });
88
- if (children) {
89
- // 遍历下一层属性树
90
- getUsedCompsFromProperties(children, usedMeta);
91
- }
92
- }
93
- }
94
- /**
95
- * 直接访问 cals 来收集
96
- */
97
- function getUsedCompsFromIPlatformComponent(comp, used, options) {
98
- var _a, _b;
99
- // 非 slot
100
- if (comp.component) {
101
- const module = comp.module || utils_1.OFFICIAL_LIB_KEY;
102
- if (!used.component[module]) {
103
- used.component[module] = new Set([]);
104
- }
105
- used.component[module].add(comp.component);
106
- }
107
- /**
108
- * @deprecated
109
- * generic-component 协议待定,并未启用
110
- * Handle generic component props
111
- */
112
- // Object.entries(comp.attributes || {}).forEach(([key, value]) => {
113
- // if (/^\w+:\w+$/.test(value)) {
114
- // const [module, name] = value.split(':');
115
- // const libName = module || OFFICIAL_LIB_KEY;
116
- // if (!used.component[libName]) {
117
- // used.component[libName] = new Set<string>([]);
118
- // }
119
- // used.component[module].add(name);
120
- // }
121
- // });
122
- if (options === null || options === void 0 ? void 0 : options.withAction) {
123
- const { listeners = [] } = comp;
124
- listeners.forEach((listener) => {
125
- var _a, _b;
126
- if (listener.type === utils_1.ActionType.Material) {
127
- const module = listener.handler.module || utils_1.OFFICIAL_LIB_KEY;
128
- if (!used.action[module]) {
129
- used.action[module] = new Set([]);
130
- }
131
- if ((_a = listener.handler) === null || _a === void 0 ? void 0 : _a.name) {
132
- used.action[module].add((_b = listener.handler) === null || _b === void 0 ? void 0 : _b.name);
133
- }
134
- }
135
- });
136
- }
137
- (_b = (_a = comp.items) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (item) => {
138
- getUsedCompsFromIPlatformComponent(item, used, options);
139
- });
140
- }
141
- // 递归查询复合组件库所使用的组件
142
- function getUsedCompsFromCompositedLibsRecursively(
143
- // 已知的被使用到的组件
144
- usedMeta,
145
- // 已知的被遍历过的组件
146
- checkedComps,
147
- // 全量复合组件库
148
- compositedLibMap,
149
- // 新增的被使用到的组件
150
- addedUsedMeta) {
151
- // 开始遍历已知的被使用到的组件库
152
- Object.keys(usedMeta.component).forEach((libName) => {
153
- if (!compositedLibMap.has(libName)) {
154
- // 不是复合组件库, 不需要继续遍历
155
- return;
156
- }
157
- // 遍历复合组件库
158
- const lib = compositedLibMap.get(libName);
159
- const cmpNames = usedMeta.component[libName];
160
- cmpNames.forEach((cmpName) => {
161
- // 找到复合组件的内容
162
- const cmp = lib.components.find((c) => c.name === cmpName);
163
- if (!cmp) {
164
- // 找不到复合组件内容, 应该抛异常
165
- console.warn('Component not found', `${libName}:${cmpName}`);
166
- return;
167
- }
168
- if (checkedComps.indexOf(cmp) > -1) {
169
- // 该复合组件已经在其他递归路径上入栈
170
- return;
171
- }
172
- // 该复合组件第一次入栈, 则需要记录并继续递归它的内容
173
- checkedComps.push(cmp);
174
- const usedMetaOfThisComp = { component: {}, action: {} };
175
- // 和遍历应用内容一样, 遍历低码组件内容, 寻找出组件自身引用的所有组件
176
- getUsedCompsFromProperties(cmp.componentInstances, usedMetaOfThisComp);
177
- ['component', 'action'].forEach((type) => {
178
- Object.keys(usedMetaOfThisComp[type]).forEach((libName) => {
179
- // 开始记录新增的被使用的组件库
180
- if (!addedUsedMeta[type][libName]) {
181
- addedUsedMeta[type][libName] = usedMetaOfThisComp[type][libName];
182
- }
183
- else {
184
- usedMetaOfThisComp[type][libName].forEach((n) => addedUsedMeta[type][libName].add(n));
185
- }
186
- });
187
- });
188
- // 递归遍历
189
- getUsedCompsFromCompositedLibsRecursively(usedMetaOfThisComp, checkedComps, compositedLibMap, addedUsedMeta);
190
- });
191
- });
192
- }
193
- // 获取使用到的组件
194
- function getUsedComps(
195
- // 主子包的应用内容
196
- apps,
197
- // 分库后的组件库 denpendienicy
198
- dependencies, options) {
199
- const { streamline = false, withAction = false } = options || {};
200
- const { templates = [] } = (apps === null || apps === void 0 ? void 0 : apps[0]) || {};
201
- const comps = streamline && templates.length ? [...dependencies, (0, index_1.processTemplatesToDependiencies)(templates)] : dependencies;
202
- // 1. 寻找应用内容里用到的所有组件
203
- // 1.1 寻找主子应用各自的内容里所用到的组件
204
- const appUsedComps = apps.map((app) => {
205
- var _a, _b, _c, _d;
206
- const usedMeta = {
207
- component: {},
208
- action: {},
209
- };
210
- // 主子包模式下, 可能没有应用内容
211
- (_b = (_a = app.items) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (page) => {
212
- var _a, _b;
213
- (_b = (_a = page === null || page === void 0 ? void 0 : page.items) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (comp) => {
214
- getUsedCompsFromIPlatformComponent(comp, usedMeta, options);
215
- });
216
- });
217
- if (!streamline) {
218
- (_d = (_c = app.templates) === null || _c === void 0 ? void 0 : _c.forEach) === null || _d === void 0 ? void 0 : _d.call(_c, (template) => {
219
- var _a;
220
- (_a = template.items) === null || _a === void 0 ? void 0 : _a.forEach((comp) => {
221
- getUsedCompsFromIPlatformComponent(comp, usedMeta, options);
222
- });
223
- });
224
- }
225
- return usedMeta;
226
- });
227
- // 1.2 合并主子包所有用到的组件
228
- const mergeAppUsedMeta = appUsedComps.reduce((meta, item) => {
229
- if (!meta.component) {
230
- meta.component = {};
231
- }
232
- if (!meta.action) {
233
- meta.action = {};
234
- }
235
- ['component', 'action'].forEach((type) => {
236
- Object.entries(item[type] || {}).forEach(([libName]) => {
237
- meta[type][libName] = new Set([
238
- ...Array.from(item[type][libName]),
239
- ...Array.from(meta[type][libName] || []),
240
- ]);
241
- });
242
- });
243
- return meta;
244
- }, { component: {}, action: {} });
245
- // 2. 寻找应用内容的复合组件里嵌套的其他组件(复合组件即低码组件)
246
- // 2.1 过滤出复合组件库
247
- const compositedLibMap = new Map();
248
- comps.forEach((lib) => {
249
- if (lib.isComposite) {
250
- compositedLibMap.set(lib.name, lib);
251
- }
252
- });
253
- // 2.2 递归查询复合组件库所使用的组件
254
- const libUsedMeta = { component: {}, action: {} };
255
- getUsedCompsFromCompositedLibsRecursively(mergeAppUsedMeta, [], compositedLibMap, libUsedMeta);
256
- // 3. 合并[应用内容用到的组件]和[复合组件库用到的组件]
257
- const allMeta = { component: {}, action: {} };
258
- ['component', 'action'].forEach((type) => {
259
- allMeta[type] = [mergeAppUsedMeta[type], libUsedMeta[type]].reduce((comps, item) => {
260
- for (const libName in item) {
261
- comps[libName] = new Set([...Array.from(item[libName]), ...Array.from(comps[libName] || [])]);
262
- }
263
- return comps;
264
- }, {});
265
- });
266
- return withAction ? allMeta : allMeta.component;
267
- }
268
- exports.getUsedComps = getUsedComps;
@@ -1,10 +0,0 @@
1
- export declare function getUsedResources(apps: any[]): Array<string>;
2
- export declare function _simpleGetUsedResourceOfComponent(comp: any, staticResourceSet?: Set<string>, attributeSet?: Set<string>): {
3
- staticResourceSet: Set<string>;
4
- attributeSet: Set<string>;
5
- };
6
- export declare function getNavUsedStaticResource(config: any): {
7
- staticResourceAttribute: string[];
8
- resources: string[];
9
- };
10
- //# sourceMappingURL=getUsedResources.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUsedResources.d.ts","sourceRoot":"","sources":["../../../../src/parser/cals/utils/getUsedResources.ts"],"names":[],"mappings":"AAgBA,wBAAgB,gBAAgB,CAE9B,IAAI,EAAE,GAAG,EAAE,GACV,KAAK,CAAC,MAAM,CAAC,CASf;AAiED,wBAAgB,iCAAiC,CAC/C,IAAI,KAAA,EACJ,iBAAiB,cAAsB,EACvC,YAAY,cAAsB;;;EAQnC;AAkBD,wBAAgB,wBAAwB,CAAC,MAAM,KAAA,GAAG;IAAE,uBAAuB,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAqB3G"}
@@ -1,128 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNavUsedStaticResource = exports._simpleGetUsedResourceOfComponent = exports.getUsedResources = void 0;
4
- const lodash_1 = require("lodash");
5
- // 入口
6
- function getUsedResources(
7
- // 模版的应用内容
8
- apps) {
9
- // 递归查询模版
10
- const allUsedResources = new Set();
11
- for (let app of apps) {
12
- getUsedResourcesFromAppRecursively(app, allUsedResources);
13
- }
14
- return Array.from(allUsedResources);
15
- }
16
- exports.getUsedResources = getUsedResources;
17
- /**
18
- * 解析路径处理属性
19
- */
20
- function processStaticResourceAttribute(data, property, staticResourceSet = new Set([]), attributeSet = new Set([])) {
21
- let segments = [property];
22
- if (/\.\*\.?/.test(property)) {
23
- segments = property === null || property === void 0 ? void 0 : property.trim().split('.').reduce((segments, path) => {
24
- const latest = segments.length ? segments.length - 1 : 0;
25
- const current = segments[latest];
26
- if (path === '*') {
27
- segments.push('');
28
- }
29
- else {
30
- segments[latest] = current ? `${current}.${path}` : path;
31
- }
32
- return segments;
33
- }, []);
34
- }
35
- try {
36
- resolveStaticResourceAttribute(data, segments, staticResourceSet, attributeSet);
37
- }
38
- catch (e) {
39
- console.error('处理静态资源失败:', e);
40
- }
41
- return { staticResourceSet, attributeSet };
42
- }
43
- /**
44
- * 处理单个路径
45
- */
46
- function resolveStaticResourceAttribute(obj, paths, staticResourceSet, attributeSet, index = 0) {
47
- const path = paths[index];
48
- const value = (0, lodash_1.get)(obj, path);
49
- if (index === paths.length - 1) {
50
- try {
51
- if (typeof value === 'string' && value.indexOf('/') === 0) {
52
- staticResourceSet.add(value);
53
- attributeSet.add(paths.join('.*.'));
54
- }
55
- }
56
- catch (e) {
57
- console.error(e);
58
- }
59
- }
60
- else {
61
- if (Array.isArray(value)) {
62
- value.forEach((current) => {
63
- resolveStaticResourceAttribute(current, paths, staticResourceSet, attributeSet, index + 1);
64
- });
65
- }
66
- else {
67
- try {
68
- Object.values(value).forEach((current) => {
69
- resolveStaticResourceAttribute(current, paths, staticResourceSet, attributeSet, index + 1);
70
- });
71
- }
72
- catch (e) { }
73
- }
74
- }
75
- }
76
- function _simpleGetUsedResourceOfComponent(comp, staticResourceSet = new Set([]), attributeSet = new Set([])) {
77
- var _a, _b, _c;
78
- let staticAttrs = ((_b = (_a = comp.extra) === null || _a === void 0 ? void 0 : _a.staticResourceAttribute) === null || _b === void 0 ? void 0 : _b.length) ? (_c = comp.extra) === null || _c === void 0 ? void 0 : _c.staticResourceAttribute : [];
79
- // 判断是否存在静态资源属性
80
- staticAttrs.forEach((property) => {
81
- processStaticResourceAttribute(comp.attributes, property, staticResourceSet, attributeSet);
82
- });
83
- return { staticResourceSet, attributeSet };
84
- }
85
- exports._simpleGetUsedResourceOfComponent = _simpleGetUsedResourceOfComponent;
86
- // 递归遍历模版,找到静态资源
87
- function getUsedResourcesFromAppRecursively(app, allUsedResources) {
88
- function recursive(list) {
89
- for (let item of list) {
90
- _simpleGetUsedResourceOfComponent(item, allUsedResources);
91
- if (item.items) {
92
- getUsedResourcesFromAppRecursively(item, allUsedResources);
93
- }
94
- }
95
- }
96
- recursive(app.items || []);
97
- recursive(app.templates || []);
98
- }
99
- function getNavUsedStaticResource(config) {
100
- var _a, _b, _c, _d, _e, _f, _g;
101
- const staticResourceAttribute = new Set([]);
102
- const resources = new Set([]);
103
- if ((_b = (_a = config === null || config === void 0 ? void 0 : config.navigationStyle) === null || _a === void 0 ? void 0 : _a.logoPath) === null || _b === void 0 ? void 0 : _b.startsWith('/resources')) {
104
- staticResourceAttribute.add('navigationStyle.logoPath');
105
- resources.add((_c = config === null || config === void 0 ? void 0 : config.navigationStyle) === null || _c === void 0 ? void 0 : _c.logoPath);
106
- }
107
- (_e = (_d = config.menuData) === null || _d === void 0 ? void 0 : _d.forEach) === null || _e === void 0 ? void 0 : _e.call(_d, (menu) => {
108
- getMenuUsedStaticResource(menu, 'menuData.*', staticResourceAttribute, resources);
109
- });
110
- (_g = (_f = config.mobileMenuData) === null || _f === void 0 ? void 0 : _f.forEach) === null || _g === void 0 ? void 0 : _g.call(_f, (menu) => {
111
- getMenuUsedStaticResource(menu, 'mobileMenuData.*', staticResourceAttribute, resources);
112
- });
113
- return {
114
- staticResourceAttribute: Array.from(staticResourceAttribute),
115
- resources: Array.from(resources),
116
- };
117
- }
118
- exports.getNavUsedStaticResource = getNavUsedStaticResource;
119
- function getMenuUsedStaticResource(menu, prefix, staticResourceAttribute, resources) {
120
- var _a;
121
- if ((_a = menu.iconPath) === null || _a === void 0 ? void 0 : _a.startsWith('/resources')) {
122
- staticResourceAttribute.add(`${prefix}.iconPath`);
123
- resources.add(menu.iconPath);
124
- }
125
- menu.children.forEach((sub) => {
126
- getMenuUsedStaticResource(sub, `${prefix}.children.*`, staticResourceAttribute, resources);
127
- });
128
- }
@@ -1,268 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getValidValue = exports.setValidValue = exports.writeDynamicData = exports.writeListeners = exports.readListeners = exports.readDynamicData = exports.readDirectives = exports.readComponents = void 0;
7
- const expression_1 = require("../../expression");
8
- const style_1 = require("./style");
9
- const common_1 = require("./common");
10
- const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
11
- function readComponents(properties = {}, excludeKeys = []) {
12
- var _a;
13
- const cmps /* IWeAppPage['componentInstances'] */ = {};
14
- for (const key in properties) {
15
- if (excludeKeys.indexOf(key) > -1) {
16
- continue;
17
- }
18
- const srcCmp = properties[key];
19
- const srcProps = srcCmp['x-props'];
20
- if (srcProps) {
21
- const cmpParts = srcProps.sourceKey.split(':');
22
- cmps[key] = {};
23
- setValidValue(cmps[key], 'xComponent', {
24
- moduleName: cmpParts[0],
25
- name: cmpParts[1],
26
- });
27
- const componentXProps = {};
28
- setValidValue(componentXProps, 'data', readDynamicData(srcProps));
29
- setValidValue(componentXProps, 'listeners', readListeners(srcProps.listenerInstances));
30
- setValidValue(componentXProps, 'directives', readDirectives(srcProps));
31
- setValidValue(componentXProps, 'style', srcProps.style);
32
- setValidValue(componentXProps, 'commonStyle', (0, style_1.removeInvalidStyleFormValue)(srcProps.commonStyle));
33
- setValidValue(componentXProps, 'styleBindPath', srcProps.styleBindPath);
34
- if ((_a = srcProps.styleBind) === null || _a === void 0 ? void 0 : _a.bindDataPath) {
35
- componentXProps.styleBind = {
36
- type: srcProps.styleBind.type,
37
- value: srcProps.styleBind.bindDataPath,
38
- extra: srcProps.styleBind.extra,
39
- };
40
- }
41
- if ((0, common_1.isValidClassNameListBind)(srcProps.classNameListBind)) {
42
- const classList = srcProps.classNameListBind;
43
- setValidValue(componentXProps, 'classListBind', {
44
- type: classList.type,
45
- value: classList.bindDataPath,
46
- extra: classList.extra,
47
- });
48
- }
49
- if (srcProps.classNameList) {
50
- setValidValue(componentXProps, 'classList', srcProps.classNameList);
51
- }
52
- setValidValue(cmps[key], 'xProps', componentXProps);
53
- setValidValue(cmps[key], 'xIndex', srcCmp['x-index']);
54
- const excludeKeys = (srcProps.dataTypes || [])
55
- .filter((dataType) => dataType.type !== 'slot')
56
- .map((dataType) => dataType.propertyPath);
57
- setValidValue(cmps[key], 'properties', readComponents(srcCmp.properties, excludeKeys));
58
- }
59
- else {
60
- cmps[key] = { properties: readComponents(srcCmp.properties) };
61
- }
62
- }
63
- return cmps;
64
- }
65
- exports.readComponents = readComponents;
66
- function readDirectives(cmp) {
67
- var _a, _b;
68
- const directives /* IWeAppComponentInstance['xProps']['directives'] */ = {};
69
- // 默认为 true,节省体积不记录
70
- if (cmp.data && cmp.data._visible !== true) {
71
- directives.waIf = {
72
- value: cmp.data._visible,
73
- };
74
- }
75
- if ((_a = cmp.dataBinds) === null || _a === void 0 ? void 0 : _a.length) {
76
- const bind = cmp.dataBinds.find((bind) => bind.propertyPath === '_visible');
77
- if (bind) {
78
- const foundDataType = (cmp.dataTypes || []).find((dataType) => dataType.propertyPath === bind.propertyPath);
79
- if (foundDataType && foundDataType.type === 'bind') {
80
- directives.waIf = {
81
- type: bind.type || expression_1.PropBindType.state,
82
- value: bind.bindDataPath,
83
- extra: bind.extra,
84
- };
85
- }
86
- }
87
- const forBind = cmp.dataBinds.find((bind) => bind.propertyPath === '_waFor');
88
- if (forBind) {
89
- directives.waFor = {
90
- type: forBind.type || expression_1.PropBindType.state,
91
- value: forBind.bindDataPath,
92
- extra: forBind.extra,
93
- };
94
- }
95
- const displayBind = cmp.dataBinds.find((bind) => bind.propertyPath === '_display');
96
- if (displayBind) {
97
- directives.waDisplay = {
98
- type: displayBind.type || expression_1.PropBindType.state,
99
- value: displayBind.bindDataPath,
100
- extra: displayBind.extra,
101
- };
102
- }
103
- }
104
- if (directives.waFor && ((_b = cmp.data) === null || _b === void 0 ? void 0 : _b._waForKey)) {
105
- directives.waForKey = {
106
- value: cmp.data._waForKey,
107
- };
108
- }
109
- return directives;
110
- }
111
- exports.readDirectives = readDirectives;
112
- function readDynamicData(cmp) {
113
- var _a, _b;
114
- const data = {};
115
- const ignoredProps = ['_visible', '_waFor', '_waForKey', '_display'];
116
- // Read data
117
- for (const prop in cmp.data) {
118
- if (ignoredProps.indexOf(prop) > -1) {
119
- continue;
120
- }
121
- // Keep null values to generate all wxml attributes
122
- data[prop] = { value: cmp.data[prop] };
123
- }
124
- // Read data binds
125
- (_b = (_a = cmp.dataBinds) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (bind) => {
126
- if (ignoredProps.indexOf(bind.propertyPath) > -1) {
127
- return;
128
- }
129
- const foundDataType = (cmp.dataTypes || []).find((dataType) => dataType.propertyPath === bind.propertyPath);
130
- if (foundDataType && foundDataType.type === 'bind') {
131
- data[bind.propertyPath] = {
132
- type: bind.type || expression_1.PropBindType.state,
133
- value: bind.bindDataPath,
134
- extra: bind.extra,
135
- };
136
- }
137
- });
138
- return data;
139
- }
140
- exports.readDynamicData = readDynamicData;
141
- function readListeners(listenerInstances = []) {
142
- const listeners = listenerInstances.map((act) => {
143
- const fromParts = act.sourceKey.split(':');
144
- return {
145
- key: act.key,
146
- trigger: act.trigger,
147
- type: act.type,
148
- handler: {
149
- moduleName: fromParts[0],
150
- name: fromParts[1],
151
- },
152
- data: readDynamicData(act),
153
- isCapturePhase: act.isCapturePhase,
154
- noPropagation: act.noPropagation,
155
- };
156
- });
157
- return listeners;
158
- }
159
- exports.readListeners = readListeners;
160
- function writeListeners(listeners = []) {
161
- return listeners.map((l) => {
162
- const act = {
163
- key: l.key || '',
164
- sourceKey: `${l.handler.moduleName}:${l.handler.name}`,
165
- trigger: l.trigger,
166
- type: l.type,
167
- data: {},
168
- dataBinds: [],
169
- handler: l.handler,
170
- isCapturePhase: l.isCapturePhase,
171
- noPropagation: l.noPropagation,
172
- };
173
- return writeDynamicData(l.data, act, null);
174
- });
175
- }
176
- exports.writeListeners = writeListeners;
177
- // 处理Listeners动态数据
178
- function writeDynamicData(from = {}, to, properties) {
179
- const act = (0, cloneDeep_1.default)(to);
180
- act.dataTypes = to.dataTypes || [];
181
- for (const prop in from) {
182
- const dv = from[prop];
183
- if (dv.type === 'static' || dv.type === undefined) {
184
- act.data = to.data || {};
185
- act.data[prop] = dv.value;
186
- act.dataTypes.push({
187
- propertyPath: prop,
188
- type: 'static',
189
- });
190
- }
191
- else if (dv.type === 'slot') {
192
- act.dataTypes.push({
193
- propertyPath: prop,
194
- type: 'slot',
195
- });
196
- }
197
- else {
198
- act.dataBinds = to.dataBinds || [];
199
- if (!dv.value.startsWith('!') || dv.value === expression_1.PropBindType.expression) {
200
- act.dataBinds.push({
201
- propertyPath: prop,
202
- bindDataPath: dv.value,
203
- type: dv.type,
204
- extra: dv.extra,
205
- });
206
- }
207
- else {
208
- // check "!" to be compatible with legacy data
209
- const globalStateReg = /^!global./;
210
- let fixedValue = '';
211
- if (globalStateReg.test(dv.value)) {
212
- fixedValue = dv.value.replace(globalStateReg, '!app.state.');
213
- }
214
- else {
215
- fixedValue = dv.value.replace(/^!\w+./, '!$page.');
216
- }
217
- act.dataBinds.push({
218
- propertyPath: prop,
219
- bindDataPath: fixedValue,
220
- type: expression_1.PropBindType.expression,
221
- extra: dv.extra,
222
- });
223
- }
224
- act.dataTypes.push({
225
- propertyPath: prop,
226
- type: 'bind',
227
- });
228
- }
229
- }
230
- // 兼容之前的应用,slot类型的字段从 properties 中取
231
- if (properties) {
232
- Object.keys(properties).forEach((key) => {
233
- const foundOne = act.dataTypes.find((dataType) => dataType.propertyPath === key);
234
- if (foundOne) {
235
- foundOne.type = 'slot';
236
- }
237
- else {
238
- if (!properties[key].xComponent)
239
- act.dataTypes.push({
240
- propertyPath: key,
241
- type: 'slot',
242
- });
243
- }
244
- });
245
- }
246
- return act;
247
- }
248
- exports.writeDynamicData = writeDynamicData;
249
- function setValidValue(target, key, value) {
250
- if (!target) {
251
- return;
252
- }
253
- target[key] = getValidValue(value);
254
- }
255
- exports.setValidValue = setValidValue;
256
- function getValidValue(value) {
257
- if (value === undefined || value === null) {
258
- return;
259
- }
260
- if (Array.isArray(value) && value.length === 0) {
261
- return;
262
- }
263
- if ((0, common_1.isPlainObject)(value) && (0, common_1.isEmptyObj)(value)) {
264
- return;
265
- }
266
- return value;
267
- }
268
- exports.getValidValue = getValidValue;