@cloudbase/cals 0.5.11-beta1 → 0.5.11-beta3

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,272 +1,211 @@
1
- 'use strict';
2
- var __rest =
3
- (this && this.__rest) ||
4
- function (s, e) {
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
5
3
  var t = {};
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
- return t;
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];
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]];
84
10
  }
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';
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
+ }
90
86
  }
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
87
  }
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;
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;
94
+ }
133
95
  }
134
- }
135
- return { key, value, extra: dynamicValue.extra };
96
+ return { key, value, extra: dynamicValue.extra };
136
97
  }
137
98
  exports.serializeValue = serializeValue;
138
99
  const DYNAMIC_KEY_REG = /^:(.*)$/;
139
100
  function deserializeValue(ctx, key, value, extra) {
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;
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;
159
106
  try {
160
- value = value.replace(/\$app\./g, 'app.').replace(/\$for./g, 'forItems.');
161
- } catch (e) {}
162
- }
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
+ };
163
142
  }
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
- }
181
143
  }
182
144
  exports.deserializeValue = deserializeValue;
183
145
  function serializeDynamicMap(props) {
184
- return serializeDynamicMapWithExtra(props).data;
146
+ return serializeDynamicMapWithExtra(props).data;
185
147
  }
186
148
  exports.serializeDynamicMap = serializeDynamicMap;
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
- }
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
+ }
201
164
  })
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;
258
- });
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);
259
178
  }
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);
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;
196
+ });
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
+ }
265
205
  }
266
- }
267
- extra[originKey] = processedExtra;
206
+ extra[originKey] = processedExtra;
268
207
  });
269
- return { data, extra };
208
+ return { data, extra };
270
209
  }
271
210
  /**
272
211
  * 将{ range: [{ label: "$page.dataset.state.test1"}] }的path range.0.label 转为range.0.:label
@@ -274,10 +213,10 @@ function serializeDynamicMapWithExtra({ ctx, map = {}, scope = 'page', streamlin
274
213
  * @returns
275
214
  */
276
215
  function replaceWithColon(key) {
277
- const keyArr = key.split('.');
278
- // 最深一层前面加上":"
279
- keyArr[keyArr.length - 1] = `:${keyArr[keyArr.length - 1]}`;
280
- return keyArr.join('.');
216
+ const keyArr = key.split('.');
217
+ // 最深一层前面加上":"
218
+ keyArr[keyArr.length - 1] = `:${keyArr[keyArr.length - 1]}`;
219
+ return keyArr.join('.');
281
220
  }
282
221
  /**
283
222
  * 预处理,先还原数据。
@@ -289,126 +228,97 @@ function replaceWithColon(key) {
289
228
  * @returns
290
229
  */
