@cloudbase/cals 0.5.11-alpha.1 → 0.5.11-beta1

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.
@@ -1,211 +1,272 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
1
+ 'use strict';
2
+ var __rest =
3
+ (this && this.__rest) ||
4
+ function (s, e) {
3
5
  var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
7
+ if (s != null && typeof Object.getOwnPropertySymbols === 'function')
8
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
10
+ }
11
11
  return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.parseVersion = exports.processRuntimeCodeResources = exports.deserializeComponentLibraryMeta = exports.deserializeRuntimeComponent = exports.serializeRuntimeComponent = exports.serializeRuntimePage = exports.deserializePlatformApp = exports.serializePlatformApp = exports.deserializePage = exports.serializePage = exports.deserializeComponent = exports.serializeComponent = exports.deserializeDataVariables = exports.deserializeAttributes = exports.serializeAttributes = exports.deserializeDynamicMap = exports.serializeDynamicMap = exports.deserializeValue = exports.serializeValue = exports.generateDefaultCode = exports.getUsedComps = void 0;
15
- const lodash_1 = require("lodash");
16
- const common_1 = require("../../types/platform/common");
17
- const expression_1 = require("../expression");
18
- const common_2 = require("./utils/common");
19
- const style_1 = require("./utils/style");
20
- const runtime_1 = require("./utils/runtime");
21
- const config_1 = require("./utils/version/config");
22
- const template_1 = require("./utils/template");
23
- var common_3 = require("./utils/common");
24
- Object.defineProperty(exports, "getUsedComps", { enumerable: true, get: function () { return common_3.getUsedComps; } });
25
- var template_2 = require("./utils/template");
26
- Object.defineProperty(exports, "generateDefaultCode", { enumerable: true, get: function () { return template_2.generateDefaultCode; } });
27
- function serializeValue({ ctx, key, dynamicValue, scope = 'page', streamlineDefaultValue, }) {
28
- var _a, _b;
29
- let { value } = dynamicValue;
30
- let { dependenciesMap = {} } = ctx;
31
- if (dynamicValue.type && dynamicValue.type !== 'static') {
32
- key = `:${key}`;
33
- switch (dynamicValue.type) {
34
- case expression_1.PropBindType.state:
35
- case expression_1.PropBindType.computed:
36
- case expression_1.PropBindType.dataVar:
37
- case expression_1.PropBindType.stateData:
38
- case expression_1.PropBindType.params: {
39
- const TYPE_MAP = {
40
- [expression_1.PropBindType.prop]: 'props',
41
- [expression_1.PropBindType.state]: 'state',
42
- [expression_1.PropBindType.computed]: 'computed',
43
- [expression_1.PropBindType.dataVar]: 'dataVar',
44
- [expression_1.PropBindType.stateData]: 'dataset.state',
45
- [expression_1.PropBindType.params]: 'dataset.params',
46
- };
47
- let exp = dynamicValue.value;
48
- let reg = /^(.*?)\./;
49
- let prefix = exp;
50
- let matched = exp.match(reg);
51
- if (matched) {
52
- prefix = matched[1];
53
- }
54
- let replacer = scope === 'component' ? '$comp' : '$page';
55
- if (prefix === 'global') {
56
- replacer = '$app';
57
- }
58
- else if (/^comp-\w+/.test(prefix) || /^\$comp_\w+/.test(prefix)) {
59
- replacer = '$comp';
60
- }
61
- replacer += `.${TYPE_MAP[dynamicValue.type]}.`;
62
- value = exp.replace(reg, replacer);
63
- break;
64
- }
65
- case expression_1.PropBindType.prop: {
66
- const isNeg = dynamicValue.value.startsWith('!');
67
- value = isNeg
68
- ? dynamicValue.value.replace('!', '!$comp.props.data.')
69
- : `$comp.props.data.${dynamicValue.value}`;
70
- break;
71
- }
72
- case expression_1.PropBindType.forItem: {
73
- value = `$for.${dynamicValue.value}`;
74
- break;
75
- }
76
- case expression_1.PropBindType.slot: {
77
- value = '$slot';
78
- break;
79
- }
80
- case expression_1.PropBindType.expression: {
81
- // Todo: 表达式转义
82
- // app.state => $app.state
83
- // forItems.state => $for.state
84
- break;
85
- }
12
+ };
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+ exports.parseVersion =
15
+ exports.processRuntimeCodeResources =
16
+ exports.deserializeComponentLibraryMeta =
17
+ exports.deserializeRuntimeComponent =
18
+ exports.serializeRuntimeComponent =
19
+ exports.serializeRuntimePage =
20
+ exports.deserializePlatformApp =
21
+ exports.serializePlatformApp =
22
+ exports.deserializePage =
23
+ exports.serializePage =
24
+ exports.deserializeComponent =
25
+ exports.serializeComponent =
26
+ exports.deserializeDataVariables =
27
+ exports.deserializeAttributes =
28
+ exports.serializeAttributes =
29
+ exports.deserializeDynamicMap =
30
+ exports.serializeDynamicMap =
31
+ exports.deserializeValue =
32
+ exports.serializeValue =
33
+ exports.generateDefaultCode =
34
+ exports.getUsedComps =
35
+ void 0;
36
+ const lodash_1 = require('lodash');
37
+ const common_1 = require('../../types/platform/common');
38
+ const expression_1 = require('../expression');
39
+ const common_2 = require('./utils/common');
40
+ const style_1 = require('./utils/style');
41
+ const runtime_1 = require('./utils/runtime');
42
+ const config_1 = require('./utils/version/config');
43
+ const template_1 = require('./utils/template');
44
+ var common_3 = require('./utils/common');
45
+ Object.defineProperty(exports, 'getUsedComps', {
46
+ enumerable: true,
47
+ get: function () {
48
+ return common_3.getUsedComps;
49
+ },
50
+ });
51
+ var template_2 = require('./utils/template');
52
+ Object.defineProperty(exports, 'generateDefaultCode', {
53
+ enumerable: true,
54
+ get: function () {
55
+ return template_2.generateDefaultCode;
56
+ },
57
+ });
58
+ function serializeValue({ ctx, key, dynamicValue, scope = 'page', streamlineDefaultValue }) {
59
+ var _a, _b;
60
+ let { value } = dynamicValue;
61
+ let { dependenciesMap = {} } = ctx;
62
+ if (dynamicValue.type && dynamicValue.type !== 'static') {
63
+ key = `:${key}`;
64
+ switch (dynamicValue.type) {
65
+ case expression_1.PropBindType.state:
66
+ case expression_1.PropBindType.computed:
67
+ case expression_1.PropBindType.dataVar:
68
+ case expression_1.PropBindType.stateData:
69
+ case expression_1.PropBindType.params: {
70
+ const TYPE_MAP = {
71
+ [expression_1.PropBindType.prop]: 'props',
72
+ [expression_1.PropBindType.state]: 'state',
73
+ [expression_1.PropBindType.computed]: 'computed',
74
+ [expression_1.PropBindType.dataVar]: 'dataVar',
75
+ [expression_1.PropBindType.stateData]: 'dataset.state',
76
+ [expression_1.PropBindType.params]: 'dataset.params',
77
+ };
78
+ let exp = dynamicValue.value;
79
+ let reg = /^(.*?)\./;
80
+ let prefix = exp;
81
+ let matched = exp.match(reg);
82
+ if (matched) {
83
+ prefix = matched[1];
86
84
  }
87
- }
88
- else if (streamlineDefaultValue) {
89
- let { module = '', component = '' } = ctx.component || {};
90
- let sourceKey = `${module}:${component}`;
91
- let config = (_b = (_a = dependenciesMap === null || dependenciesMap === void 0 ? void 0 : dependenciesMap[sourceKey]) === null || _a === void 0 ? void 0 : _a.dataForm) === null || _b === void 0 ? void 0 : _b[key];
92
- if ((config === null || config === void 0 ? void 0 : config.default) === value || (config && config.default === undefined && value === '')) {
93
- value = undefined;
85
+ let replacer = scope === 'component' ? '$comp' : '$page';
86
+ if (prefix === 'global') {
87
+ replacer = '$app';
88
+ } else if (/^comp-\w+/.test(prefix) || /^\$comp_\w+/.test(prefix)) {
89
+ replacer = '$comp';
94
90
  }
91
+ replacer += `.${TYPE_MAP[dynamicValue.type]}.`;
92
+ value = exp.replace(reg, replacer);
93
+ break;
94
+ }
95
+ case expression_1.PropBindType.prop: {
96
+ const isNeg = dynamicValue.value.startsWith('!');
97
+ value = isNeg
98
+ ? dynamicValue.value.replace('!', '!$comp.props.data.')
99
+ : `$comp.props.data.${dynamicValue.value}`;
100
+ break;
101
+ }
102
+ case expression_1.PropBindType.forItem: {
103
+ value = `$for.${dynamicValue.value}`;
104
+ break;
105
+ }
106
+ case expression_1.PropBindType.slot: {
107
+ value = '$slot';
108
+ break;
109
+ }
110
+ case expression_1.PropBindType.expression: {
111
+ // Todo: 表达式转义
112
+ // app.state => $app.state
113
+ // forItems.state => $for.state
114
+ break;
115
+ }
116
+ }
117
+ } else if (streamlineDefaultValue) {
118
+ let { module = '', component = '' } = ctx.component || {};
119
+ let sourceKey = `${module}:${component}`;
120
+ let config =
121
+ (_b =
122
+ (_a = dependenciesMap === null || dependenciesMap === void 0 ? void 0 : dependenciesMap[sourceKey]) === null ||
123
+ _a === void 0
124
+ ? void 0
125
+ : _a.dataForm) === null || _b === void 0
126
+ ? void 0
127
+ : _b[key];
128
+ if (
129
+ (config === null || config === void 0 ? void 0 : config.default) === value ||
130
+ (config && config.default === undefined && value === '')
131
+ ) {
132
+ value = undefined;
95
133
  }
96
- return { key, value, extra: dynamicValue.extra };
134
+ }
135
+ return { key, value, extra: dynamicValue.extra };
97
136
  }
98
137
  exports.serializeValue = serializeValue;
99
138
  const DYNAMIC_KEY_REG = /^:(.*)$/;
100
139
  function deserializeValue(ctx, key, value, extra) {
101
- var _a;
102
- let matched = key.match(DYNAMIC_KEY_REG);
103
- if (matched) {
104
- let key = matched[1];
105
- let type = expression_1.PropBindType.expression;
140
+ var _a;
141
+ let matched = key.match(DYNAMIC_KEY_REG);
142
+ if (matched) {
143
+ let key = matched[1];
144
+ let type = expression_1.PropBindType.expression;
145
+ try {
146
+ let parser = new expression_1.DynamicValueParser(value, {
147
+ pageId: (_a = ctx.page) === null || _a === void 0 ? void 0 : _a.id,
148
+ });
149
+ let res = parser.parse();
150
+ type = res.type;
151
+ if ((res === null || res === void 0 ? void 0 : res.value) != undefined) {
152
+ value = res.value;
153
+ }
154
+ } catch (e) {
155
+ if (typeof value === 'boolean') {
156
+ type = expression_1.PropBindType.static;
157
+ } else {
158
+ type = expression_1.PropBindType.expression;
106
159
  try {
107
- let parser = new expression_1.DynamicValueParser(value, { pageId: (_a = ctx.page) === null || _a === void 0 ? void 0 : _a.id });
108
- let res = parser.parse();
109
- type = res.type;
110
- if ((res === null || res === void 0 ? void 0 : res.value) != undefined) {
111
- value = res.value;
112
- }
113
- }
114
- catch (e) {
115
- if (typeof value === 'boolean') {
116
- type = expression_1.PropBindType.static;
117
- }
118
- else {
119
- type = expression_1.PropBindType.expression;
120
- try {
121
- value = value.replace(/\$app\./g, 'app.').replace(/\$for./g, 'forItems.');
122
- }
123
- catch (e) { }
124
- }
125
- }
126
- return {
127
- key,
128
- value: { type, value, extra },
129
- };
130
- }
131
- else {
132
- return {
133
- key,
134
- value: value === undefined
135
- ? undefined
136
- : {
137
- type: undefined /* 'static'*/,
138
- value,
139
- extra,
140
- },
141
- };
160
+ value = value.replace(/\$app\./g, 'app.').replace(/\$for./g, 'forItems.');
161
+ } catch (e) {}
162
+ }
142
163
  }
164
+ return {
165
+ key,
166
+ value: { type, value, extra },
167
+ };
168
+ } else {
169
+ return {
170
+ key,
171
+ value:
172
+ value === undefined
173
+ ? undefined
174
+ : {
175
+ type: undefined /* 'static'*/,
176
+ value,
177
+ extra,
178
+ },
179
+ };
180
+ }
143
181
  }
144
182
  exports.deserializeValue = deserializeValue;
145
183
  function serializeDynamicMap(props) {
146
- return serializeDynamicMapWithExtra(props).data;
184
+ return serializeDynamicMapWithExtra(props).data;
147
185
  }
148
186
  exports.serializeDynamicMap = serializeDynamicMap;
149
- function serializeDynamicMapWithExtra({ ctx, map = {}, scope = 'page', streamlineDefaultValue, }) {
150
- let data = {};
151
- let extra = {};
152
- Object.keys(map)
153
- .sort((a, b) => {
154
- const aPath = a.split('.');
155
- const bPath = b.split('.');
156
- const isADynamic = aPath[0].startsWith(':');
157
- const isBDynamic = bPath[0].startsWith(':');
158
- if (isADynamic !== isBDynamic) {
159
- return isADynamic ? -1 : 1;
160
- }
161
- else {
162
- return aPath > bPath ? 1 : -1;
163
- }
187
+ function serializeDynamicMapWithExtra({ ctx, map = {}, scope = 'page', streamlineDefaultValue }) {
188
+ let data = {};
189
+ let extra = {};
190
+ Object.keys(map)
191
+ .sort((a, b) => {
192
+ const aPath = a.split('.');
193
+ const bPath = b.split('.');
194
+ const isADynamic = aPath[0].startsWith(':');
195
+ const isBDynamic = bPath[0].startsWith(':');
196
+ if (isADynamic !== isBDynamic) {
197
+ return isADynamic ? -1 : 1;
198
+ } else {
199
+ return aPath > bPath ? 1 : -1;
200
+ }
164
201
  })
165
- .forEach((key) => {
166
- let { key: processedKey, value: processedValue, extra: processedExtra, } = serializeValue({
167
- ctx,
168
- key,
169
- dynamicValue: map[key],
170
- scope,
171
- streamlineDefaultValue,
172
- });
173
- let matched = processedKey.match(/^:(.*)$/);
174
- let originKey = processedKey;
175
- if (matched) {
176
- originKey = matched[1];
177
- (0, lodash_1.unset)(data, originKey);
178
- }
179
- const originKeyArr = originKey.split('.');
180
- if ((0, lodash_1.get)(data, processedKey) == undefined) {
181
- /* 选区结构处理 [formily] to [CALS] */
182
- if (Array.isArray(processedValue) && (processedValue === null || processedValue === void 0 ? void 0 : processedValue.some((item) => !!(item === null || item === void 0 ? void 0 : item.selectableBlock)))) {
183
- let valueTmp = (0, lodash_1.cloneDeep)(processedValue);
184
- processedValue = valueTmp === null || valueTmp === void 0 ? void 0 : valueTmp.map((_value) => {
185
- var _a, _b, _c;
186
- const xProp = (_a = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null || _a === void 0 ? void 0 : _a['x-props'];
187
- const xComponent = (_c = (_b = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null || _b === void 0 ? void 0 : _b['x-component']) === null || _c === void 0 ? void 0 : _c.toLowerCase();
188
- const module = xComponent === null || xComponent === void 0 ? void 0 : xComponent.split(':')[0];
189
- const component = xComponent === null || xComponent === void 0 ? void 0 : xComponent.split(':')[1];
190
- if (xProp &&
191
- config_1.MODULE_SELECTABLEBLOCK_REGEX.test(module) &&
192
- config_1.COMPONENT_SELECTABLEBLOCK_WHITELIST.includes(component)) {
193
- _value.selectableBlock = serializeRuntimeComponent(ctx, _value.selectableBlock);
194
- }
195
- return _value;
202
+ .forEach((key) => {
203
+ let {
204
+ key: processedKey,
205
+ value: processedValue,
206
+ extra: processedExtra,
207
+ } = serializeValue({
208
+ ctx,
209
+ key,
210
+ dynamicValue: map[key],
211
+ scope,
212
+ streamlineDefaultValue,
213
+ });
214
+ let matched = processedKey.match(/^:(.*)$/);
215
+ let originKey = processedKey;
216
+ if (matched) {
217
+ originKey = matched[1];
218
+ (0, lodash_1.unset)(data, originKey);
219
+ }
220
+ const originKeyArr = originKey.split('.');
221
+ if ((0, lodash_1.get)(data, processedKey) == undefined) {
222
+ /* 选区结构处理 [formily] to [CALS] */
223
+ if (
224
+ Array.isArray(processedValue) &&
225
+ (processedValue === null || processedValue === void 0
226
+ ? void 0
227
+ : processedValue.some((item) => !!(item === null || item === void 0 ? void 0 : item.selectableBlock)))
228
+ ) {
229
+ let valueTmp = (0, lodash_1.cloneDeep)(processedValue);
230
+ processedValue =
231
+ valueTmp === null || valueTmp === void 0
232
+ ? void 0
233
+ : valueTmp.map((_value) => {
234
+ var _a, _b, _c;
235
+ const xProp =
236
+ (_a = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null ||
237
+ _a === void 0
238
+ ? void 0
239
+ : _a['x-props'];
240
+ const xComponent =
241
+ (_c =
242
+ (_b = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null ||
243
+ _b === void 0
244
+ ? void 0
245
+ : _b['x-component']) === null || _c === void 0
246
+ ? void 0
247
+ : _c.toLowerCase();
248
+ const module = xComponent === null || xComponent === void 0 ? void 0 : xComponent.split(':')[0];
249
+ const component = xComponent === null || xComponent === void 0 ? void 0 : xComponent.split(':')[1];
250
+ if (
251
+ xProp &&
252
+ config_1.MODULE_SELECTABLEBLOCK_REGEX.test(module) &&
253
+ config_1.COMPONENT_SELECTABLEBLOCK_WHITELIST.includes(component)
254
+ ) {
255
+ _value.selectableBlock = serializeRuntimeComponent(ctx, _value.selectableBlock);
256
+ }
257
+ return _value;
196
258
  });
197
- }
198
- // 为动态数据且有多级,将{":range.0.label": "$page.dataset.state.test1"}转为{ range: [{ label: "$page.dataset.state.test1"}] }
199
- if (matched && originKeyArr.length >= 2) {
200
- (0, lodash_1.set)(data, replaceWithColon(originKey), (0, lodash_1.cloneDeep)(processedValue));
201
- }
202
- else {
203
- data[processedKey] = (0, lodash_1.cloneDeep)(processedValue);
204
- }
205
259
  }
206
- extra[originKey] = processedExtra;
260
+ // 为动态数据且有多级,将{":range.0.label": "$page.dataset.state.test1"}转为{ range: [{ label: "$page.dataset.state.test1"}] }
261
+ if (matched && originKeyArr.length >= 2) {
262
+ (0, lodash_1.set)(data, replaceWithColon(originKey), (0, lodash_1.cloneDeep)(processedValue));
263
+ } else {
264
+ data[processedKey] = (0, lodash_1.cloneDeep)(processedValue);
265
+ }
266
+ }
267
+ extra[originKey] = processedExtra;
207
268
  });
208
- return { data, extra };
269
+ return { data, extra };
209
270
  }
210
271
  /**
211
272
  * 将{ range: [{ label: "$page.dataset.state.test1"}] }的path range.0.label 转为range.0.:label
@@ -213,10 +274,10 @@ function serializeDynamicMapWithExtra({ ctx, map = {}, scope = 'page', streamlin
213
274
  * @returns
214
275
  */
215
276
  function replaceWithColon(key) {
216
- const keyArr = key.split('.');
217
- // 最深一层前面加上":"
218
- keyArr[keyArr.length - 1] = `:${keyArr[keyArr.length - 1]}`;
219
- return keyArr.join('.');
277
+ const keyArr = key.split('.');
278
+ // 最深一层前面加上":"
279
+ keyArr[keyArr.length - 1] = `:${keyArr[keyArr.length - 1]}`;
280
+ return keyArr.join('.');
220
281
  }
221
282
  /**
222
283
  * 预处理,先还原数据。
@@ -228,97 +289,126 @@ function replaceWithColon(key) {
228
289
  * @returns
229
290
  */
230
291
  function recoverSynamicMap(parent, current, path = '') {
231
- Object.keys(current).forEach((key) => {
232
- let value = current[key];
233
- if ((0, lodash_1.isArray)(value)) {
234
- // 注意如果是 selectableBlock 独立处理
235
- if (value === null || value === void 0 ? void 0 : value.some((item) => !!(item === null || item === void 0 ? void 0 : item.selectableBlock))) {
236
- return;
237
- }
238
- // 数组必须在前面
239
- value.forEach((valueItem, valueIndex) => {
240
- if ((0, lodash_1.isObject)(valueItem)) {
241
- valueItem = recoverSynamicMap(parent, valueItem, `${path === '' ? '' : `${path}.`}${key}.${valueIndex}`);
242
- }
243
- });
292
+ Object.keys(current).forEach((key) => {
293
+ let value = current[key];
294
+ if ((0, lodash_1.isArray)(value)) {
295
+ // 注意如果是 selectableBlock 独立处理
296
+ if (
297
+ value === null || value === void 0
298
+ ? void 0
299
+ : value.some((item) => !!(item === null || item === void 0 ? void 0 : item.selectableBlock))
300
+ ) {
301
+ return;
302
+ }
303
+ // 数组必须在前面
304
+ value.forEach((valueItem, valueIndex) => {
305
+ if ((0, lodash_1.isObject)(valueItem)) {
306
+ valueItem = recoverSynamicMap(parent, valueItem, `${path === '' ? '' : `${path}.`}${key}.${valueIndex}`);
244
307
  }
245
- else if ((0, lodash_1.isObject)(value)) {
246
- value = recoverSynamicMap(parent, value, `${path === '' ? '' : `${path}.`}${key}`);
308
+ });
309
+ } else if ((0, lodash_1.isObject)(value)) {
310
+ value = recoverSynamicMap(parent, value, `${path === '' ? '' : `${path}.`}${key}`);
311
+ } else {
312
+ const matched = key.match(DYNAMIC_KEY_REG);
313
+ if (matched) {
314
+ parent[`:${path === '' ? '' : `${path}.`}${matched[1]}`] = current[key];
315
+ if (current !== parent) {
316
+ // 如果是第一层级,说明current和parent相等,不unset
317
+ (0, lodash_1.unset)(current, key);
247
318
  }
248
- else {
249
- const matched = key.match(DYNAMIC_KEY_REG);
250
- if (matched) {
251
- parent[`:${path === '' ? '' : `${path}.`}${matched[1]}`] = current[key];
252
- if (current !== parent) {
253
- // 如果是第一层级,说明current和parent相等,不unset
254
- (0, lodash_1.unset)(current, key);
255
- }
256
- }
257
- }
258
- });
259
- return current;
319
+ }
320
+ }
321
+ });
322
+ return current;
260
323
  }
261
324
  function deserializeDynamicMap(ctx, map, extraMap) {
262
- var _a, _b;
263
- let data = {};
264
- const clonedMap = (0, lodash_1.cloneDeep)(map);
265
- // 还原flatten path
266
- map = recoverSynamicMap(clonedMap, clonedMap, '');
267
- for (let key in map || {}) {
268
- let value = map === null || map === void 0 ? void 0 : map[key];
269
- let matched = key.match(DYNAMIC_KEY_REG);
270
- let { key: processedKey, value: processedValue } = deserializeValue(ctx, key, value, extraMap === null || extraMap === void 0 ? void 0 : extraMap[matched ? matched[1] : key]);
271
- /* 选区结构处理 [CALS] to [formily] */
272
- if (Array.isArray(processedValue === null || processedValue === void 0 ? void 0 : processedValue.value) && ((_a = processedValue === null || processedValue === void 0 ? void 0 : processedValue.value) === null || _a === void 0 ? void 0 : _a.some((item) => !!(item === null || item === void 0 ? void 0 : item.selectableBlock)))) {
273
- (_b = processedValue === null || processedValue === void 0 ? void 0 : processedValue.value) === null || _b === void 0 ? void 0 : _b.forEach((_value) => {
274
- var _a, _b, _c, _d;
275
- const module = (_b = (_a = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null || _a === void 0 ? void 0 : _a.module) === null || _b === void 0 ? void 0 : _b.toLowerCase();
276
- const component = (_d = (_c = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null || _c === void 0 ? void 0 : _c.component) === null || _d === void 0 ? void 0 : _d.toLowerCase();
277
- if (_value.selectableBlock &&
278
- config_1.MODULE_SELECTABLEBLOCK_REGEX.test(module) &&
279
- config_1.COMPONENT_SELECTABLEBLOCK_WHITELIST.includes(component)) {
280
- _value.selectableBlock = deserializeRuntimeComponent(ctx, _value.selectableBlock);
281
- }
282
- return _value;
283
- });
284
- }
285
- if (processedValue !== undefined) {
286
- data[processedKey] = processedValue;
287
- }
325
+ var _a, _b;
326
+ let data = {};
327
+ const clonedMap = (0, lodash_1.cloneDeep)(map);
328
+ // 还原flatten path
329
+ map = recoverSynamicMap(clonedMap, clonedMap, '');
330
+ for (let key in map || {}) {
331
+ let value = map === null || map === void 0 ? void 0 : map[key];
332
+ let matched = key.match(DYNAMIC_KEY_REG);
333
+ let { key: processedKey, value: processedValue } = deserializeValue(
334
+ ctx,
335
+ key,
336
+ value,
337
+ extraMap === null || extraMap === void 0 ? void 0 : extraMap[matched ? matched[1] : key],
338
+ );
339
+ /* 选区结构处理 [CALS] to [formily] */
340
+ if (
341
+ Array.isArray(processedValue === null || processedValue === void 0 ? void 0 : processedValue.value) &&
342
+ ((_a = processedValue === null || processedValue === void 0 ? void 0 : processedValue.value) === null ||
343
+ _a === void 0
344
+ ? void 0
345
+ : _a.some((item) => !!(item === null || item === void 0 ? void 0 : item.selectableBlock)))
346
+ ) {
347
+ (_b = processedValue === null || processedValue === void 0 ? void 0 : processedValue.value) === null ||
348
+ _b === void 0
349
+ ? void 0
350
+ : _b.forEach((_value) => {
351
+ var _a, _b, _c, _d;
352
+ const module =
353
+ (_b =
354
+ (_a = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null || _a === void 0
355
+ ? void 0
356
+ : _a.module) === null || _b === void 0
357
+ ? void 0
358
+ : _b.toLowerCase();
359
+ const component =
360
+ (_d =
361
+ (_c = _value === null || _value === void 0 ? void 0 : _value.selectableBlock) === null || _c === void 0
362
+ ? void 0
363
+ : _c.component) === null || _d === void 0
364
+ ? void 0
365
+ : _d.toLowerCase();
366
+ if (
367
+ _value.selectableBlock &&
368
+ config_1.MODULE_SELECTABLEBLOCK_REGEX.test(module) &&
369
+ config_1.COMPONENT_SELECTABLEBLOCK_WHITELIST.includes(component)
370
+ ) {
371
+ _value.selectableBlock = deserializeRuntimeComponent(ctx, _value.selectableBlock);
372
+ }
373
+ return _value;
374
+ });
375
+ }
376
+ if (processedValue !== undefined) {
377
+ data[processedKey] = processedValue;
288
378
  }
289
- return data;
379
+ }
380
+ return data;
290
381
  }
291
382
  exports.deserializeDynamicMap = deserializeDynamicMap;
292
383
  function serializeAttributes(ctx, scope, attributes = {}) {
293
- var _a;
294
- return (_a = serializeAttributesWithExtra(ctx, scope, attributes)) === null || _a === void 0 ? void 0 : _a.data;
384
+ var _a;
385
+ return (_a = serializeAttributesWithExtra(ctx, scope, attributes)) === null || _a === void 0 ? void 0 : _a.data;
295
386
  }
296
387
  exports.serializeAttributes = serializeAttributes;
297
388
  function serializeAttributesWithExtra(ctx, scope, attributes = {}) {
298
- return serializeDynamicMapWithExtra({
299
- ctx,
300
- scope,
301
- map: attributes,
302
- streamlineDefaultValue: ctx.streamlineDefaultValue,
303
- });
389
+ return serializeDynamicMapWithExtra({
390
+ ctx,
391
+ scope,
392
+ map: attributes,
393
+ streamlineDefaultValue: ctx.streamlineDefaultValue,
394
+ });
304
395
  }
305
396
  function deserializeAttributes(ctx, attributes = {}, attributesExtraData = {}) {
306
- const reservedAttributes = ['style', 'commonStyle', 'class'];
307
- const reservedAttributesMap = reservedAttributes.reduce((map, key) => {
308
- map[key] = true;
309
- map[`:${key}`] = true;
310
- return map;
311
- }, {});
312
- let restAttributes = {};
313
- for (let key in attributes) {
314
- if (reservedAttributesMap[key]) {
315
- continue;
316
- }
317
- else {
318
- restAttributes[key] = attributes[key];
319
- }
397
+ const reservedAttributes = ['style', 'commonStyle', 'class'];
398
+ const reservedAttributesMap = reservedAttributes.reduce((map, key) => {
399
+ map[key] = true;
400
+ map[`:${key}`] = true;
401
+ return map;
402
+ }, {});
403
+ let restAttributes = {};
404
+ for (let key in attributes) {
405
+ if (reservedAttributesMap[key]) {
406
+ continue;
407
+ } else {
408
+ restAttributes[key] = attributes[key];
320
409
  }
321
- return deserializeDynamicMap(ctx, restAttributes, attributesExtraData);
410
+ }
411
+ return deserializeDynamicMap(ctx, restAttributes, attributesExtraData);
322
412
  }
323
413
  exports.deserializeAttributes = deserializeAttributes;
324
414
  /**
@@ -326,452 +416,607 @@ exports.deserializeAttributes = deserializeAttributes;
326
416
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
327
417
  */
328
418
  function serializeDataset(ctx, dataset) {
329
- if (!isDatasetNeedToProcess(dataset))
330
- return dataset;
331
- const result = JSON.parse(JSON.stringify(dataset));
332
- Object.values(result.state).forEach((state) => {
333
- var _a, _b, _c, _d;
334
- if (state.varType !== 'datasource')
335
- return;
336
- if ((_a = state.initMethod) === null || _a === void 0 ? void 0 : _a.params) {
337
- state.initMethod.params = (_b = serializeDynamicMapWithExtra({
338
- ctx,
339
- map: state.initMethod.params,
340
- })) === null || _b === void 0 ? void 0 : _b.data;
341
- }
342
- if ((_c = state.updateMethod) === null || _c === void 0 ? void 0 : _c.params) {
343
- state.updateMethod.params = (_d = serializeDynamicMapWithExtra({
344
- ctx,
345
- map: state.updateMethod.params,
346
- })) === null || _d === void 0 ? void 0 : _d.data;
347
- }
348
- });
349
- return result;
419
+ if (!isDatasetNeedToProcess(dataset)) return dataset;
420
+ const result = JSON.parse(JSON.stringify(dataset));
421
+ Object.values(result.state).forEach((state) => {
422
+ var _a, _b, _c, _d;
423
+ if (state.varType !== 'datasource') return;
424
+ if ((_a = state.initMethod) === null || _a === void 0 ? void 0 : _a.params) {
425
+ state.initMethod.params =
426
+ (_b = serializeDynamicMapWithExtra({
427
+ ctx,
428
+ map: state.initMethod.params,
429
+ })) === null || _b === void 0
430
+ ? void 0
431
+ : _b.data;
432
+ }
433
+ if ((_c = state.updateMethod) === null || _c === void 0 ? void 0 : _c.params) {
434
+ state.updateMethod.params =
435
+ (_d = serializeDynamicMapWithExtra({
436
+ ctx,
437
+ map: state.updateMethod.params,
438
+ })) === null || _d === void 0
439
+ ? void 0
440
+ : _d.data;
441
+ }
442
+ });
443
+ return result;
350
444
  }
351
445
  /**
352
446
  * 将dataset({state: {}, params: {}})从 cals 结构转换为weapp结构
353
447
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
354
448
  */
355
449
  function deserializeDataset(ctx, dataset) {
356
- if (!isDatasetNeedToProcess(dataset))
357
- return dataset;
358
- // 克隆, 避免引用问题
359
- const result = JSON.parse(JSON.stringify(dataset));
360
- Object.values(result.state).forEach((state) => {
361
- var _a, _b;
362
- if (state.varType !== 'datasource')
363
- return;
364
- if ((_a = state.initMethod) === null || _a === void 0 ? void 0 : _a.params) {
365
- state.initMethod.params = deserializeDynamicMap(ctx, state.initMethod.params);
366
- }
367
- if ((_b = state.updateMethod) === null || _b === void 0 ? void 0 : _b.params) {
368
- state.updateMethod.params = deserializeDynamicMap(ctx, state.updateMethod.params);
369
- }
370
- });
371
- return result;
450
+ if (!isDatasetNeedToProcess(dataset)) return dataset;
451
+ // 克隆, 避免引用问题
452
+ const result = JSON.parse(JSON.stringify(dataset));
453
+ Object.values(result.state).forEach((state) => {
454
+ var _a, _b;
455
+ if (state.varType !== 'datasource') return;
456
+ if ((_a = state.initMethod) === null || _a === void 0 ? void 0 : _a.params) {
457
+ state.initMethod.params = deserializeDynamicMap(ctx, state.initMethod.params);
458
+ }
459
+ if ((_b = state.updateMethod) === null || _b === void 0 ? void 0 : _b.params) {
460
+ state.updateMethod.params = deserializeDynamicMap(ctx, state.updateMethod.params);
461
+ }
462
+ });
463
+ return result;
372
464
  }
373
465
  /**
374
466
  * dataset 是否需要转换处理
375
467
  * dataset 为空, 或者无数据源变量, 或者变量中未使用入参, 则不需要进行转换
376
468
  */
377
469
  function isDatasetNeedToProcess(dataset) {
378
- if (!dataset || !dataset.state)
379
- return false;
380
- const hasNoParams = Object.values(dataset.state).every((item) => {
381
- var _a, _b;
382
- return item.varType !== 'datasource' || !(((_a = item.initMethod) === null || _a === void 0 ? void 0 : _a.params) || ((_b = item.updateMethod) === null || _b === void 0 ? void 0 : _b.params));
383
- });
384
- if (hasNoParams)
385
- return false;
386
- return true;
470
+ if (!dataset || !dataset.state) return false;
471
+ const hasNoParams = Object.values(dataset.state).every((item) => {
472
+ var _a, _b;
473
+ return (
474
+ item.varType !== 'datasource' ||
475
+ !(
476
+ ((_a = item.initMethod) === null || _a === void 0 ? void 0 : _a.params) ||
477
+ ((_b = item.updateMethod) === null || _b === void 0 ? void 0 : _b.params)
478
+ )
479
+ );
480
+ });
481
+ if (hasNoParams) return false;
482
+ return true;
387
483
  }
388
484
  function serializeDirecties(ctx, directives, scope = 'page') {
389
- var _a;
390
- let processed = {
391
- ':if': directives.waIf
392
- ? serializeValue({
393
- ctx,
394
- key: 'waIf',
395
- dynamicValue: directives.waIf,
396
- scope,
397
- }).value
398
- : undefined,
399
- ':for': directives.waFor
400
- ? `${(_a = ctx.component) === null || _a === void 0 ? void 0 : _a.id} in ${serializeValue({
401
- ctx,
402
- key: 'waFor',
403
- dynamicValue: directives.waFor,
404
- scope,
405
- }).value}`
406
- : undefined,
407
- key: directives.waForKey
408
- ? serializeValue({
409
- ctx,
410
- key: 'waForKey',
411
- dynamicValue: directives.waForKey,
412
- scope,
413
- }).value
414
- : undefined,
415
- };
416
- for (let key in processed) {
417
- let map = processed;
418
- if (map[key] !== undefined) {
419
- return processed;
420
- }
485
+ var _a;
486
+ let processed = {
487
+ ':if': directives.waIf
488
+ ? serializeValue({
489
+ ctx,
490
+ key: 'waIf',
491
+ dynamicValue: directives.waIf,
492
+ scope,
493
+ }).value
494
+ : undefined,
495
+ ':for': directives.waFor
496
+ ? `${(_a = ctx.component) === null || _a === void 0 ? void 0 : _a.id} in ${
497
+ serializeValue({
498
+ ctx,
499
+ key: 'waFor',
500
+ dynamicValue: directives.waFor,
501
+ scope,
502
+ }).value
503
+ }`
504
+ : undefined,
505
+ key: directives.waForKey
506
+ ? serializeValue({
507
+ ctx,
508
+ key: 'waForKey',
509
+ dynamicValue: directives.waForKey,
510
+ scope,
511
+ }).value
512
+ : undefined,
513
+ };
514
+ for (let key in processed) {
515
+ let map = processed;
516
+ if (map[key] !== undefined) {
517
+ return processed;
421
518
  }
422
- return undefined;
519
+ }
520
+ return undefined;
423
521
  }
424
522
  function deserializeDirecties(ctx, directives) {
425
- let waIf = (directives === null || directives === void 0 ? void 0 : directives[':if']) !== undefined ? deserializeValue(ctx, ':if', directives[':if']).value : { value: true };
426
- let waFor = (directives === null || directives === void 0 ? void 0 : directives[':for']) ? deserializeValue(ctx, ':for', directives[':for']).value : undefined;
427
- const waForKey = (directives === null || directives === void 0 ? void 0 : directives.key) ? deserializeValue(ctx, 'key', directives.key).value : undefined;
428
- if (waFor) {
429
- let { type, value } = waFor;
430
- if (type === expression_1.PropBindType.expression) {
431
- waFor.value = value.replace(/^(.*?in\s)/, '');
432
- }
523
+ let waIf =
524
+ (directives === null || directives === void 0 ? void 0 : directives[':if']) !== undefined
525
+ ? deserializeValue(ctx, ':if', directives[':if']).value
526
+ : { value: true };
527
+ let waFor = (directives === null || directives === void 0 ? void 0 : directives[':for'])
528
+ ? deserializeValue(ctx, ':for', directives[':for']).value
529
+ : undefined;
530
+ const waForKey = (directives === null || directives === void 0 ? void 0 : directives.key)
531
+ ? deserializeValue(ctx, 'key', directives.key).value
532
+ : undefined;
533
+ if (waFor) {
534
+ let { type, value } = waFor;
535
+ if (type === expression_1.PropBindType.expression) {
536
+ waFor.value = value.replace(/^(.*?in\s)/, '');
433
537
  }
434
- let processed = {
435
- waIf: (waIf === null || waIf === void 0 ? void 0 : waIf.value) === true ? undefined : waIf,
436
- waFor,
437
- waForKey,
438
- };
439
- for (let key in processed) {
440
- let map = processed;
441
- if (map[key] !== undefined) {
442
- return processed;
443
- }
538
+ }
539
+ let processed = {
540
+ waIf: (waIf === null || waIf === void 0 ? void 0 : waIf.value) === true ? undefined : waIf,
541
+ waFor,
542
+ waForKey,
543
+ };
544
+ for (let key in processed) {
545
+ let map = processed;
546
+ if (map[key] !== undefined) {
547
+ return processed;
444
548
  }
445
- return undefined;
549
+ }
550
+ return undefined;
446
551
  }
447
552
  /**
448
553
  * TODO
449
554
  * heander 更新为表达式
450
555
  */
451
556
  function serializeListener(ctx, listener) {
452
- const { data, extra = {} } = serializeDynamicMapWithExtra({
453
- ctx,
454
- map: listener.data,
557
+ const { data, extra = {} } =
558
+ serializeDynamicMapWithExtra({
559
+ ctx,
560
+ map: listener.data,
455
561
  }) || {};
456
- const platfromListener = {
457
- id: listener.key,
458
- eventName: listener.trigger,
459
- type: listener.type,
460
- handler: {
461
- name: listener.handler.name,
462
- module: /^comp-\w+$/.test(listener.handler.moduleName) ? '$comp' : listener.handler.moduleName,
463
- params: data,
464
- },
465
- isCapturePhase: listener.isCapturePhase,
562
+ let platfromListener = {};
563
+ if (listener.handler) {
564
+ platfromListener = {
565
+ id: listener.key,
566
+ eventName: listener.trigger,
567
+ type: listener.type,
568
+ handler: {
569
+ name: listener.handler.name,
570
+ module: /^comp-\w+$/.test(listener.handler.moduleName) ? '$comp' : listener.handler.moduleName,
571
+ params: data,
572
+ },
573
+ isCapturePhase: listener.isCapturePhase,
466
574
  };
467
- if (Object.keys(extra).some((key) => extra[key] !== undefined)) {
468
- if (!platfromListener.extra) {
469
- platfromListener.extra = {};
470
- }
471
- platfromListener.extra.handlerParamExtraData = extra;
575
+ } else {
576
+ platfromListener = {
577
+ id: listener.key,
578
+ eventName: listener.trigger,
579
+ type: listener.type,
580
+ handler: {},
581
+ jsCode: listener.jsCode,
582
+ isCapturePhase: listener.isCapturePhase,
583
+ };
584
+ }
585
+ if (Object.keys(extra).some((key) => extra[key] !== undefined)) {
586
+ if (!platfromListener.extra) {
587
+ platfromListener.extra = {};
472
588
  }
473
- return platfromListener;
589
+ platfromListener.extra.handlerParamExtraData = extra;
590
+ }
591
+ return platfromListener;
474
592
  }
475
593
  function deserializeListener(ctx, listener) {
476
- var _a, _b, _c, _d;
477
- let processed = {
478
- key: listener.id,
479
- trigger: listener.eventName,
480
- type: listener.type,
481
- handler: {
482
- name: (_a = listener.handler) === null || _a === void 0 ? void 0 : _a.name,
483
- moduleName: (_b = listener.handler) === null || _b === void 0 ? void 0 : _b.module,
484
- },
485
- data: deserializeDynamicMap(ctx, ((_c = listener.handler) === null || _c === void 0 ? void 0 : _c.params) || {}, ((_d = listener === null || listener === void 0 ? void 0 : listener.extra) === null || _d === void 0 ? void 0 : _d.handlerParamExtraData) || {}),
486
- isCapturePhase: !!listener.isCapturePhase,
487
- // TODO
488
- noPropagation: !!listener.noPropagation,
489
- };
490
- return processed;
594
+ var _a, _b, _c, _d;
595
+ let processed = {
596
+ key: listener.id,
597
+ trigger: listener.eventName,
598
+ type: listener.type,
599
+ handler: {
600
+ name: (_a = listener.handler) === null || _a === void 0 ? void 0 : _a.name,
601
+ moduleName: (_b = listener.handler) === null || _b === void 0 ? void 0 : _b.module,
602
+ },
603
+ data: deserializeDynamicMap(
604
+ ctx,
605
+ ((_c = listener.handler) === null || _c === void 0 ? void 0 : _c.params) || {},
606
+ ((_d = listener === null || listener === void 0 ? void 0 : listener.extra) === null || _d === void 0
607
+ ? void 0
608
+ : _d.handlerParamExtraData) || {},
609
+ ),
610
+ isCapturePhase: !!listener.isCapturePhase,
611
+ // TODO
612
+ noPropagation: !!listener.noPropagation,
613
+ };
614
+ if (listener.jsCode) {
615
+ processed.jsCode = listener.jsCode;
616
+ }
617
+ return processed;
491
618
  }
492
619
  function serializeDataVariables(ctx, data) {
493
- let { title } = data, restData = __rest(data, ["title"]);
494
- return Object.assign(Object.assign({ varType: 'datasource' }, restData), { label: title });
620
+ let { title } = data,
621
+ restData = __rest(data, ['title']);
622
+ return Object.assign(Object.assign({ varType: 'datasource' }, restData), { label: title });
495
623
  }
496
624
  function deserializeDataVariables(ctx, data) {
497
- let { label } = data, restData = __rest(data, ["label"]);
498
- return Object.assign(Object.assign({}, restData), { title: label });
625
+ let { label } = data,
626
+ restData = __rest(data, ['label']);
627
+ return Object.assign(Object.assign({}, restData), { title: label });
499
628
  }
500
629
  exports.deserializeDataVariables = deserializeDataVariables;
501
630
  function serializeCodeSource(ctx, data) {
502
- const { type } = data;
503
- return Object.assign(Object.assign({}, data), { type: common_1.EResourceType.CODE, codeType: type });
631
+ const { type } = data;
632
+ return Object.assign(Object.assign({}, data), { type: common_1.EResourceType.CODE, codeType: type });
504
633
  }
505
634
  function deserializeCodeResource(ctx, data) {
506
- const { type, codeType } = data, resData = __rest(data, ["type", "codeType"]);
507
- return Object.assign(Object.assign({}, resData), { type: codeType });
635
+ const { type, codeType } = data,
636
+ resData = __rest(data, ['type', 'codeType']);
637
+ return Object.assign(Object.assign({}, resData), { type: codeType });
508
638
  }
509
639
  function serializeModuleName(ctx, moduleName, componentName) {
510
- var _a, _b;
511
- let { dependencies = [], dependenciesMap = {} } = ctx;
512
- if (ctx.streamlineModuleName) {
513
- if (moduleName === ((_a = dependencies[0]) === null || _a === void 0 ? void 0 : _a.name)) {
514
- moduleName = undefined;
515
- }
516
- let find = undefined;
517
- for (let i = dependencies.length - 1; i > 0; i--) {
518
- let lib = dependencies[i];
519
- let currentModuleName = lib.name;
520
- let key = `${currentModuleName}:${componentName}`;
521
- if (!!dependenciesMap[key]) {
522
- find = lib;
523
- break;
524
- }
525
- }
526
- if (find) {
527
- if ((find === null || find === void 0 ? void 0 : find.name) === moduleName) {
528
- return undefined;
529
- }
530
- }
531
- else if (((_b = dependencies[0]) === null || _b === void 0 ? void 0 : _b.name) === moduleName) {
532
- return undefined;
533
- }
640
+ var _a, _b;
641
+ let { dependencies = [], dependenciesMap = {} } = ctx;
642
+ if (ctx.streamlineModuleName) {
643
+ if (moduleName === ((_a = dependencies[0]) === null || _a === void 0 ? void 0 : _a.name)) {
644
+ moduleName = undefined;
534
645
  }
535
- else if (moduleName &&
536
- !/-lcap-spinoff$/.test(moduleName) &&
537
- !dependenciesMap[`${moduleName}:${componentName}`] &&
538
- dependenciesMap[`${moduleName}-lcap-spinoff:${componentName}`]) {
539
- return `${moduleName}-lcap-spinoff`;
646
+ let find = undefined;
647
+ for (let i = dependencies.length - 1; i > 0; i--) {
648
+ let lib = dependencies[i];
649
+ let currentModuleName = lib.name;
650
+ let key = `${currentModuleName}:${componentName}`;
651
+ if (!!dependenciesMap[key]) {
652
+ find = lib;
653
+ break;
654
+ }
540
655
  }
541
- return moduleName;
656
+ if (find) {
657
+ if ((find === null || find === void 0 ? void 0 : find.name) === moduleName) {
658
+ return undefined;
659
+ }
660
+ } else if (((_b = dependencies[0]) === null || _b === void 0 ? void 0 : _b.name) === moduleName) {
661
+ return undefined;
662
+ }
663
+ } else if (
664
+ moduleName &&
665
+ !/-lcap-spinoff$/.test(moduleName) &&
666
+ !dependenciesMap[`${moduleName}:${componentName}`] &&
667
+ dependenciesMap[`${moduleName}-lcap-spinoff:${componentName}`]
668
+ ) {
669
+ return `${moduleName}-lcap-spinoff`;
670
+ }
671
+ return moduleName;
542
672
  }
543
673
  function deserializeModuleName(ctx, componentName, moduleName) {
544
- var _a;
545
- let { dependencies = [], dependenciesMap = {} } = ctx;
546
- let defaultModuleName = (_a = dependencies[0]) === null || _a === void 0 ? void 0 : _a.name;
547
- // 补充默认的 moduleName 按照依赖反序查找
548
- if (!moduleName) {
549
- let find = undefined;
550
- for (let i = dependencies.length - 1; i > 0; i--) {
551
- let lib = dependencies[i];
552
- let { name } = lib;
553
- let key = `${name}:${componentName}`;
554
- if (!!dependenciesMap[key]) {
555
- find = lib;
556
- break;
557
- }
558
- }
559
- return find ? find === null || find === void 0 ? void 0 : find.name : defaultModuleName;
674
+ var _a;
675
+ let { dependencies = [], dependenciesMap = {} } = ctx;
676
+ let defaultModuleName = (_a = dependencies[0]) === null || _a === void 0 ? void 0 : _a.name;
677
+ // 补充默认的 moduleName 按照依赖反序查找
678
+ if (!moduleName) {
679
+ let find = undefined;
680
+ for (let i = dependencies.length - 1; i > 0; i--) {
681
+ let lib = dependencies[i];
682
+ let { name } = lib;
683
+ let key = `${name}:${componentName}`;
684
+ if (!!dependenciesMap[key]) {
685
+ find = lib;
686
+ break;
687
+ }
560
688
  }
561
- else if (moduleName &&
562
- !/-lcap-spinoff$/.test(moduleName) &&
563
- !dependenciesMap[`${moduleName}:${componentName}`] &&
564
- dependenciesMap[`${moduleName}-lcap-spinoff:${componentName}`]) {
565
- return `${moduleName}-lcap-spinoff`;
566
- }
567
- return moduleName;
689
+ return find ? (find === null || find === void 0 ? void 0 : find.name) : defaultModuleName;
690
+ } else if (
691
+ moduleName &&
692
+ !/-lcap-spinoff$/.test(moduleName) &&
693
+ !dependenciesMap[`${moduleName}:${componentName}`] &&
694
+ dependenciesMap[`${moduleName}-lcap-spinoff:${componentName}`]
695
+ ) {
696
+ return `${moduleName}-lcap-spinoff`;
697
+ }
698
+ return moduleName;
568
699
  }
569
700
  function serializeComponent(ctx, component, scope = 'page') {
570
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
571
- // const scope = ctx.component?.id ? 'component' : 'page'
572
- const moduleName = (_a = component.xComponent) === null || _a === void 0 ? void 0 : _a.moduleName;
573
- const componentName = ((_b = component.xComponent) === null || _b === void 0 ? void 0 : _b.name) || '';
574
- const componentCtx = Object.assign(Object.assign({}, ctx), { component: {
575
- id: component.id,
576
- module: moduleName,
577
- component: (_c = component.xComponent) === null || _c === void 0 ? void 0 : _c.name,
578
- } });
579
- if (componentCtx.dependencies && !componentCtx.dependenciesMap) {
580
- componentCtx.dependenciesMap = processDependenciesMap(componentCtx.dependencies || []);
581
- }
582
- let attributeMeta = serializeAttributesWithExtra(componentCtx, scope, (((_d = component === null || component === void 0 ? void 0 : component.xProps) === null || _d === void 0 ? void 0 : _d.data) || {})) || {};
583
- const { data: attributes = {}, extra: attributeExtraData = {} } = attributeMeta;
584
- let classListBindData = null;
585
- let styleBindData = null;
586
- if ((_e = component === null || component === void 0 ? void 0 : component.xProps) === null || _e === void 0 ? void 0 : _e.classListBind) {
587
- classListBindData = serializeValue({
588
- ctx: componentCtx,
589
- key: 'classListBind',
590
- dynamicValue: (_f = component === null || component === void 0 ? void 0 : component.xProps) === null || _f === void 0 ? void 0 : _f.classListBind,
591
- scope,
592
- });
593
- if (classListBindData.extra) {
594
- attributeExtraData.class = classListBindData.extra;
595
- }
701
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
702
+ // const scope = ctx.component?.id ? 'component' : 'page'
703
+ const moduleName = (_a = component.xComponent) === null || _a === void 0 ? void 0 : _a.moduleName;
704
+ const componentName = ((_b = component.xComponent) === null || _b === void 0 ? void 0 : _b.name) || '';
705
+ const componentCtx = Object.assign(Object.assign({}, ctx), {
706
+ component: {
707
+ id: component.id,
708
+ module: moduleName,
709
+ component: (_c = component.xComponent) === null || _c === void 0 ? void 0 : _c.name,
710
+ },
711
+ });
712
+ if (componentCtx.dependencies && !componentCtx.dependenciesMap) {
713
+ componentCtx.dependenciesMap = processDependenciesMap(componentCtx.dependencies || []);
714
+ }
715
+ let attributeMeta =
716
+ serializeAttributesWithExtra(
717
+ componentCtx,
718
+ scope,
719
+ ((_d = component === null || component === void 0 ? void 0 : component.xProps) === null || _d === void 0
720
+ ? void 0
721
+ : _d.data) || {},
722
+ ) || {};
723
+ const { data: attributes = {}, extra: attributeExtraData = {} } = attributeMeta;
724
+ let classListBindData = null;
725
+ let styleBindData = null;
726
+ if (
727
+ (_e = component === null || component === void 0 ? void 0 : component.xProps) === null || _e === void 0
728
+ ? void 0
729
+ : _e.classListBind
730
+ ) {
731
+ classListBindData = serializeValue({
732
+ ctx: componentCtx,
733
+ key: 'classListBind',
734
+ dynamicValue:
735
+ (_f = component === null || component === void 0 ? void 0 : component.xProps) === null || _f === void 0
736
+ ? void 0
737
+ : _f.classListBind,
738
+ scope,
739
+ });
740
+ if (classListBindData.extra) {
741
+ attributeExtraData.class = classListBindData.extra;
596
742
  }
597
- if ((_g = component === null || component === void 0 ? void 0 : component.xProps) === null || _g === void 0 ? void 0 : _g.styleBind) {
598
- styleBindData = serializeValue({
599
- ctx: componentCtx,
600
- key: 'styleBind',
601
- dynamicValue: (_h = component === null || component === void 0 ? void 0 : component.xProps) === null || _h === void 0 ? void 0 : _h.styleBind,
602
- });
603
- if (styleBindData.extra) {
604
- attributeExtraData.style = styleBindData.extra;
605
- }
743
+ }
744
+ if (
745
+ (_g = component === null || component === void 0 ? void 0 : component.xProps) === null || _g === void 0
746
+ ? void 0
747
+ : _g.styleBind
748
+ ) {
749
+ styleBindData = serializeValue({
750
+ ctx: componentCtx,
751
+ key: 'styleBind',
752
+ dynamicValue:
753
+ (_h = component === null || component === void 0 ? void 0 : component.xProps) === null || _h === void 0
754
+ ? void 0
755
+ : _h.styleBind,
756
+ });
757
+ if (styleBindData.extra) {
758
+ attributeExtraData.style = styleBindData.extra;
606
759
  }
607
- return {
608
- id: component.id,
609
- label: (0, runtime_1.getValidValue)(component.label),
610
- type: undefined,
611
- module: serializeModuleName(componentCtx, moduleName, componentName),
612
- component: componentName,
613
- attributes: (0, runtime_1.getValidValue)(component.xProps
614
- ? Object.assign(Object.assign({}, attributes), { style: (_j = component.xProps) === null || _j === void 0 ? void 0 : _j.style, class: (_l = (_k = component.xProps) === null || _k === void 0 ? void 0 : _k.classList) === null || _l === void 0 ? void 0 : _l.join(' ') }) : undefined),
615
- items: component.properties
616
- ? Object.keys(component.properties).map((key) => {
617
- var _a;
618
- return serializeComponent(componentCtx, Object.assign({ id: key }, (_a = component.properties) === null || _a === void 0 ? void 0 : _a[key]), scope);
619
- })
620
- : undefined,
621
- listeners: (0, runtime_1.getValidValue)((_o = (_m = component.xProps) === null || _m === void 0 ? void 0 : _m.listeners) === null || _o === void 0 ? void 0 : _o.map((listener) => {
760
+ }
761
+ return {
762
+ id: component.id,
763
+ label: (0, runtime_1.getValidValue)(component.label),
764
+ type: undefined,
765
+ module: serializeModuleName(componentCtx, moduleName, componentName),
766
+ component: componentName,
767
+ attributes: (0, runtime_1.getValidValue)(
768
+ component.xProps
769
+ ? Object.assign(Object.assign({}, attributes), {
770
+ style: (_j = component.xProps) === null || _j === void 0 ? void 0 : _j.style,
771
+ class:
772
+ (_l = (_k = component.xProps) === null || _k === void 0 ? void 0 : _k.classList) === null || _l === void 0
773
+ ? void 0
774
+ : _l.join(' '),
775
+ })
776
+ : undefined,
777
+ ),
778
+ items: component.properties
779
+ ? Object.keys(component.properties).map((key) => {
780
+ var _a;
781
+ return serializeComponent(
782
+ componentCtx,
783
+ Object.assign({ id: key }, (_a = component.properties) === null || _a === void 0 ? void 0 : _a[key]),
784
+ scope,
785
+ );
786
+ })
787
+ : undefined,
788
+ listeners: (0, runtime_1.getValidValue)(
789
+ (_o = (_m = component.xProps) === null || _m === void 0 ? void 0 : _m.listeners) === null || _o === void 0
790
+ ? void 0
791
+ : _o.map((listener) => {
622
792
  return serializeListener(componentCtx, listener);
623
- })),
624
- directives: serializeDirecties(componentCtx, (((_p = component.xProps) === null || _p === void 0 ? void 0 : _p.directives) || {}), scope) || {
625
- ':if': true,
626
- },
627
- ':class': classListBindData ? classListBindData.value : undefined,
628
- ':style': styleBindData ? styleBindData.value : undefined,
629
- extra: {
630
- commonStyle: (_q = component.xProps) === null || _q === void 0 ? void 0 : _q.commonStyle,
631
- xIndex: component.xIndex,
632
- styleBindPath: (_r = component === null || component === void 0 ? void 0 : component.xProps) === null || _r === void 0 ? void 0 : _r.styleBindPath,
633
- staticResourceAttribute: (_s = component === null || component === void 0 ? void 0 : component.xProps) === null || _s === void 0 ? void 0 : _s.staticResourceAttribute,
634
- attributeExtraData: (0, common_2.isEmptyObj)(attributeExtraData) ? undefined : attributeExtraData,
635
- },
636
- };
793
+ }),
794
+ ),
795
+ directives: serializeDirecties(
796
+ componentCtx,
797
+ ((_p = component.xProps) === null || _p === void 0 ? void 0 : _p.directives) || {},
798
+ scope,
799
+ ) || {
800
+ ':if': true,
801
+ },
802
+ ':class': classListBindData ? classListBindData.value : undefined,
803
+ ':style': styleBindData ? styleBindData.value : undefined,
804
+ extra: {
805
+ commonStyle: (_q = component.xProps) === null || _q === void 0 ? void 0 : _q.commonStyle,
806
+ xIndex: component.xIndex,
807
+ styleBindPath:
808
+ (_r = component === null || component === void 0 ? void 0 : component.xProps) === null || _r === void 0
809
+ ? void 0
810
+ : _r.styleBindPath,
811
+ staticResourceAttribute:
812
+ (_s = component === null || component === void 0 ? void 0 : component.xProps) === null || _s === void 0
813
+ ? void 0
814
+ : _s.staticResourceAttribute,
815
+ attributeExtraData: (0, common_2.isEmptyObj)(attributeExtraData) ? undefined : attributeExtraData,
816
+ },
817
+ };
637
818
  }
638
819
  exports.serializeComponent = serializeComponent;
639
820
  function deserializeComponent(ctx, components) {
640
- let componentMap = components.reduce((map, item) => {
641
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
642
- const { attributeExtraData = {} } = item.extra || {};
643
- let dynamicStyle = item[':style']
644
- ? deserializeValue(ctx, ':style', item[':style'], attributeExtraData.style).value
645
- : undefined;
646
- let dynamicClassList = item[':class']
647
- ? deserializeValue(ctx, ':class', item[':class'], attributeExtraData.class).value
648
- : undefined;
649
- const xComponent = {
650
- moduleName: item.module,
651
- name: item.component || undefined,
652
- };
653
- if (xComponent.name) {
654
- xComponent.moduleName =
655
- deserializeModuleName(ctx, xComponent.name, xComponent.moduleName) || xComponent.moduleName;
656
- }
657
- const xProps = {
658
- data: deserializeAttributes(ctx, item.attributes, attributeExtraData),
659
- directives: deserializeDirecties(ctx, item.directives || {}),
660
- style: (_a = item.attributes) === null || _a === void 0 ? void 0 : _a.style,
661
- styleBind: dynamicStyle
662
- ? {
663
- type: dynamicStyle.type,
664
- value: dynamicStyle.value,
665
- }
666
- : undefined,
667
- commonStyle: (_b = item === null || item === void 0 ? void 0 : item.extra) === null || _b === void 0 ? void 0 : _b.commonStyle,
668
- staticResourceAttribute: (_c = item === null || item === void 0 ? void 0 : item.extra) === null || _c === void 0 ? void 0 : _c.staticResourceAttribute,
669
- classList: (_f = (_e = (_d = item.attributes) === null || _d === void 0 ? void 0 : _d.class) === null || _e === void 0 ? void 0 : _e.split(/\s/g)) === null || _f === void 0 ? void 0 : _f.filter((className) => !!className),
670
- classListBind: item[':class']
671
- ? {
672
- value: dynamicClassList === null || dynamicClassList === void 0 ? void 0 : dynamicClassList.value,
673
- type: dynamicClassList === null || dynamicClassList === void 0 ? void 0 : dynamicClassList.type,
674
- }
675
- : undefined,
676
- listeners: ((_g = item === null || item === void 0 ? void 0 : item.listeners) === null || _g === void 0 ? void 0 : _g.map((item) => {
677
- return deserializeListener(ctx, item);
821
+ let componentMap = components.reduce((map, item) => {
822
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
823
+ const { attributeExtraData = {} } = item.extra || {};
824
+ let dynamicStyle = item[':style']
825
+ ? deserializeValue(ctx, ':style', item[':style'], attributeExtraData.style).value
826
+ : undefined;
827
+ let dynamicClassList = item[':class']
828
+ ? deserializeValue(ctx, ':class', item[':class'], attributeExtraData.class).value
829
+ : undefined;
830
+ const xComponent = {
831
+ moduleName: item.module,
832
+ name: item.component || undefined,
833
+ };
834
+ if (xComponent.name) {
835
+ xComponent.moduleName =
836
+ deserializeModuleName(ctx, xComponent.name, xComponent.moduleName) || xComponent.moduleName;
837
+ }
838
+ const xProps = {
839
+ data: deserializeAttributes(ctx, item.attributes, attributeExtraData),
840
+ directives: deserializeDirecties(ctx, item.directives || {}),
841
+ style: (_a = item.attributes) === null || _a === void 0 ? void 0 : _a.style,
842
+ styleBind: dynamicStyle
843
+ ? {
844
+ type: dynamicStyle.type,
845
+ value: dynamicStyle.value,
846
+ }
847
+ : undefined,
848
+ commonStyle:
849
+ (_b = item === null || item === void 0 ? void 0 : item.extra) === null || _b === void 0
850
+ ? void 0
851
+ : _b.commonStyle,
852
+ staticResourceAttribute:
853
+ (_c = item === null || item === void 0 ? void 0 : item.extra) === null || _c === void 0
854
+ ? void 0
855
+ : _c.staticResourceAttribute,
856
+ classList:
857
+ (_f =
858
+ (_e = (_d = item.attributes) === null || _d === void 0 ? void 0 : _d.class) === null || _e === void 0
859
+ ? void 0
860
+ : _e.split(/\s/g)) === null || _f === void 0
861
+ ? void 0
862
+ : _f.filter((className) => !!className),
863
+ classListBind: item[':class']
864
+ ? {
865
+ value: dynamicClassList === null || dynamicClassList === void 0 ? void 0 : dynamicClassList.value,
866
+ type: dynamicClassList === null || dynamicClassList === void 0 ? void 0 : dynamicClassList.type,
867
+ }
868
+ : undefined,
869
+ listeners:
870
+ ((_g = item === null || item === void 0 ? void 0 : item.listeners) === null || _g === void 0
871
+ ? void 0
872
+ : _g.map((item) => {
873
+ return deserializeListener(ctx, item);
678
874
  })) || [],
679
- };
680
- let processed = {
681
- xComponent: Object.values(xComponent).find((item) => item != undefined) ? xComponent : undefined,
682
- xProps: Object.values(xProps).find((item) => {
683
- if (Array.isArray(item)) {
684
- return !!item.length;
685
- }
686
- return item != undefined && !(0, common_2.isEmptyObj)(item);
687
- })
688
- ? xProps
689
- : undefined,
690
- /**
691
- * TODO
692
- */
693
- xIndex: ((_h = item.extra) === null || _h === void 0 ? void 0 : _h.xIndex) !== undefined ? (_j = item.extra) === null || _j === void 0 ? void 0 : _j.xIndex : undefined /* 0*/,
694
- label: (item === null || item === void 0 ? void 0 : item.label) !== undefined ? item === null || item === void 0 ? void 0 : item.label : undefined /* 0*/,
695
- properties: item.items ? deserializeComponent(ctx, item.items) : undefined,
696
- };
697
- map[item.id] = processed;
698
- return map;
699
- }, {});
700
- return componentMap;
875
+ };
876
+ let processed = {
877
+ xComponent: Object.values(xComponent).find((item) => item != undefined) ? xComponent : undefined,
878
+ xProps: Object.values(xProps).find((item) => {
879
+ if (Array.isArray(item)) {
880
+ return !!item.length;
881
+ }
882
+ return item != undefined && !(0, common_2.isEmptyObj)(item);
883
+ })
884
+ ? xProps
885
+ : undefined,
886
+ /**
887
+ * TODO
888
+ */
889
+ xIndex:
890
+ ((_h = item.extra) === null || _h === void 0 ? void 0 : _h.xIndex) !== undefined
891
+ ? (_j = item.extra) === null || _j === void 0
892
+ ? void 0
893
+ : _j.xIndex
894
+ : undefined /* 0*/,
895
+ label:
896
+ (item === null || item === void 0 ? void 0 : item.label) !== undefined
897
+ ? item === null || item === void 0
898
+ ? void 0
899
+ : item.label
900
+ : undefined /* 0*/,
901
+ properties: item.items ? deserializeComponent(ctx, item.items) : undefined,
902
+ };
903
+ map[item.id] = processed;
904
+ return map;
905
+ }, {});
906
+ return componentMap;
701
907
  }
702
908
  exports.deserializeComponent = deserializeComponent;
703
909
  function serializePage(ctx, page) {
704
- var _a, _b, _c, _d, _e;
705
- const pageCtx = Object.assign(Object.assign({}, ctx), { page });
706
- if (pageCtx.dependencies && !pageCtx.dependenciesMap) {
707
- pageCtx.dependenciesMap = processDependenciesMap(pageCtx.dependencies || []);
708
- }
709
- let processedPage = {
710
- id: page.id,
711
- type: 'PAGE',
712
- component: 'Page',
713
- attributes: (0, runtime_1.getValidValue)((_a = serializeAttributesWithExtra(pageCtx, 'page', page.data)) === null || _a === void 0 ? void 0 : _a.data),
714
- items: Object.keys(page.componentInstances || {}).map((id) => {
715
- return serializeComponent(pageCtx, Object.assign({ id }, page.componentInstances[id]));
716
- }),
717
- directives: {
718
- ':if': true,
719
- },
720
- resources: (_b = page === null || page === void 0 ? void 0 : page.lowCodes) === null || _b === void 0 ? void 0 : _b.map((item) => serializeCodeSource(pageCtx, item)),
721
- dataset: serializeDataset(ctx, page === null || page === void 0 ? void 0 : page.dataset),
722
- dataVariables: (0, runtime_1.getValidValue)((_d = (_c = page === null || page === void 0 ? void 0 : page.vars) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.map((item) => serializeDataVariables(pageCtx, item))),
723
- listeners: (0, runtime_1.getValidValue)((_e = page === null || page === void 0 ? void 0 : page.listeners) === null || _e === void 0 ? void 0 : _e.map((item) => {
910
+ var _a, _b, _c, _d, _e;
911
+ const pageCtx = Object.assign(Object.assign({}, ctx), { page });
912
+ if (pageCtx.dependencies && !pageCtx.dependenciesMap) {
913
+ pageCtx.dependenciesMap = processDependenciesMap(pageCtx.dependencies || []);
914
+ }
915
+ let processedPage = {
916
+ id: page.id,
917
+ type: 'PAGE',
918
+ component: 'Page',
919
+ attributes: (0, runtime_1.getValidValue)(
920
+ (_a = serializeAttributesWithExtra(pageCtx, 'page', page.data)) === null || _a === void 0 ? void 0 : _a.data,
921
+ ),
922
+ items: Object.keys(page.componentInstances || {}).map((id) => {
923
+ return serializeComponent(pageCtx, Object.assign({ id }, page.componentInstances[id]));
924
+ }),
925
+ directives: {
926
+ ':if': true,
927
+ },
928
+ resources:
929
+ (_b = page === null || page === void 0 ? void 0 : page.lowCodes) === null || _b === void 0
930
+ ? void 0
931
+ : _b.map((item) => serializeCodeSource(pageCtx, item)),
932
+ dataset: serializeDataset(ctx, page === null || page === void 0 ? void 0 : page.dataset),
933
+ dataVariables: (0, runtime_1.getValidValue)(
934
+ (_d =
935
+ (_c = page === null || page === void 0 ? void 0 : page.vars) === null || _c === void 0 ? void 0 : _c.data) ===
936
+ null || _d === void 0
937
+ ? void 0
938
+ : _d.map((item) => serializeDataVariables(pageCtx, item)),
939
+ ),
940
+ listeners: (0, runtime_1.getValidValue)(
941
+ (_e = page === null || page === void 0 ? void 0 : page.listeners) === null || _e === void 0
942
+ ? void 0
943
+ : _e.map((item) => {
724
944
  return serializeListener(pageCtx, item);
725
- })),
726
- extra: {
727
- commonStyle: page === null || page === void 0 ? void 0 : page.commonStyle,
728
- xIndex: page.xIndex,
729
- staticResourceAttribute: page === null || page === void 0 ? void 0 : page.staticResourceAttribute,
730
- hideAdminPortalMenu: page === null || page === void 0 ? void 0 : page.hideAdminPortalMenu,
731
- },
732
- };
733
- if (page.styleBind) {
734
- page[':style'] = serializeValue({
735
- ctx: pageCtx,
736
- key: 'styleBind',
737
- dynamicValue: page.styleBind,
738
- }).value;
739
- }
740
- if (page.classListBind) {
741
- page[':class'] = serializeValue({
742
- ctx: pageCtx,
743
- key: 'classListBind',
744
- dynamicValue: page.classListBind,
745
- });
746
- }
747
- return processedPage;
945
+ }),
946
+ ),
947
+ extra: {
948
+ commonStyle: page === null || page === void 0 ? void 0 : page.commonStyle,
949
+ xIndex: page.xIndex,
950
+ staticResourceAttribute: page === null || page === void 0 ? void 0 : page.staticResourceAttribute,
951
+ hideAdminPortalMenu: page === null || page === void 0 ? void 0 : page.hideAdminPortalMenu,
952
+ },
953
+ };
954
+ if (page.styleBind) {
955
+ page[':style'] = serializeValue({
956
+ ctx: pageCtx,
957
+ key: 'styleBind',
958
+ dynamicValue: page.styleBind,
959
+ }).value;
960
+ }
961
+ if (page.classListBind) {
962
+ page[':class'] = serializeValue({
963
+ ctx: pageCtx,
964
+ key: 'classListBind',
965
+ dynamicValue: page.classListBind,
966
+ });
967
+ }
968
+ return processedPage;
748
969
  }
749
970
  exports.serializePage = serializePage;
750
971
  function deserializePage(ctx, page) {
751
- var _a, _b, _c, _d, _e, _f, _g;
752
- let pageCtx = Object.assign(Object.assign({}, ctx), { page });
753
- return {
754
- id: page.id,
755
- isHome: page.id === ctx.homePageId,
756
- dataset: deserializeDataset(ctx, page.dataset),
757
- vars: {
758
- data: ((_a = page.dataVariables) === null || _a === void 0 ? void 0 : _a.map((item) => {
759
- return deserializeDataVariables(pageCtx, item);
972
+ var _a, _b, _c, _d, _e, _f, _g;
973
+ let pageCtx = Object.assign(Object.assign({}, ctx), { page });
974
+ return {
975
+ id: page.id,
976
+ isHome: page.id === ctx.homePageId,
977
+ dataset: deserializeDataset(ctx, page.dataset),
978
+ vars: {
979
+ data:
980
+ ((_a = page.dataVariables) === null || _a === void 0
981
+ ? void 0
982
+ : _a.map((item) => {
983
+ return deserializeDataVariables(pageCtx, item);
760
984
  })) || [],
761
- },
762
- data: deserializeAttributes(pageCtx, page.attributes, (_b = page === null || page === void 0 ? void 0 : page.extra) === null || _b === void 0 ? void 0 : _b.attributeExtraData),
763
- componentInstances: deserializeComponent(pageCtx, page.items || []),
764
- commonStyle: (_c = page === null || page === void 0 ? void 0 : page.extra) === null || _c === void 0 ? void 0 : _c.commonStyle,
765
- staticResourceAttribute: (_d = page === null || page === void 0 ? void 0 : page.extra) === null || _d === void 0 ? void 0 : _d.staticResourceAttribute,
766
- hideAdminPortalMenu: (_e = page === null || page === void 0 ? void 0 : page.extra) === null || _e === void 0 ? void 0 : _e.hideAdminPortalMenu,
767
- lowCodes: (_f = page === null || page === void 0 ? void 0 : page.resources) === null || _f === void 0 ? void 0 : _f.filter((item) => item.type === common_1.EResourceType.CODE).map((item) => deserializeCodeResource(pageCtx, item)),
768
- listeners: ((_g = page === null || page === void 0 ? void 0 : page.listeners) === null || _g === void 0 ? void 0 : _g.map((item) => {
985
+ },
986
+ data: deserializeAttributes(
987
+ pageCtx,
988
+ page.attributes,
989
+ (_b = page === null || page === void 0 ? void 0 : page.extra) === null || _b === void 0
990
+ ? void 0
991
+ : _b.attributeExtraData,
992
+ ),
993
+ componentInstances: deserializeComponent(pageCtx, page.items || []),
994
+ commonStyle:
995
+ (_c = page === null || page === void 0 ? void 0 : page.extra) === null || _c === void 0 ? void 0 : _c.commonStyle,
996
+ staticResourceAttribute:
997
+ (_d = page === null || page === void 0 ? void 0 : page.extra) === null || _d === void 0
998
+ ? void 0
999
+ : _d.staticResourceAttribute,
1000
+ hideAdminPortalMenu:
1001
+ (_e = page === null || page === void 0 ? void 0 : page.extra) === null || _e === void 0
1002
+ ? void 0
1003
+ : _e.hideAdminPortalMenu,
1004
+ lowCodes:
1005
+ (_f = page === null || page === void 0 ? void 0 : page.resources) === null || _f === void 0
1006
+ ? void 0
1007
+ : _f
1008
+ .filter((item) => item.type === common_1.EResourceType.CODE)
1009
+ .map((item) => deserializeCodeResource(pageCtx, item)),
1010
+ listeners:
1011
+ ((_g = page === null || page === void 0 ? void 0 : page.listeners) === null || _g === void 0
1012
+ ? void 0
1013
+ : _g.map((item) => {
769
1014
  return deserializeListener(pageCtx, item);
770
- })) || [],
771
- // TODO
772
- // children: [],
773
- // styleBindPath: item.styleBindPath,
774
- };
1015
+ })) || [],
1016
+ // TODO
1017
+ // children: [],
1018
+ // styleBindPath: item.styleBindPath,
1019
+ };
775
1020
  }
776
1021
  exports.deserializePage = deserializePage;
777
1022
  /**
@@ -780,34 +1025,96 @@ exports.deserializePage = deserializePage;
780
1025
  * @param data
781
1026
  */
782
1027
  function serializePlatformApp(data, optsions) {
783
- var _a;
784
- let { version, author, name, label, description, selectedPageId, pageInstanceList, lowCodes = [], datasources, vars, dataset, extra, dependencies: calsDependencies, miniprogramPlugins, lastDependencies, externalResources, schemaVersion } = data, restData = __rest(data, ["version", "author", "name", "label", "description", "selectedPageId", "pageInstanceList", "lowCodes", "datasources", "vars", "dataset", "extra", "dependencies", "miniprogramPlugins", "lastDependencies", "externalResources", "schemaVersion"]);
785
- let { dependencies = [] } = optsions || {};
786
- const _b = extra || {}, { name: extraName, label: extraLabel, author: extraAuthor, description: extraDescription } = _b, restExtra = __rest(_b, ["name", "label", "author", "description"]);
787
- const ctx = {
788
- app: data,
789
- dependencies,
790
- dependenciesMap: processDependenciesMap(dependencies),
791
- };
792
- const homePage = pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList.find((page) => page.isHome);
793
- let processed = {
794
- label: label || extraLabel,
795
- name: name || extraName,
796
- author: author || extraAuthor,
797
- version,
798
- schemaVersion,
799
- description: description || extraDescription,
800
- externalResources,
801
- main: homePage ? homePage.id : ((_a = pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList[0]) === null || _a === void 0 ? void 0 : _a.id) || selectedPageId,
802
- items: pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList.map((page) => serializePage(ctx, page)),
803
- resources: lowCodes === null || lowCodes === void 0 ? void 0 : lowCodes.map((item) => serializeCodeSource(ctx, item)),
804
- dataSources: datasources,
805
- dataset: serializeDataset(ctx, dataset),
806
- dataVariables: (0, runtime_1.getValidValue)(vars === null || vars === void 0 ? void 0 : vars.data.map((item) => serializeDataVariables(ctx, item))),
807
- dependencies: calsDependencies,
808
- extra: Object.assign(Object.assign(Object.assign({}, restExtra), restData), { miniprogramPlugins, historyType: data.historyType, npmDependencies: data.npmDependencies || {}, plugins: data.plugins, maxID: data.maxID, rootPath: data.rootPath, themeVars: data.themeVars, presetColors: data.presetColors, appConfig: data.appConfig, lastDependencies }),
809
- };
810
- return processed;
1028
+ var _a;
1029
+ let {
1030
+ version,
1031
+ author,
1032
+ name,
1033
+ label,
1034
+ description,
1035
+ selectedPageId,
1036
+ pageInstanceList,
1037
+ lowCodes = [],
1038
+ datasources,
1039
+ vars,
1040
+ dataset,
1041
+ extra,
1042
+ dependencies: calsDependencies,
1043
+ miniprogramPlugins,
1044
+ lastDependencies,
1045
+ externalResources,
1046
+ schemaVersion,
1047
+ } = data,
1048
+ restData = __rest(data, [
1049
+ 'version',
1050
+ 'author',
1051
+ 'name',
1052
+ 'label',
1053
+ 'description',
1054
+ 'selectedPageId',
1055
+ 'pageInstanceList',
1056
+ 'lowCodes',
1057
+ 'datasources',
1058
+ 'vars',
1059
+ 'dataset',
1060
+ 'extra',
1061
+ 'dependencies',
1062
+ 'miniprogramPlugins',
1063
+ 'lastDependencies',
1064
+ 'externalResources',
1065
+ 'schemaVersion',
1066
+ ]);
1067
+ let { dependencies = [] } = optsions || {};
1068
+ const _b = extra || {},
1069
+ { name: extraName, label: extraLabel, author: extraAuthor, description: extraDescription } = _b,
1070
+ restExtra = __rest(_b, ['name', 'label', 'author', 'description']);
1071
+ const ctx = {
1072
+ app: data,
1073
+ dependencies,
1074
+ dependenciesMap: processDependenciesMap(dependencies),
1075
+ };
1076
+ const homePage =
1077
+ pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList.find((page) => page.isHome);
1078
+ let processed = {
1079
+ label: label || extraLabel,
1080
+ name: name || extraName,
1081
+ author: author || extraAuthor,
1082
+ version,
1083
+ schemaVersion,
1084
+ description: description || extraDescription,
1085
+ externalResources,
1086
+ main: homePage
1087
+ ? homePage.id
1088
+ : ((_a = pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList[0]) === null ||
1089
+ _a === void 0
1090
+ ? void 0
1091
+ : _a.id) || selectedPageId,
1092
+ items:
1093
+ pageInstanceList === null || pageInstanceList === void 0
1094
+ ? void 0
1095
+ : pageInstanceList.map((page) => serializePage(ctx, page)),
1096
+ resources:
1097
+ lowCodes === null || lowCodes === void 0 ? void 0 : lowCodes.map((item) => serializeCodeSource(ctx, item)),
1098
+ dataSources: datasources,
1099
+ dataset: serializeDataset(ctx, dataset),
1100
+ dataVariables: (0, runtime_1.getValidValue)(
1101
+ vars === null || vars === void 0 ? void 0 : vars.data.map((item) => serializeDataVariables(ctx, item)),
1102
+ ),
1103
+ dependencies: calsDependencies,
1104
+ extra: Object.assign(Object.assign(Object.assign({}, restExtra), restData), {
1105
+ miniprogramPlugins,
1106
+ historyType: data.historyType,
1107
+ npmDependencies: data.npmDependencies || {},
1108
+ plugins: data.plugins,
1109
+ maxID: data.maxID,
1110
+ rootPath: data.rootPath,
1111
+ themeVars: data.themeVars,
1112
+ presetColors: data.presetColors,
1113
+ appConfig: data.appConfig,
1114
+ lastDependencies,
1115
+ }),
1116
+ };
1117
+ return processed;
811
1118
  }
812
1119
  exports.serializePlatformApp = serializePlatformApp;
813
1120
  /**
@@ -816,54 +1123,89 @@ exports.serializePlatformApp = serializePlatformApp;
816
1123
  * @param data
817
1124
  */
818
1125
  function deserializePlatformApp(data, optsions) {
819
- var _a, _b;
820
- let homePageId = data.main || ((_a = data.items[0]) === null || _a === void 0 ? void 0 : _a.id) || '';
821
- let extra = data.extra || {};
822
- const { historyType, npmDependencies, plugins, maxID, rootPath, themeVars, presetColors, appConfig, miniprogramPlugins, compHiddenConfig, lastDependencies } = extra, restExtra = __rest(extra, ["historyType", "npmDependencies", "plugins", "maxID", "rootPath", "themeVars", "presetColors", "appConfig", "miniprogramPlugins", "compHiddenConfig", "lastDependencies"]);
823
- const ctx = {
824
- app: data,
825
- dependencies: (optsions === null || optsions === void 0 ? void 0 : optsions.dependencies) || [],
826
- homePageId,
827
- dependenciesMap: processDependenciesMap(((optsions === null || optsions === void 0 ? void 0 : optsions.dependencies) || [])),
828
- };
829
- let processed = {
830
- id: data.id,
831
- version: data.version,
832
- author: data.author,
833
- name: data.name,
834
- label: data.label,
835
- description: data.description,
836
- selectedPageId: homePageId,
837
- historyType,
838
- pageInstanceList: (data.items || []).map((page) => deserializePage(ctx, page)),
839
- // lowCodes: data.resources || [],
840
- lowCodes: (data.resources || [])
841
- .filter((item) => item.type === common_1.EResourceType.CODE)
842
- .map((item) => deserializeCodeResource(ctx, item)),
843
- datasources: data.dataSources,
844
- dataset: deserializeDataset(ctx, data.dataset),
845
- vars: {
846
- data: ((_b = data.dataVariables) === null || _b === void 0 ? void 0 : _b.map((item) => {
847
- return deserializeDataVariables(ctx, item);
1126
+ var _a, _b;
1127
+ let homePageId = data.main || ((_a = data.items[0]) === null || _a === void 0 ? void 0 : _a.id) || '';
1128
+ let extra = data.extra || {};
1129
+ const {
1130
+ historyType,
1131
+ npmDependencies,
1132
+ plugins,
1133
+ maxID,
1134
+ rootPath,
1135
+ themeVars,
1136
+ presetColors,
1137
+ appConfig,
1138
+ miniprogramPlugins,
1139
+ compHiddenConfig,
1140
+ lastDependencies,
1141
+ } = extra,
1142
+ restExtra = __rest(extra, [
1143
+ 'historyType',
1144
+ 'npmDependencies',
1145
+ 'plugins',
1146
+ 'maxID',
1147
+ 'rootPath',
1148
+ 'themeVars',
1149
+ 'presetColors',
1150
+ 'appConfig',
1151
+ 'miniprogramPlugins',
1152
+ 'compHiddenConfig',
1153
+ 'lastDependencies',
1154
+ ]);
1155
+ const ctx = {
1156
+ app: data,
1157
+ dependencies: (optsions === null || optsions === void 0 ? void 0 : optsions.dependencies) || [],
1158
+ homePageId,
1159
+ dependenciesMap: processDependenciesMap(
1160
+ (optsions === null || optsions === void 0 ? void 0 : optsions.dependencies) || [],
1161
+ ),
1162
+ };
1163
+ let processed = {
1164
+ id: data.id,
1165
+ version: data.version,
1166
+ author: data.author,
1167
+ name: data.name,
1168
+ label: data.label,
1169
+ description: data.description,
1170
+ selectedPageId: homePageId,
1171
+ historyType,
1172
+ pageInstanceList: (data.items || []).map((page) => deserializePage(ctx, page)),
1173
+ // lowCodes: data.resources || [],
1174
+ lowCodes: (data.resources || [])
1175
+ .filter((item) => item.type === common_1.EResourceType.CODE)
1176
+ .map((item) => deserializeCodeResource(ctx, item)),
1177
+ datasources: data.dataSources,
1178
+ dataset: deserializeDataset(ctx, data.dataset),
1179
+ vars: {
1180
+ data:
1181
+ ((_b = data.dataVariables) === null || _b === void 0
1182
+ ? void 0
1183
+ : _b.map((item) => {
1184
+ return deserializeDataVariables(ctx, item);
848
1185
  })) || [],
849
- },
850
- compHiddenConfig: compHiddenConfig || {},
851
- npmDependencies: npmDependencies || {},
852
- plugins: plugins || [],
853
- maxID,
854
- rootPath,
855
- themeVars,
856
- presetColors: presetColors || [],
857
- appConfig,
858
- miniprogramPlugins,
859
- externalResources: data.externalResources,
860
- extra: Object.assign(Object.assign({}, restExtra), { name: data.name, author: data.author, description: data.description, lastDependencies }),
861
- dependencies: data.dependencies,
862
- // TODO
863
- // emitEvents: [], { "name": "自定义校验规则", "eventName": "validator" }
864
- schemaVersion: data.schemaVersion,
865
- };
866
- return processed;
1186
+ },
1187
+ compHiddenConfig: compHiddenConfig || {},
1188
+ npmDependencies: npmDependencies || {},
1189
+ plugins: plugins || [],
1190
+ maxID,
1191
+ rootPath,
1192
+ themeVars,
1193
+ presetColors: presetColors || [],
1194
+ appConfig,
1195
+ miniprogramPlugins,
1196
+ externalResources: data.externalResources,
1197
+ extra: Object.assign(Object.assign({}, restExtra), {
1198
+ name: data.name,
1199
+ author: data.author,
1200
+ description: data.description,
1201
+ lastDependencies,
1202
+ }),
1203
+ dependencies: data.dependencies,
1204
+ // TODO
1205
+ // emitEvents: [], { "name": "自定义校验规则", "eventName": "validator" }
1206
+ schemaVersion: data.schemaVersion,
1207
+ };
1208
+ return processed;
867
1209
  }
868
1210
  exports.deserializePlatformApp = deserializePlatformApp;
869
1211
  /**
@@ -871,45 +1213,75 @@ exports.deserializePlatformApp = deserializePlatformApp;
871
1213
  * [formily] to [CALS]
872
1214
  */
873
1215
  function serializeRuntimePage(ctx, page) {
874
- var _a, _b, _c, _d, _e, _f;
875
- const pageCtx = Object.assign(Object.assign({}, ctx), { dependenciesMap: processDependenciesMap(ctx.dependencies || []), page: { id: page.id } });
876
- let processedPage = {
877
- id: page.id,
878
- type: 'PAGE',
879
- component: 'Page',
880
- attributes: (_a = serializeAttributesWithExtra(pageCtx, 'page', (0, runtime_1.readDynamicData)(page))) === null || _a === void 0 ? void 0 : _a.data,
881
- items: (0, runtime_1.getValidValue)(Object.keys(((_b = page.componentSchemaJson) === null || _b === void 0 ? void 0 : _b.properties) || {}).map((id) => {
882
- var _a;
883
- return serializeRuntimeComponent(pageCtx, Object.assign({ id }, (_a = page.componentSchemaJson) === null || _a === void 0 ? void 0 : _a.properties[id]));
884
- })),
885
- resources: (_c = page === null || page === void 0 ? void 0 : page.codeModules) === null || _c === void 0 ? void 0 : _c.map((item) => serializeCodeSource(pageCtx, item)),
886
- dataset: page === null || page === void 0 ? void 0 : page.dataset,
887
- dataVariables: (0, runtime_1.getValidValue)((_e = (_d = page === null || page === void 0 ? void 0 : page.vars) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.map((item) => serializeDataVariables(pageCtx, item))),
888
- listeners: (0, runtime_1.getValidValue)((0, runtime_1.readListeners)(page.listenerInstances || []).map((item) => {
889
- return serializeListener(pageCtx, item);
890
- })),
891
- extra: {
892
- commonStyle: (0, runtime_1.getValidValue)((0, style_1.removeInvalidStyleFormValue)(page.style)),
893
- styleBindPath: (0, runtime_1.getValidValue)(page.styleBindPath),
894
- xIndex: page.xIndex,
895
- children: (0, runtime_1.getValidValue)((_f = page.children) === null || _f === void 0 ? void 0 : _f.map((child) => serializeRuntimePage(ctx, child))),
1216
+ var _a, _b, _c, _d, _e, _f;
1217
+ const pageCtx = Object.assign(Object.assign({}, ctx), {
1218
+ dependenciesMap: processDependenciesMap(ctx.dependencies || []),
1219
+ page: { id: page.id },
1220
+ });
1221
+ let processedPage = {
1222
+ id: page.id,
1223
+ type: 'PAGE',
1224
+ component: 'Page',
1225
+ attributes:
1226
+ (_a = serializeAttributesWithExtra(pageCtx, 'page', (0, runtime_1.readDynamicData)(page))) === null ||
1227
+ _a === void 0
1228
+ ? void 0
1229
+ : _a.data,
1230
+ items: (0, runtime_1.getValidValue)(
1231
+ Object.keys(((_b = page.componentSchemaJson) === null || _b === void 0 ? void 0 : _b.properties) || {}).map(
1232
+ (id) => {
1233
+ var _a;
1234
+ return serializeRuntimeComponent(
1235
+ pageCtx,
1236
+ Object.assign(
1237
+ { id },
1238
+ (_a = page.componentSchemaJson) === null || _a === void 0 ? void 0 : _a.properties[id],
1239
+ ),
1240
+ );
896
1241
  },
897
- };
898
- if ((0, common_2.isValidStyleBind)(page.styleBind) && (0, runtime_1.getValidValue)(page.styleBind)) {
899
- page[':style'] = serializeValue({
900
- ctx: pageCtx,
901
- key: 'styleBind',
902
- dynamicValue: page.styleBind,
903
- }).value;
904
- }
905
- if ((0, common_2.isValidClassNameListBind)(page.classListBind) && (0, runtime_1.getValidValue)(page.classListBind)) {
906
- page[':class'] = serializeValue({
907
- ctx: pageCtx,
908
- key: 'classListBind',
909
- dynamicValue: page.classListBind,
910
- });
911
- }
912
- return processedPage;
1242
+ ),
1243
+ ),
1244
+ resources:
1245
+ (_c = page === null || page === void 0 ? void 0 : page.codeModules) === null || _c === void 0
1246
+ ? void 0
1247
+ : _c.map((item) => serializeCodeSource(pageCtx, item)),
1248
+ dataset: page === null || page === void 0 ? void 0 : page.dataset,
1249
+ dataVariables: (0, runtime_1.getValidValue)(
1250
+ (_e =
1251
+ (_d = page === null || page === void 0 ? void 0 : page.vars) === null || _d === void 0 ? void 0 : _d.data) ===
1252
+ null || _e === void 0
1253
+ ? void 0
1254
+ : _e.map((item) => serializeDataVariables(pageCtx, item)),
1255
+ ),
1256
+ listeners: (0, runtime_1.getValidValue)(
1257
+ (0, runtime_1.readListeners)(page.listenerInstances || []).map((item) => {
1258
+ return serializeListener(pageCtx, item);
1259
+ }),
1260
+ ),
1261
+ extra: {
1262
+ commonStyle: (0, runtime_1.getValidValue)((0, style_1.removeInvalidStyleFormValue)(page.style)),
1263
+ styleBindPath: (0, runtime_1.getValidValue)(page.styleBindPath),
1264
+ xIndex: page.xIndex,
1265
+ children: (0, runtime_1.getValidValue)(
1266
+ (_f = page.children) === null || _f === void 0 ? void 0 : _f.map((child) => serializeRuntimePage(ctx, child)),
1267
+ ),
1268
+ },
1269
+ };
1270
+ if ((0, common_2.isValidStyleBind)(page.styleBind) && (0, runtime_1.getValidValue)(page.styleBind)) {
1271
+ page[':style'] = serializeValue({
1272
+ ctx: pageCtx,
1273
+ key: 'styleBind',
1274
+ dynamicValue: page.styleBind,
1275
+ }).value;
1276
+ }
1277
+ if ((0, common_2.isValidClassNameListBind)(page.classListBind) && (0, runtime_1.getValidValue)(page.classListBind)) {
1278
+ page[':class'] = serializeValue({
1279
+ ctx: pageCtx,
1280
+ key: 'classListBind',
1281
+ dynamicValue: page.classListBind,
1282
+ });
1283
+ }
1284
+ return processedPage;
913
1285
  }
914
1286
  exports.serializeRuntimePage = serializeRuntimePage;
915
1287
  // /**
@@ -925,78 +1297,112 @@ exports.serializeRuntimePage = serializeRuntimePage;
925
1297
  * [formily] to [CALS]
926
1298
  */
927
1299
  function serializeRuntimeComponent(ctx, component) {
928
- var _a, _b, _c;
929
- if (!component.id) {
930
- component.id = component.key;
1300
+ var _a, _b, _c;
1301
+ if (!component.id) {
1302
+ component.id = component.key;
1303
+ }
1304
+ let processed = {
1305
+ id: component.id,
1306
+ type: undefined,
1307
+ component: '',
1308
+ label: (0, runtime_1.getValidValue)(component.label),
1309
+ };
1310
+ let props = component['x-props'];
1311
+ const { dependencies = [] } = ctx;
1312
+ if (props) {
1313
+ const [moduleName, name = ''] = props.sourceKey.split(':');
1314
+ const componentCtx = Object.assign(Object.assign({}, ctx), {
1315
+ component: { id: component.id, module: moduleName, component: name },
1316
+ });
1317
+ if (componentCtx.dependencies && !componentCtx.dependenciesMap) {
1318
+ componentCtx.dependenciesMap = processDependenciesMap(componentCtx.dependencies || []);
931
1319
  }
932
- let processed = {
933
- id: component.id,
934
- type: undefined,
935
- component: '',
936
- label: (0, runtime_1.getValidValue)(component.label),
937
- };
938
- let props = component['x-props'];
939
- const { dependencies = [] } = ctx;
940
- if (props) {
941
- const [moduleName, name = ''] = props.sourceKey.split(':');
942
- const componentCtx = Object.assign(Object.assign({}, ctx), { component: { id: component.id, module: moduleName, component: name } });
943
- if (componentCtx.dependencies && !componentCtx.dependenciesMap) {
944
- componentCtx.dependenciesMap = processDependenciesMap(componentCtx.dependencies || []);
945
- }
946
- const excludeKeys = (props.dataTypes || [])
947
- .filter((dataType) => dataType.type !== 'slot')
948
- .map((dataType) => dataType.propertyPath);
949
- let properties = component.properties || {};
950
- const { data: attributes = {}, extra: attributeExtraData = {} } = serializeAttributesWithExtra(componentCtx, 'page', (0, runtime_1.getValidValue)((0, runtime_1.readDynamicData)(props)) || {}) || {};
951
- let styleBindData = null;
952
- let classListBindData = null;
953
- if ((_a = props === null || props === void 0 ? void 0 : props.styleBind) === null || _a === void 0 ? void 0 : _a.bindDataPath) {
954
- styleBindData = serializeValue({
955
- ctx: componentCtx,
956
- key: 'styleBind',
957
- dynamicValue: {
958
- type: props.styleBind.type,
959
- value: props.styleBind.bindDataPath,
960
- extra: props.styleBind.extra,
961
- },
962
- });
963
- if (styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.extra) {
964
- attributeExtraData.style = styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.extra;
965
- }
966
- }
967
- if ((0, common_2.isValidClassNameListBind)(props.classNameListBind)) {
968
- classListBindData = serializeValue({
969
- ctx: componentCtx,
970
- key: 'classListBind',
971
- dynamicValue: (0, runtime_1.getValidValue)({
972
- type: props.classNameListBind.type,
973
- value: props.classNameListBind.bindDataPath,
974
- }),
975
- });
976
- if (classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.extra) {
977
- attributeExtraData.class = classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.extra;
978
- }
979
- }
980
- processed = Object.assign(Object.assign({}, processed), { module: serializeModuleName(componentCtx, moduleName, name), component: name, attributes: Object.assign(Object.assign({}, attributes), { style: (0, runtime_1.getValidValue)(props.style), class: (_b = (0, runtime_1.getValidValue)(props.classNameList)) === null || _b === void 0 ? void 0 : _b.join(' ') }), items: (0, runtime_1.getValidValue)(Object.keys(properties)
981
- .filter((key) => !excludeKeys.includes(key))
982
- .sort((a, b) => properties[a]['x-index'] - properties[b]['x-index'])
983
- .map((key) => serializeRuntimeComponent(ctx, Object.assign({ id: key }, properties[key])))), listeners: (_c = (0, runtime_1.getValidValue)((0, runtime_1.readListeners)(props.listenerInstances))) === null || _c === void 0 ? void 0 : _c.map((listener /* IEventListener */) => {
984
- return serializeListener(componentCtx, listener);
985
- }), directives: serializeDirecties(componentCtx, ((0, runtime_1.getValidValue)((0, runtime_1.readDirectives)(props)) || {})) || undefined, ':class': (classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.value) || undefined, ':style': (styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.value) || undefined, extra: {
986
- commonStyle: (0, runtime_1.getValidValue)((0, style_1.removeInvalidStyleFormValue)(props.commonStyle)),
987
- xIndex: (0, runtime_1.getValidValue)(component['x-index']),
988
- styleBindPath: (0, runtime_1.getValidValue)(props.styleBindPath),
989
- staticResourceAttribute: (0, runtime_1.getValidValue)(props.staticResourceAttribute),
990
- attributeExtraData: (0, common_2.isEmptyObj)(attributeExtraData) ? undefined : attributeExtraData,
991
- } });
1320
+ const excludeKeys = (props.dataTypes || [])
1321
+ .filter((dataType) => dataType.type !== 'slot')
1322
+ .map((dataType) => dataType.propertyPath);
1323
+ let properties = component.properties || {};
1324
+ const { data: attributes = {}, extra: attributeExtraData = {} } =
1325
+ serializeAttributesWithExtra(
1326
+ componentCtx,
1327
+ 'page',
1328
+ (0, runtime_1.getValidValue)((0, runtime_1.readDynamicData)(props)) || {},
1329
+ ) || {};
1330
+ let styleBindData = null;
1331
+ let classListBindData = null;
1332
+ if (
1333
+ (_a = props === null || props === void 0 ? void 0 : props.styleBind) === null || _a === void 0
1334
+ ? void 0
1335
+ : _a.bindDataPath
1336
+ ) {
1337
+ styleBindData = serializeValue({
1338
+ ctx: componentCtx,
1339
+ key: 'styleBind',
1340
+ dynamicValue: {
1341
+ type: props.styleBind.type,
1342
+ value: props.styleBind.bindDataPath,
1343
+ extra: props.styleBind.extra,
1344
+ },
1345
+ });
1346
+ if (styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.extra) {
1347
+ attributeExtraData.style = styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.extra;
1348
+ }
992
1349
  }
993
- else {
994
- let items = Object.keys(component.properties || {})
995
- .sort((a, b) => component.properties[a]['x-index'] - component.properties[b]['x-index'])
996
- .map((key) => serializeRuntimeComponent(ctx, Object.assign({ id: key }, component.properties[key])));
997
- processed = Object.assign(Object.assign({}, processed), { items: (0, runtime_1.getValidValue)(items) });
1350
+ if ((0, common_2.isValidClassNameListBind)(props.classNameListBind)) {
1351
+ classListBindData = serializeValue({
1352
+ ctx: componentCtx,
1353
+ key: 'classListBind',
1354
+ dynamicValue: (0, runtime_1.getValidValue)({
1355
+ type: props.classNameListBind.type,
1356
+ value: props.classNameListBind.bindDataPath,
1357
+ }),
1358
+ });
1359
+ if (classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.extra) {
1360
+ attributeExtraData.class =
1361
+ classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.extra;
1362
+ }
998
1363
  }
999
- return processed;
1364
+ processed = Object.assign(Object.assign({}, processed), {
1365
+ module: serializeModuleName(componentCtx, moduleName, name),
1366
+ component: name,
1367
+ attributes: Object.assign(Object.assign({}, attributes), {
1368
+ style: (0, runtime_1.getValidValue)(props.style),
1369
+ class:
1370
+ (_b = (0, runtime_1.getValidValue)(props.classNameList)) === null || _b === void 0 ? void 0 : _b.join(' '),
1371
+ }),
1372
+ items: (0, runtime_1.getValidValue)(
1373
+ Object.keys(properties)
1374
+ .filter((key) => !excludeKeys.includes(key))
1375
+ .sort((a, b) => properties[a]['x-index'] - properties[b]['x-index'])
1376
+ .map((key) => serializeRuntimeComponent(ctx, Object.assign({ id: key }, properties[key]))),
1377
+ ),
1378
+ listeners:
1379
+ (_c = (0, runtime_1.getValidValue)((0, runtime_1.readListeners)(props.listenerInstances))) === null ||
1380
+ _c === void 0
1381
+ ? void 0
1382
+ : _c.map((listener /* IEventListener */) => {
1383
+ return serializeListener(componentCtx, listener);
1384
+ }),
1385
+ directives:
1386
+ serializeDirecties(componentCtx, (0, runtime_1.getValidValue)((0, runtime_1.readDirectives)(props)) || {}) ||
1387
+ undefined,
1388
+ ':class':
1389
+ (classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.value) || undefined,
1390
+ ':style': (styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.value) || undefined,
1391
+ extra: {
1392
+ commonStyle: (0, runtime_1.getValidValue)((0, style_1.removeInvalidStyleFormValue)(props.commonStyle)),
1393
+ xIndex: (0, runtime_1.getValidValue)(component['x-index']),
1394
+ styleBindPath: (0, runtime_1.getValidValue)(props.styleBindPath),
1395
+ staticResourceAttribute: (0, runtime_1.getValidValue)(props.staticResourceAttribute),
1396
+ attributeExtraData: (0, common_2.isEmptyObj)(attributeExtraData) ? undefined : attributeExtraData,
1397
+ },
1398
+ });
1399
+ } else {
1400
+ let items = Object.keys(component.properties || {})
1401
+ .sort((a, b) => component.properties[a]['x-index'] - component.properties[b]['x-index'])
1402
+ .map((key) => serializeRuntimeComponent(ctx, Object.assign({ id: key }, component.properties[key])));
1403
+ processed = Object.assign(Object.assign({}, processed), { items: (0, runtime_1.getValidValue)(items) });
1404
+ }
1405
+ return processed;
1000
1406
  }
1001
1407
  exports.serializeRuntimeComponent = serializeRuntimeComponent;
1002
1408
  /**
@@ -1005,93 +1411,126 @@ exports.serializeRuntimeComponent = serializeRuntimeComponent;
1005
1411
  * To be continue, currently support listener
1006
1412
  */
1007
1413
  function deserializeRuntimeComponent(ctx, component) {
1008
- const { id, module, component: runtimeComponent, listeners = [] } = component;
1009
- let listenerInstances = (0, runtime_1.getValidValue)((0, runtime_1.writeListeners)((listeners === null || listeners === void 0 ? void 0 : listeners.map((item) => {
1010
- return Object.assign({ sourceKey: `${module}:${runtimeComponent}` }, deserializeListener(ctx, item));
1011
- })) || []));
1012
- const target = {
1013
- key: id,
1014
- type: 'object',
1015
- properties: {},
1016
- 'x-component': `${module}:${runtimeComponent}`,
1017
- 'x-props': {
1018
- sourceKey: `${module}:${runtimeComponent}`,
1019
- listenerInstances: listenerInstances || [],
1020
- },
1021
- };
1022
- return target;
1414
+ const { id, module, component: runtimeComponent, listeners = [] } = component;
1415
+ let listenerInstances = (0, runtime_1.getValidValue)(
1416
+ (0, runtime_1.writeListeners)(
1417
+ (listeners === null || listeners === void 0
1418
+ ? void 0
1419
+ : listeners.map((item) => {
1420
+ return Object.assign({ sourceKey: `${module}:${runtimeComponent}` }, deserializeListener(ctx, item));
1421
+ })) || [],
1422
+ ),
1423
+ );
1424
+ const target = {
1425
+ key: id,
1426
+ type: 'object',
1427
+ properties: {},
1428
+ 'x-component': `${module}:${runtimeComponent}`,
1429
+ 'x-props': {
1430
+ sourceKey: `${module}:${runtimeComponent}`,
1431
+ listenerInstances: listenerInstances || [],
1432
+ },
1433
+ };
1434
+ return target;
1023
1435
  }
1024
1436
  exports.deserializeRuntimeComponent = deserializeRuntimeComponent;
1025
1437
  function processDependenciesMap(dependencies = []) {
1026
- let map = dependencies.reduce((map, componentLib) => {
1027
- let { components = [] } = componentLib;
1028
- for (let item of components) {
1029
- map[item.sourceKey] = item;
1030
- }
1031
- return map;
1032
- }, {});
1438
+ let map = dependencies.reduce((map, componentLib) => {
1439
+ let { components = [] } = componentLib;
1440
+ for (let item of components) {
1441
+ map[item.sourceKey] = item;
1442
+ }
1033
1443
  return map;
1444
+ }, {});
1445
+ return map;
1034
1446
  }
1035
1447
  function deserializeComponentLibraryMeta(meta) {
1036
- let { components = {}, actions = {}, styles = [], dependencies = {} } = meta, restLibraryMeta = __rest(meta, ["components", "actions", "styles", "dependencies"]);
1037
- let processedComponents = {};
1038
- for (const componentName in components) {
1039
- let component = components[componentName];
1040
- let _a = (component.meta || {}), { title, description, category, icon, extra = {} } = _a, restComponentMeta = __rest(_a, ["title", "description", "category", "icon", "extra"]);
1041
- processedComponents[componentName] = Object.assign(Object.assign({ title: title || component.name || componentName, desc: description || '', category: category || '', thumbnail: icon }, extra), restComponentMeta);
1042
- }
1043
- return Object.assign(Object.assign({}, restLibraryMeta), { styles,
1044
- dependencies, components: processedComponents, actions });
1448
+ let { components = {}, actions = {}, styles = [], dependencies = {} } = meta,
1449
+ restLibraryMeta = __rest(meta, ['components', 'actions', 'styles', 'dependencies']);
1450
+ let processedComponents = {};
1451
+ for (const componentName in components) {
1452
+ let component = components[componentName];
1453
+ let _a = component.meta || {},
1454
+ { title, description, category, icon, extra = {} } = _a,
1455
+ restComponentMeta = __rest(_a, ['title', 'description', 'category', 'icon', 'extra']);
1456
+ processedComponents[componentName] = Object.assign(
1457
+ Object.assign(
1458
+ {
1459
+ title: title || component.name || componentName,
1460
+ desc: description || '',
1461
+ category: category || '',
1462
+ thumbnail: icon,
1463
+ },
1464
+ extra,
1465
+ ),
1466
+ restComponentMeta,
1467
+ );
1468
+ }
1469
+ return Object.assign(Object.assign({}, restLibraryMeta), {
1470
+ styles,
1471
+ dependencies,
1472
+ components: processedComponents,
1473
+ actions,
1474
+ });
1045
1475
  }
1046
1476
  exports.deserializeComponentLibraryMeta = deserializeComponentLibraryMeta;
1047
1477
  function processRuntimeCodeResources(ctx, resources /* : IWeappCode[]*/ = [], scope) {
1048
- const { id } = ctx;
1049
- const fileTypes = [common_1.ECodeType.STYLE, common_1.ECodeType.STATE, common_1.ECodeType.LIFECYCLE, common_1.ECodeType.COMPUTEDN];
1050
- const CODE_TYPE_NAME_MAP = {
1051
- [common_1.ECodeType.STATE]: common_1.ECodeName.STATE,
1052
- [common_1.ECodeType.COMPUTEDN]: common_1.ECodeName.COMPUTEDN,
1053
- [common_1.ECodeType.STYLE]: common_1.ECodeName.STYLE,
1054
- [common_1.ECodeType.LIFECYCLE]: common_1.ECodeName.LIFECYCLE,
1055
- };
1056
- const isComponent = id === '$comp' || scope === 'component';
1057
- if (id === 'global' || scope === 'app') {
1058
- fileTypes.push(common_1.ECodeType.THEME);
1478
+ const { id } = ctx;
1479
+ const fileTypes = [
1480
+ common_1.ECodeType.STYLE,
1481
+ common_1.ECodeType.STATE,
1482
+ common_1.ECodeType.LIFECYCLE,
1483
+ common_1.ECodeType.COMPUTEDN,
1484
+ ];
1485
+ const CODE_TYPE_NAME_MAP = {
1486
+ [common_1.ECodeType.STATE]: common_1.ECodeName.STATE,
1487
+ [common_1.ECodeType.COMPUTEDN]: common_1.ECodeName.COMPUTEDN,
1488
+ [common_1.ECodeType.STYLE]: common_1.ECodeName.STYLE,
1489
+ [common_1.ECodeType.LIFECYCLE]: common_1.ECodeName.LIFECYCLE,
1490
+ };
1491
+ const isComponent = id === '$comp' || scope === 'component';
1492
+ if (id === 'global' || scope === 'app') {
1493
+ fileTypes.push(common_1.ECodeType.THEME);
1494
+ }
1495
+ const EXIST_FILE_TYPE_MAP = {};
1496
+ resources.forEach((mod) => {
1497
+ EXIST_FILE_TYPE_MAP[mod.type] = true;
1498
+ });
1499
+ fileTypes.forEach((type) => {
1500
+ const isHasLowcodeIndex = EXIST_FILE_TYPE_MAP[type];
1501
+ if (!isHasLowcodeIndex) {
1502
+ const name = CODE_TYPE_NAME_MAP[type] || type;
1503
+ resources.unshift({
1504
+ name,
1505
+ type,
1506
+ code: (0, template_1.generateDefaultCode)(
1507
+ ctx,
1508
+ type,
1509
+ isComponent ? 'component' : id === 'global' ? 'app' : 'page',
1510
+ ),
1511
+ path: `${id}/${name}`,
1512
+ system: true,
1513
+ });
1059
1514
  }
1060
- const EXIST_FILE_TYPE_MAP = {};
1061
- resources.forEach((mod) => {
1062
- EXIST_FILE_TYPE_MAP[mod.type] = true;
1063
- });
1064
- fileTypes.forEach((type) => {
1065
- const isHasLowcodeIndex = EXIST_FILE_TYPE_MAP[type];
1066
- if (!isHasLowcodeIndex) {
1067
- const name = CODE_TYPE_NAME_MAP[type] || type;
1068
- resources.unshift({
1069
- name,
1070
- type,
1071
- code: (0, template_1.generateDefaultCode)(ctx, type, isComponent ? 'component' : id === 'global' ? 'app' : 'page'),
1072
- path: `${id}/${name}`,
1073
- system: true,
1074
- });
1075
- }
1076
- });
1077
- return resources.filter((m) => m.name !== common_1.ECodeName.PLACEHOLDER);
1515
+ });
1516
+ return resources.filter((m) => m.name !== common_1.ECodeName.PLACEHOLDER);
1078
1517
  }
1079
1518
  exports.processRuntimeCodeResources = processRuntimeCodeResources;
1080
1519
  /**
1081
1520
  * 解析 cals version 来生成 feature map
1082
1521
  */
1083
1522
  function parseVersion(version = '') {
1084
- const list = version.split('.');
1085
- const FEATURE_MAP = {
1086
- /**
1087
- * 默认单位为 px,
1088
- * 然后进行动态转换 为 rem及rpx
1089
- */
1090
- defaultDynamicCssUnit: true,
1091
- };
1092
- if (list[0] === '4' || version === 'latest') {
1093
- FEATURE_MAP.defaultDynamicCssUnit = false;
1094
- }
1095
- return FEATURE_MAP;
1523
+ const list = version.split('.');
1524
+ const FEATURE_MAP = {
1525
+ /**
1526
+ * 默认单位为 px,
1527
+ * 然后进行动态转换 为 rem及rpx
1528
+ */
1529
+ defaultDynamicCssUnit: true,
1530
+ };
1531
+ if (list[0] === '4' || version === 'latest') {
1532
+ FEATURE_MAP.defaultDynamicCssUnit = false;
1533
+ }
1534
+ return FEATURE_MAP;
1096
1535
  }
1097
1536
  exports.parseVersion = parseVersion;