291
230
  function recoverSynamicMap(parent, current, path = '') {
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}`);
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
+ });
307
244
  }
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);
245
+ else if ((0, lodash_1.isObject)(value)) {
246
+ value = recoverSynamicMap(parent, value, `${path === '' ? '' : `${path}.`}${key}`);
318
247
  }
319
- }
320
- }
321
- });
322
- return current;
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;
323
260
  }
324
261
  function deserializeDynamicMap(ctx, map, extraMap) {
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;
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
+ }
378
288
  }
379
- }
380
- return data;
289
+ return data;
381
290
  }
382
291
  exports.deserializeDynamicMap = deserializeDynamicMap;
383
292
  function serializeAttributes(ctx, scope, attributes = {}) {
384
- var _a;
385
- return (_a = serializeAttributesWithExtra(ctx, scope, attributes)) === null || _a === void 0 ? void 0 : _a.data;
293
+ var _a;
294
+ return (_a = serializeAttributesWithExtra(ctx, scope, attributes)) === null || _a === void 0 ? void 0 : _a.data;
386
295
  }
387
296
  exports.serializeAttributes = serializeAttributes;
388
297
  function serializeAttributesWithExtra(ctx, scope, attributes = {}) {
389
- return serializeDynamicMapWithExtra({
390
- ctx,
391
- scope,
392
- map: attributes,
393
- streamlineDefaultValue: ctx.streamlineDefaultValue,
394
- });
298
+ return serializeDynamicMapWithExtra({
299
+ ctx,
300
+ scope,
301
+ map: attributes,
302
+ streamlineDefaultValue: ctx.streamlineDefaultValue,
303
+ });
395
304
  }
396
305
  function deserializeAttributes(ctx, attributes = {}, attributesExtraData = {}) {
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];
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
+ }
409
320
  }
410
- }
411
- return deserializeDynamicMap(ctx, restAttributes, attributesExtraData);
321
+ return deserializeDynamicMap(ctx, restAttributes, attributesExtraData);
412
322
  }
413
323
  exports.deserializeAttributes = deserializeAttributes;
414
324
  /**
@@ -416,607 +326,459 @@ exports.deserializeAttributes = deserializeAttributes;
416
326
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
417
327
  */
418
328
  function serializeDataset(ctx, dataset) {
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;
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;
444
350
  }
445
351
  /**
446
352
  * 将dataset({state: {}, params: {}})从 cals 结构转换为weapp结构
447
353
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
448
354
  */
449
355
  function deserializeDataset(ctx, dataset) {
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;
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;
464
372
  }
465
373
  /**
466
374
  * dataset 是否需要转换处理
467
375
  * dataset 为空, 或者无数据源变量, 或者变量中未使用入参, 则不需要进行转换
468
376
  */
469
377
  function isDatasetNeedToProcess(dataset) {
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;
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;
483
387
  }
484
388
  function serializeDirecties(ctx, directives, scope = 'page') {
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;
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
+ }
518
421
  }
519
- }
520
- return undefined;
422
+ return undefined;
521
423
  }
522
424
  function deserializeDirecties(ctx, directives) {
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)/, '');
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
+ }
537
433
  }
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;
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
+ }
548
444
  }
549
- }
550
- return undefined;
445
+ return undefined;
551
446
  }
552
447
  /**
553
448
  * TODO
554
449
  * heander 更新为表达式
555
450
  */
556
451
  function serializeListener(ctx, listener) {
557
- const { data, extra = {} } =
558
- serializeDynamicMapWithExtra({
559
- ctx,
560
- map: listener.data,
452
+ const { data, extra = {} } = serializeDynamicMapWithExtra({
453
+ ctx,
454
+ map: listener.data,
561
455
  }) || {};
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,
574
- };
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,
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,
583
466
  };
584
- }
585
- if (Object.keys(extra).some((key) => extra[key] !== undefined)) {
586
- if (!platfromListener.extra) {
587
- platfromListener.extra = {};
467
+ if (listener.jsCode) {
468
+ platfromListener.jsCode = listener.jsCode;
469
+ }
470
+ if (Object.keys(extra).some((key) => extra[key] !== undefined)) {
471
+ if (!platfromListener.extra) {
472
+ platfromListener.extra = {};
473
+ }
474
+ platfromListener.extra.handlerParamExtraData = extra;
588
475
  }
589
- platfromListener.extra.handlerParamExtraData = extra;
590
- }
591
- return platfromListener;
476
+ return platfromListener;
592
477
  }
593
478
  function deserializeListener(ctx, listener) {
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;
479
+ var _a, _b, _c, _d;
480
+ let processed = {
481
+ key: listener.id,
482
+ trigger: listener.eventName,
483
+ type: listener.type,
484
+ handler: {
485
+ name: (_a = listener.handler) === null || _a === void 0 ? void 0 : _a.name,
486
+ moduleName: (_b = listener.handler) === null || _b === void 0 ? void 0 : _b.module,
487
+ },
488
+ 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) || {}),
489
+ isCapturePhase: !!listener.isCapturePhase,
490
+ // TODO
491
+ noPropagation: !!listener.noPropagation,
492
+ };
493
+ if (listener.jsCode) {
494
+ // @ts-ignore
495
+ processed.jsCode = listener.jsCode;
496
+ }
497
+ return processed;
618
498
  }
619
499
  function serializeDataVariables(ctx, data) {
620
- let { title } = data,
621
- restData = __rest(data, ['title']);
622
- return Object.assign(Object.assign({ varType: 'datasource' }, restData), { label: title });
500
+ let { title } = data, restData = __rest(data, ["title"]);
501
+ return Object.assign(Object.assign({ varType: 'datasource' }, restData), { label: title });
623
502
  }
624
503
  function deserializeDataVariables(ctx, data) {
625
- let { label } = data,
626
- restData = __rest(data, ['label']);
627
- return Object.assign(Object.assign({}, restData), { title: label });
504
+ let { label } = data, restData = __rest(data, ["label"]);
505
+ return Object.assign(Object.assign({}, restData), { title: label });
628
506
  }
629
507
  exports.deserializeDataVariables = deserializeDataVariables;
630
508
  function serializeCodeSource(ctx, data) {
631
- const { type } = data;
632
- return Object.assign(Object.assign({}, data), { type: common_1.EResourceType.CODE, codeType: type });
509
+ const { type } = data;
510
+ return Object.assign(Object.assign({}, data), { type: common_1.EResourceType.CODE, codeType: type });
633
511
  }
634
512
  function deserializeCodeResource(ctx, data) {
635
- const { type, codeType } = data,
636
- resData = __rest(data, ['type', 'codeType']);
637
- return Object.assign(Object.assign({}, resData), { type: codeType });
513
+ const { type, codeType } = data, resData = __rest(data, ["type", "codeType"]);
514
+ return Object.assign(Object.assign({}, resData), { type: codeType });
638
515
  }
639
516
  function serializeModuleName(ctx, moduleName, componentName) {
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;
645
- }
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
- }
517
+ var _a, _b;
518
+ let { dependencies = [], dependenciesMap = {} } = ctx;
519
+ if (ctx.streamlineModuleName) {
520
+ if (moduleName === ((_a = dependencies[0]) === null || _a === void 0 ? void 0 : _a.name)) {
521
+ moduleName = undefined;
522
+ }
523
+ let find = undefined;
524
+ for (let i = dependencies.length - 1; i > 0; i--) {
525
+ let lib = dependencies[i];
526
+ let currentModuleName = lib.name;
527
+ let key = `${currentModuleName}:${componentName}`;
528
+ if (!!dependenciesMap[key]) {
529
+ find = lib;
530
+ break;
531
+ }
532
+ }
533
+ if (find) {
534
+ if ((find === null || find === void 0 ? void 0 : find.name) === moduleName) {
535
+ return undefined;
536
+ }
537
+ }
538
+ else if (((_b = dependencies[0]) === null || _b === void 0 ? void 0 : _b.name) === moduleName) {
539
+ return undefined;
540
+ }
655
541
  }
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;
542
+ else if (moduleName &&
543
+ !/-lcap-spinoff$/.test(moduleName) &&
544
+ !dependenciesMap[`${moduleName}:${componentName}`] &&
545
+ dependenciesMap[`${moduleName}-lcap-spinoff:${componentName}`]) {
546
+ return `${moduleName}-lcap-spinoff`;
662
547
  }
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;
548
+ return moduleName;
672
549
  }
673
550
  function deserializeModuleName(ctx, componentName, moduleName) {
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
- }
551
+ var _a;
552
+ let { dependencies = [], dependenciesMap = {} } = ctx;
553
+ let defaultModuleName = (_a = dependencies[0]) === null || _a === void 0 ? void 0 : _a.name;
554
+ // 补充默认的 moduleName 按照依赖反序查找
555
+ if (!moduleName) {
556
+ let find = undefined;
557
+ for (let i = dependencies.length - 1; i > 0; i--) {
558
+ let lib = dependencies[i];
559
+ let { name } = lib;
560
+ let key = `${name}:${componentName}`;
561
+ if (!!dependenciesMap[key]) {
562
+ find = lib;
563
+ break;
564
+ }
565
+ }
566
+ return find ? find === null || find === void 0 ? void 0 : find.name : defaultModuleName;
567
+ }
568
+ else if (moduleName &&
569
+ !/-lcap-spinoff$/.test(moduleName) &&
570
+ !dependenciesMap[`${moduleName}:${componentName}`] &&
571
+ dependenciesMap[`${moduleName}-lcap-spinoff:${componentName}`]) {
572
+ return `${moduleName}-lcap-spinoff`;
688
573
  }
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;
574
+ return moduleName;
699
575
  }
700
576
  function serializeComponent(ctx, component, scope = 'page') {
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;
742
- }
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;
577
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
578
+ // const scope = ctx.component?.id ? 'component' : 'page'
579
+ const moduleName = (_a = component.xComponent) === null || _a === void 0 ? void 0 : _a.moduleName;
580
+ const componentName = ((_b = component.xComponent) === null || _b === void 0 ? void 0 : _b.name) || '';
581
+ const componentCtx = Object.assign(Object.assign({}, ctx), { component: {
582
+ id: component.id,
583
+ module: moduleName,
584
+ component: (_c = component.xComponent) === null || _c === void 0 ? void 0 : _c.name,
585
+ } });
586
+ if (componentCtx.dependencies && !componentCtx.dependenciesMap) {
587
+ componentCtx.dependenciesMap = processDependenciesMap(componentCtx.dependencies || []);
759
588
  }
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]),
589
+ let attributeMeta = serializeAttributesWithExtra(componentCtx, scope, (((_d = component === null || component === void 0 ? void 0 : component.xProps) === null || _d === void 0 ? void 0 : _d.data) || {})) || {};
590
+ const { data: attributes = {}, extra: attributeExtraData = {} } = attributeMeta;
591
+ let classListBindData = null;
592
+ let styleBindData = null;
593
+ if ((_e = component === null || component === void 0 ? void 0 : component.xProps) === null || _e === void 0 ? void 0 : _e.classListBind) {
594
+ classListBindData = serializeValue({
595
+ ctx: componentCtx,
596
+ key: 'classListBind',
597
+ dynamicValue: (_f = component === null || component === void 0 ? void 0 : component.xProps) === null || _f === void 0 ? void 0 : _f.classListBind,
784
598
  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) => {
599
+ });
600
+ if (classListBindData.extra) {
601
+ attributeExtraData.class = classListBindData.extra;
602
+ }
603
+ }
604
+ if ((_g = component === null || component === void 0 ? void 0 : component.xProps) === null || _g === void 0 ? void 0 : _g.styleBind) {
605
+ styleBindData = serializeValue({
606
+ ctx: componentCtx,
607
+ key: 'styleBind',
608
+ dynamicValue: (_h = component === null || component === void 0 ? void 0 : component.xProps) === null || _h === void 0 ? void 0 : _h.styleBind,
609
+ });
610
+ if (styleBindData.extra) {
611
+ attributeExtraData.style = styleBindData.extra;
612
+ }
613
+ }
614
+ return {
615
+ id: component.id,
616
+ label: (0, runtime_1.getValidValue)(component.label),
617
+ type: undefined,
618
+ module: serializeModuleName(componentCtx, moduleName, componentName),
619
+ component: componentName,
620
+ attributes: (0, runtime_1.getValidValue)(component.xProps
621
+ ? 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),
622
+ items: component.properties
623
+ ? Object.keys(component.properties).map((key) => {
624
+ var _a;
625
+ return serializeComponent(componentCtx, Object.assign({ id: key }, (_a = component.properties) === null || _a === void 0 ? void 0 : _a[key]), scope);
626
+ })
627
+ : undefined,
628
+ 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) => {
792
629
  return serializeListener(componentCtx, listener);
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
- };
630
+ })),
631
+ directives: serializeDirecties(componentCtx, (((_p = component.xProps) === null || _p === void 0 ? void 0 : _p.directives) || {}), scope) || {
632
+ ':if': true,
633
+ },
634
+ ':class': classListBindData ? classListBindData.value : undefined,
635
+ ':style': styleBindData ? styleBindData.value : undefined,
636
+ extra: {
637
+ commonStyle: (_q = component.xProps) === null || _q === void 0 ? void 0 : _q.commonStyle,
638
+ xIndex: component.xIndex,
639
+ styleBindPath: (_r = component === null || component === void 0 ? void 0 : component.xProps) === null || _r === void 0 ? void 0 : _r.styleBindPath,
640
+ staticResourceAttribute: (_s = component === null || component === void 0 ? void 0 : component.xProps) === null || _s === void 0 ? void 0 : _s.staticResourceAttribute,
641
+ attributeExtraData: (0, common_2.isEmptyObj)(attributeExtraData) ? undefined : attributeExtraData,
642
+ },
643
+ };
818
644
  }
819
645
  exports.serializeComponent = serializeComponent;
820
646
  function deserializeComponent(ctx, components) {
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);
874
- })) || [],
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;
647
+ let componentMap = components.reduce((map, item) => {
648
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
649
+ const { attributeExtraData = {} } = item.extra || {};
650
+ let dynamicStyle = item[':style']
651
+ ? deserializeValue(ctx, ':style', item[':style'], attributeExtraData.style).value
652
+ : undefined;
653
+ let dynamicClassList = item[':class']
654
+ ? deserializeValue(ctx, ':class', item[':class'], attributeExtraData.class).value
655
+ : undefined;
656
+ const xComponent = {
657
+ moduleName: item.module,
658
+ name: item.component || undefined,
659
+ };
660
+ if (xComponent.name) {
661
+ xComponent.moduleName =
662
+ deserializeModuleName(ctx, xComponent.name, xComponent.moduleName) || xComponent.moduleName;
881
663
  }
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;
664
+ const xProps = {
665
+ data: deserializeAttributes(ctx, item.attributes, attributeExtraData),
666
+ directives: deserializeDirecties(ctx, item.directives || {}),
667
+ style: (_a = item.attributes) === null || _a === void 0 ? void 0 : _a.style,
668
+ styleBind: dynamicStyle
669
+ ? {
670
+ type: dynamicStyle.type,
671
+ value: dynamicStyle.value,
672
+ }
673
+ : undefined,
674
+ commonStyle: (_b = item === null || item === void 0 ? void 0 : item.extra) === null || _b === void 0 ? void 0 : _b.commonStyle,
675
+ staticResourceAttribute: (_c = item === null || item === void 0 ? void 0 : item.extra) === null || _c === void 0 ? void 0 : _c.staticResourceAttribute,
676
+ 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),
677
+ classListBind: item[':class']
678
+ ? {
679
+ value: dynamicClassList === null || dynamicClassList === void 0 ? void 0 : dynamicClassList.value,
680
+ type: dynamicClassList === null || dynamicClassList === void 0 ? void 0 : dynamicClassList.type,
681
+ }
682
+ : undefined,
683
+ listeners: ((_g = item === null || item === void 0 ? void 0 : item.listeners) === null || _g === void 0 ? void 0 : _g.map((item) => {
684
+ return deserializeListener(ctx, item);
685
+ })) || [],
686
+ };
687
+ let processed = {
688
+ xComponent: Object.values(xComponent).find((item) => item != undefined) ? xComponent : undefined,
689
+ xProps: Object.values(xProps).find((item) => {
690
+ if (Array.isArray(item)) {
691
+ return !!item.length;
692
+ }
693
+ return item != undefined && !(0, common_2.isEmptyObj)(item);
694
+ })
695
+ ? xProps
696
+ : undefined,
697
+ /**
698
+ * TODO
699
+ */
700
+ 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*/,
701
+ label: (item === null || item === void 0 ? void 0 : item.label) !== undefined ? item === null || item === void 0 ? void 0 : item.label : undefined /* 0*/,
702
+ properties: item.items ? deserializeComponent(ctx, item.items) : undefined,
703
+ };
704
+ map[item.id] = processed;
705
+ return map;
706
+ }, {});
707
+ return componentMap;
907
708
  }
908
709
  exports.deserializeComponent = deserializeComponent;
909
710
  function serializePage(ctx, page) {
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) => {
711
+ var _a, _b, _c, _d, _e;
712
+ const pageCtx = Object.assign(Object.assign({}, ctx), { page });
713
+ if (pageCtx.dependencies && !pageCtx.dependenciesMap) {
714
+ pageCtx.dependenciesMap = processDependenciesMap(pageCtx.dependencies || []);
715
+ }
716
+ let processedPage = {
717
+ id: page.id,
718
+ type: 'PAGE',
719
+ component: 'Page',
720
+ attributes: (0, runtime_1.getValidValue)((_a = serializeAttributesWithExtra(pageCtx, 'page', page.data)) === null || _a === void 0 ? void 0 : _a.data),
721
+ items: Object.keys(page.componentInstances || {}).map((id) => {
722
+ return serializeComponent(pageCtx, Object.assign({ id }, page.componentInstances[id]));
723
+ }),
724
+ directives: {
725
+ ':if': true,
726
+ },
727
+ resources: (_b = page === null || page === void 0 ? void 0 : page.lowCodes) === null || _b === void 0 ? void 0 : _b.map((item) => serializeCodeSource(pageCtx, item)),
728
+ dataset: serializeDataset(ctx, page === null || page === void 0 ? void 0 : page.dataset),
729
+ 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))),
730
+ listeners: (0, runtime_1.getValidValue)((_e = page === null || page === void 0 ? void 0 : page.listeners) === null || _e === void 0 ? void 0 : _e.map((item) => {
944
731
  return serializeListener(pageCtx, item);
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;
732
+ })),
733
+ extra: {
734
+ commonStyle: page === null || page === void 0 ? void 0 : page.commonStyle,
735
+ xIndex: page.xIndex,
736
+ staticResourceAttribute: page === null || page === void 0 ? void 0 : page.staticResourceAttribute,
737
+ hideAdminPortalMenu: page === null || page === void 0 ? void 0 : page.hideAdminPortalMenu,
738
+ },
739
+ };
740
+ if (page.styleBind) {
741
+ page[':style'] = serializeValue({
742
+ ctx: pageCtx,
743
+ key: 'styleBind',
744
+ dynamicValue: page.styleBind,
745
+ }).value;
746
+ }
747
+ if (page.classListBind) {
748
+ page[':class'] = serializeValue({
749
+ ctx: pageCtx,
750
+ key: 'classListBind',
751
+ dynamicValue: page.classListBind,
752
+ });
753
+ }
754
+ return processedPage;
969
755
  }
970
756
  exports.serializePage = serializePage;
971
757
  function deserializePage(ctx, page) {
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);
758
+ var _a, _b, _c, _d, _e, _f, _g;
759
+ let pageCtx = Object.assign(Object.assign({}, ctx), { page });
760
+ return {
761
+ id: page.id,
762
+ isHome: page.id === ctx.homePageId,
763
+ dataset: deserializeDataset(ctx, page.dataset),
764
+ vars: {
765
+ data: ((_a = page.dataVariables) === null || _a === void 0 ? void 0 : _a.map((item) => {
766
+ return deserializeDataVariables(pageCtx, item);
984
767
  })) || [],
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) => {
768
+ },
769
+ data: deserializeAttributes(pageCtx, page.attributes, (_b = page === null || page === void 0 ? void 0 : page.extra) === null || _b === void 0 ? void 0 : _b.attributeExtraData),
770
+ componentInstances: deserializeComponent(pageCtx, page.items || []),
771
+ commonStyle: (_c = page === null || page === void 0 ? void 0 : page.extra) === null || _c === void 0 ? void 0 : _c.commonStyle,
772
+ staticResourceAttribute: (_d = page === null || page === void 0 ? void 0 : page.extra) === null || _d === void 0 ? void 0 : _d.staticResourceAttribute,
773
+ hideAdminPortalMenu: (_e = page === null || page === void 0 ? void 0 : page.extra) === null || _e === void 0 ? void 0 : _e.hideAdminPortalMenu,
774
+ 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)),
775
+ listeners: ((_g = page === null || page === void 0 ? void 0 : page.listeners) === null || _g === void 0 ? void 0 : _g.map((item) => {
1014
776
  return deserializeListener(pageCtx, item);
1015
- })) || [],
1016
- // TODO
1017
- // children: [],
1018
- // styleBindPath: item.styleBindPath,
1019
- };
777
+ })) || [],
778
+ // TODO
779
+ // children: [],
780
+ // styleBindPath: item.styleBindPath,
781
+ };
1020
782
  }
1021
783
  exports.deserializePage = deserializePage;
1022
784
  /**
@@ -1025,96 +787,34 @@ exports.deserializePage = deserializePage;
1025
787
  * @param data
1026
788
  */
1027
789
  function serializePlatformApp(data, optsions) {
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;
790
+ var _a;
791
+ 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"]);
792
+ let { dependencies = [] } = optsions || {};
793
+ const _b = extra || {}, { name: extraName, label: extraLabel, author: extraAuthor, description: extraDescription } = _b, restExtra = __rest(_b, ["name", "label", "author", "description"]);
794
+ const ctx = {
795
+ app: data,
796
+ dependencies,
797
+ dependenciesMap: processDependenciesMap(dependencies),
798
+ };
799
+ const homePage = pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList.find((page) => page.isHome);
800
+ let processed = {
801
+ label: label || extraLabel,
802
+ name: name || extraName,
803
+ author: author || extraAuthor,
804
+ version,
805
+ schemaVersion,
806
+ description: description || extraDescription,
807
+ externalResources,
808
+ main: homePage ? homePage.id : ((_a = pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList[0]) === null || _a === void 0 ? void 0 : _a.id) || selectedPageId,
809
+ items: pageInstanceList === null || pageInstanceList === void 0 ? void 0 : pageInstanceList.map((page) => serializePage(ctx, page)),
810
+ resources: lowCodes === null || lowCodes === void 0 ? void 0 : lowCodes.map((item) => serializeCodeSource(ctx, item)),
811
+ dataSources: datasources,
812
+ dataset: serializeDataset(ctx, dataset),
813
+ dataVariables: (0, runtime_1.getValidValue)(vars === null || vars === void 0 ? void 0 : vars.data.map((item) => serializeDataVariables(ctx, item))),
814
+ dependencies: calsDependencies,
815
+ 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 }),
816
+ };
817
+ return processed;
1118
818
  }
1119
819
  exports.serializePlatformApp = serializePlatformApp;
1120
820
  /**
@@ -1123,89 +823,54 @@ exports.serializePlatformApp = serializePlatformApp;
1123
823
  * @param data
1124
824
  */
1125
825
  function deserializePlatformApp(data, optsions) {
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);
826
+ var _a, _b;
827
+ let homePageId = data.main || ((_a = data.items[0]) === null || _a === void 0 ? void 0 : _a.id) || '';
828
+ let extra = data.extra || {};
829
+ 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"]);
830
+ const ctx = {
831
+ app: data,
832
+ dependencies: (optsions === null || optsions === void 0 ? void 0 : optsions.dependencies) || [],
833
+ homePageId,
834
+ dependenciesMap: processDependenciesMap(((optsions === null || optsions === void 0 ? void 0 : optsions.dependencies) || [])),
835
+ };
836
+ let processed = {
837
+ id: data.id,
838
+ version: data.version,
839
+ author: data.author,
840
+ name: data.name,
841
+ label: data.label,
842
+ description: data.description,
843
+ selectedPageId: homePageId,
844
+ historyType,
845
+ pageInstanceList: (data.items || []).map((page) => deserializePage(ctx, page)),
846
+ // lowCodes: data.resources || [],
847
+ lowCodes: (data.resources || [])
848
+ .filter((item) => item.type === common_1.EResourceType.CODE)
849
+ .map((item) => deserializeCodeResource(ctx, item)),
850
+ datasources: data.dataSources,
851
+ dataset: deserializeDataset(ctx, data.dataset),
852
+ vars: {
853
+ data: ((_b = data.dataVariables) === null || _b === void 0 ? void 0 : _b.map((item) => {
854
+ return deserializeDataVariables(ctx, item);
1185
855
  })) || [],
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;
856
+ },
857
+ compHiddenConfig: compHiddenConfig || {},
858
+ npmDependencies: npmDependencies || {},
859
+ plugins: plugins || [],
860
+ maxID,
861
+ rootPath,
862
+ themeVars,
863
+ presetColors: presetColors || [],
864
+ appConfig,
865
+ miniprogramPlugins,
866
+ externalResources: data.externalResources,
867
+ extra: Object.assign(Object.assign({}, restExtra), { name: data.name, author: data.author, description: data.description, lastDependencies }),
868
+ dependencies: data.dependencies,
869
+ // TODO
870
+ // emitEvents: [], { "name": "自定义校验规则", "eventName": "validator" }
871
+ schemaVersion: data.schemaVersion,
872
+ };
873
+ return processed;
1209
874
  }
1210
875
  exports.deserializePlatformApp = deserializePlatformApp;
1211
876
  /**
@@ -1213,75 +878,45 @@ exports.deserializePlatformApp = deserializePlatformApp;
1213
878
  * [formily] to [CALS]
1214
879
  */
1215
880
  function serializeRuntimePage(ctx, page) {
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
- );
881
+ var _a, _b, _c, _d, _e, _f;
882
+ const pageCtx = Object.assign(Object.assign({}, ctx), { dependenciesMap: processDependenciesMap(ctx.dependencies || []), page: { id: page.id } });
883
+ let processedPage = {
884
+ id: page.id,
885
+ type: 'PAGE',
886
+ component: 'Page',
887
+ attributes: (_a = serializeAttributesWithExtra(pageCtx, 'page', (0, runtime_1.readDynamicData)(page))) === null || _a === void 0 ? void 0 : _a.data,
888
+ items: (0, runtime_1.getValidValue)(Object.keys(((_b = page.componentSchemaJson) === null || _b === void 0 ? void 0 : _b.properties) || {}).map((id) => {
889
+ var _a;
890
+ return serializeRuntimeComponent(pageCtx, Object.assign({ id }, (_a = page.componentSchemaJson) === null || _a === void 0 ? void 0 : _a.properties[id]));
891
+ })),
892
+ resources: (_c = page === null || page === void 0 ? void 0 : page.codeModules) === null || _c === void 0 ? void 0 : _c.map((item) => serializeCodeSource(pageCtx, item)),
893
+ dataset: page === null || page === void 0 ? void 0 : page.dataset,
894
+ 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))),
895
+ listeners: (0, runtime_1.getValidValue)((0, runtime_1.readListeners)(page.listenerInstances || []).map((item) => {
896
+ return serializeListener(pageCtx, item);
897
+ })),
898
+ extra: {
899
+ commonStyle: (0, runtime_1.getValidValue)((0, style_1.removeInvalidStyleFormValue)(page.style)),
900
+ styleBindPath: (0, runtime_1.getValidValue)(page.styleBindPath),
901
+ xIndex: page.xIndex,
902
+ children: (0, runtime_1.getValidValue)((_f = page.children) === null || _f === void 0 ? void 0 : _f.map((child) => serializeRuntimePage(ctx, child))),
1241
903
  },
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;
904
+ };
905
+ if ((0, common_2.isValidStyleBind)(page.styleBind) && (0, runtime_1.getValidValue)(page.styleBind)) {
906
+ page[':style'] = serializeValue({
907
+ ctx: pageCtx,
908
+ key: 'styleBind',
909
+ dynamicValue: page.styleBind,
910
+ }).value;
911
+ }
912
+ if ((0, common_2.isValidClassNameListBind)(page.classListBind) && (0, runtime_1.getValidValue)(page.classListBind)) {
913
+ page[':class'] = serializeValue({
914
+ ctx: pageCtx,
915
+ key: 'classListBind',
916
+ dynamicValue: page.classListBind,
917
+ });
918
+ }
919
+ return processedPage;
1285
920
  }
1286
921
  exports.serializeRuntimePage = serializeRuntimePage;
1287
922
  // /**
@@ -1297,112 +932,78 @@ exports.serializeRuntimePage = serializeRuntimePage;
1297
932
  * [formily] to [CALS]
1298
933
  */
1299
934
  function serializeRuntimeComponent(ctx, component) {
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 || []);
935
+ var _a, _b, _c;
936
+ if (!component.id) {
937
+ component.id = component.key;
1319
938
  }
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
- }
939
+ let processed = {
940
+ id: component.id,
941
+ type: undefined,
942
+ component: '',
943
+ label: (0, runtime_1.getValidValue)(component.label),
944
+ };
945
+ let props = component['x-props'];
946
+ const { dependencies = [] } = ctx;
947
+ if (props) {
948
+ const [moduleName, name = ''] = props.sourceKey.split(':');
949
+ const componentCtx = Object.assign(Object.assign({}, ctx), { component: { id: component.id, module: moduleName, component: name } });
950
+ if (componentCtx.dependencies && !componentCtx.dependenciesMap) {
951
+ componentCtx.dependenciesMap = processDependenciesMap(componentCtx.dependencies || []);
952
+ }
953
+ const excludeKeys = (props.dataTypes || [])
954
+ .filter((dataType) => dataType.type !== 'slot')
955
+ .map((dataType) => dataType.propertyPath);
956
+ let properties = component.properties || {};
957
+ const { data: attributes = {}, extra: attributeExtraData = {} } = serializeAttributesWithExtra(componentCtx, 'page', (0, runtime_1.getValidValue)((0, runtime_1.readDynamicData)(props)) || {}) || {};
958
+ let styleBindData = null;
959
+ let classListBindData = null;
960
+ if ((_a = props === null || props === void 0 ? void 0 : props.styleBind) === null || _a === void 0 ? void 0 : _a.bindDataPath) {
961
+ styleBindData = serializeValue({
962
+ ctx: componentCtx,
963
+ key: 'styleBind',
964
+ dynamicValue: {
965
+ type: props.styleBind.type,
966
+ value: props.styleBind.bindDataPath,
967
+ extra: props.styleBind.extra,
968
+ },
969
+ });
970
+ if (styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.extra) {
971
+ attributeExtraData.style = styleBindData === null || styleBindData === void 0 ? void 0 : styleBindData.extra;
972
+ }
973
+ }
974
+ if ((0, common_2.isValidClassNameListBind)(props.classNameListBind)) {
975
+ classListBindData = serializeValue({
976
+ ctx: componentCtx,
977
+ key: 'classListBind',
978
+ dynamicValue: (0, runtime_1.getValidValue)({
979
+ type: props.classNameListBind.type,
980
+ value: props.classNameListBind.bindDataPath,
981
+ }),
982
+ });
983
+ if (classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.extra) {
984
+ attributeExtraData.class = classListBindData === null || classListBindData === void 0 ? void 0 : classListBindData.extra;
985
+ }
986
+ }
987
+ 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)
988
+ .filter((key) => !excludeKeys.includes(key))
989
+ .sort((a, b) => properties[a]['x-index'] - properties[b]['x-index'])
990
+ .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 */) => {
991
+ return serializeListener(componentCtx, listener);
992
+ }), 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: {
993
+ commonStyle: (0, runtime_1.getValidValue)((0, style_1.removeInvalidStyleFormValue)(props.commonStyle)),
994
+ xIndex: (0, runtime_1.getValidValue)(component['x-index']),
995
+ styleBindPath: (0, runtime_1.getValidValue)(props.styleBindPath),
996
+ staticResourceAttribute: (0, runtime_1.getValidValue)(props.staticResourceAttribute),
997
+ attributeExtraData: (0, common_2.isEmptyObj)(attributeExtraData) ? undefined : attributeExtraData,
998
+ } });
1349
999
  }
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
- }
1000
+ else {
1001
+ let items = Object.keys(component.properties || {})
1002
+ .sort((a, b) => component.properties[a]['x-index'] - component.properties[b]['x-index'])
1003
+ .map((key) => serializeRuntimeComponent(ctx, Object.assign({ id: key }, component.properties[key])));
1004
+ processed = Object.assign(Object.assign({}, processed), { items: (0, runtime_1.getValidValue)(items) });
1363
1005
  }
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;
1006
+ return processed;
1406
1007
  }
1407
1008
  exports.serializeRuntimeComponent = serializeRuntimeComponent;
1408
1009
  /**
@@ -1411,126 +1012,93 @@ exports.serializeRuntimeComponent = serializeRuntimeComponent;
1411
1012
  * To be continue, currently support listener
1412
1013
  */
1413
1014
  function deserializeRuntimeComponent(ctx, component) {
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;
1015
+ const { id, module, component: runtimeComponent, listeners = [] } = component;
1016
+ let listenerInstances = (0, runtime_1.getValidValue)((0, runtime_1.writeListeners)((listeners === null || listeners === void 0 ? void 0 : listeners.map((item) => {
1017
+ return Object.assign({ sourceKey: `${module}:${runtimeComponent}` }, deserializeListener(ctx, item));
1018
+ })) || []));
1019
+ const target = {
1020
+ key: id,
1021
+ type: 'object',
1022
+ properties: {},
1023
+ 'x-component': `${module}:${runtimeComponent}`,
1024
+ 'x-props': {
1025
+ sourceKey: `${module}:${runtimeComponent}`,
1026
+ listenerInstances: listenerInstances || [],
1027
+ },
1028
+ };
1029
+ return target;
1435
1030
  }
1436
1031
  exports.deserializeRuntimeComponent = deserializeRuntimeComponent;
1437
1032
  function processDependenciesMap(dependencies = []) {
1438
- let map = dependencies.reduce((map, componentLib) => {
1439
- let { components = [] } = componentLib;
1440
- for (let item of components) {
1441
- map[item.sourceKey] = item;
1442
- }
1033
+ let map = dependencies.reduce((map, componentLib) => {
1034
+ let { components = [] } = componentLib;
1035
+ for (let item of components) {
1036
+ map[item.sourceKey] = item;
1037
+ }
1038
+ return map;
1039
+ }, {});
1443
1040
  return map;
1444
- }, {});
1445
- return map;
1446
1041
  }
1447
1042
  function deserializeComponentLibraryMeta(meta) {
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
- });
1043
+ let { components = {}, actions = {}, styles = [], dependencies = {} } = meta, restLibraryMeta = __rest(meta, ["components", "actions", "styles", "dependencies"]);
1044
+ let processedComponents = {};
1045
+ for (const componentName in components) {
1046
+ let component = components[componentName];
1047
+ let _a = (component.meta || {}), { title, description, category, icon, extra = {} } = _a, restComponentMeta = __rest(_a, ["title", "description", "category", "icon", "extra"]);
1048
+ processedComponents[componentName] = Object.assign(Object.assign({ title: title || component.name || componentName, desc: description || '', category: category || '', thumbnail: icon }, extra), restComponentMeta);
1049
+ }
1050
+ return Object.assign(Object.assign({}, restLibraryMeta), { styles,
1051
+ dependencies, components: processedComponents, actions });
1475
1052
  }
1476
1053
  exports.deserializeComponentLibraryMeta = deserializeComponentLibraryMeta;
1477
1054
  function processRuntimeCodeResources(ctx, resources /* : IWeappCode[]*/ = [], scope) {
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
- });
1055
+ const { id } = ctx;
1056
+ const fileTypes = [common_1.ECodeType.STYLE, common_1.ECodeType.STATE, common_1.ECodeType.LIFECYCLE, common_1.ECodeType.COMPUTEDN];
1057
+ const CODE_TYPE_NAME_MAP = {
1058
+ [common_1.ECodeType.STATE]: common_1.ECodeName.STATE,
1059
+ [common_1.ECodeType.COMPUTEDN]: common_1.ECodeName.COMPUTEDN,
1060
+ [common_1.ECodeType.STYLE]: common_1.ECodeName.STYLE,
1061
+ [common_1.ECodeType.LIFECYCLE]: common_1.ECodeName.LIFECYCLE,
1062
+ };
1063
+ const isComponent = id === '$comp' || scope === 'component';
1064
+ if (id === 'global' || scope === 'app') {
1065
+ fileTypes.push(common_1.ECodeType.THEME);
1514
1066
  }
1515
- });
1516
- return resources.filter((m) => m.name !== common_1.ECodeName.PLACEHOLDER);
1067
+ const EXIST_FILE_TYPE_MAP = {};
1068
+ resources.forEach((mod) => {
1069
+ EXIST_FILE_TYPE_MAP[mod.type] = true;
1070
+ });
1071
+ fileTypes.forEach((type) => {
1072
+ const isHasLowcodeIndex = EXIST_FILE_TYPE_MAP[type];
1073
+ if (!isHasLowcodeIndex) {
1074
+ const name = CODE_TYPE_NAME_MAP[type] || type;
1075
+ resources.unshift({
1076
+ name,
1077
+ type,
1078
+ code: (0, template_1.generateDefaultCode)(ctx, type, isComponent ? 'component' : id === 'global' ? 'app' : 'page'),
1079
+ path: `${id}/${name}`,
1080
+ system: true,
1081
+ });
1082
+ }
1083
+ });
1084
+ return resources.filter((m) => m.name !== common_1.ECodeName.PLACEHOLDER);
1517
1085
  }
1518
1086
  exports.processRuntimeCodeResources = processRuntimeCodeResources;
1519
1087
  /**
1520
1088
  * 解析 cals version 来生成 feature map
1521
1089
  */
1522
1090
  function parseVersion(version = '') {
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;
1091
+ const list = version.split('.');
1092
+ const FEATURE_MAP = {
1093
+ /**
1094
+ * 默认单位为 px,
1095
+ * 然后进行动态转换 为 rem及rpx
1096
+ */
1097
+ defaultDynamicCssUnit: true,
1098
+ };
1099
+ if (list[0] === '4' || version === 'latest') {
1100
+ FEATURE_MAP.defaultDynamicCssUnit = false;
1101
+ }
1102
+ return FEATURE_MAP;
1535
1103
  }
1536
1104
  exports.parseVersion = parseVersion;