@cloudbase/cals 1.0.72-alpha.1 → 1.0.72-alpha.3

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.
@@ -0,0 +1,6 @@
1
+ import { type IPlatformDataset } from '../../../../../types';
2
+ /**
3
+ * 合并 dataset (如遇同名,保留前者)
4
+ */
5
+ export declare function mergeDataset(first?: IPlatformDataset, second?: IPlatformDataset): IPlatformDataset;
6
+ //# sourceMappingURL=merge-dataset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-dataset.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/merge-dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,GAAE,gBAAqB,EAAE,MAAM,GAAE,gBAAqB,oBAYvF"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeDataset = void 0;
4
+ /**
5
+ * 合并 dataset (如遇同名,保留前者)
6
+ */
7
+ function mergeDataset(first = {}, second = {}) {
8
+ const dataset = {};
9
+ for (const key of ['state', 'params', 'query']) {
10
+ const value = Object.assign(Object.assign({}, second[key]), first[key]);
11
+ if (Object.keys(value).length) {
12
+ dataset[key] = value;
13
+ }
14
+ }
15
+ return Object.keys(dataset).length ? dataset : undefined;
16
+ }
17
+ exports.mergeDataset = mergeDataset;
@@ -0,0 +1,6 @@
1
+ import { type IPlatformListener } from '../../../../../types';
2
+ /**
3
+ * 合并监听器 (如遇同名,保留前者)
4
+ */
5
+ export declare function mergeListeners(first?: IPlatformListener[], second?: IPlatformListener[]): IPlatformListener[];
6
+ //# sourceMappingURL=merge-listeners.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-listeners.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/merge-listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,GAAE,iBAAiB,EAAO,EAAE,MAAM,GAAE,iBAAiB,EAAO,uBAQ/F"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeListeners = void 0;
4
+ /**
5
+ * 合并监听器 (如遇同名,保留前者)
6
+ */
7
+ function mergeListeners(first = [], second = []) {
8
+ const listenerMap = new Map();
9
+ for (const listener of [...second, ...first]) {
10
+ listenerMap.set(listener.id, listener);
11
+ }
12
+ return listenerMap.size > 0 ? [...listenerMap.values()] : undefined;
13
+ }
14
+ exports.mergeListeners = mergeListeners;
@@ -0,0 +1,6 @@
1
+ import { type ICodeResource } from '../../../../../types';
2
+ /**
3
+ * 合并代码资源 (如遇同名,保留前者)
4
+ */
5
+ export declare function mergeResources(first?: ICodeResource[], second?: ICodeResource[]): ICodeResource[];
6
+ //# sourceMappingURL=merge-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-resources.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/merge-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErE;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,GAAE,aAAa,EAAO,EAAE,MAAM,GAAE,aAAa,EAAO,mBAwBvF"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeResources = void 0;
4
+ const types_1 = require("../../../../../types");
5
+ /**
6
+ * 合并代码资源 (如遇同名,保留前者)
7
+ */
8
+ function mergeResources(first = [], second = []) {
9
+ const resourceMap = new Map();
10
+ for (const resource of first) {
11
+ const { codeType, name } = resource;
12
+ const key = `${codeType}/${name}`;
13
+ resourceMap.set(key, resource);
14
+ }
15
+ for (const resource of second) {
16
+ const { codeType, name } = resource;
17
+ const key = `${codeType}/${name}`;
18
+ if (!resourceMap.has(key)) {
19
+ resourceMap.set(key, resource);
20
+ }
21
+ else if (codeType === types_1.ECodeType.STYLE) {
22
+ // 合并样式内容
23
+ const existResource = resourceMap.get(key);
24
+ existResource.code = [existResource.code, resource.code].join('\n');
25
+ }
26
+ }
27
+ return resourceMap.size > 0 ? [...resourceMap.values()] : undefined;
28
+ }
29
+ exports.mergeResources = mergeResources;
@@ -1 +1 @@
1
- {"version":3,"file":"remap-component-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/remap-component-ids.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAK1D,aAAK,kBAAkB,GAAG,MAAM,CAAC;AACjC,aAAK,WAAW,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,QAAQ,EAAE,UAAU,CAAC;IAErB,wCAAwC;IACxC,QAAQ,EAAE,UAAU,CAAC;CACtB;AAED,qBAAa,UAAU;;;IAMrB,GAAG,CAAC,GAAG,IAAI,OAAA;IAIX,GAAG,CAAC,SAAS,EAAE,kBAAkB;IAGjC,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,EAAE,EAAE,WAAW;IAOlD,IAAI,IAAI,WAEP;CACF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,cAAc,EAAE,eAAe;;EAmClG;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE;IAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAAE,SAAS,EAAE,kBAAkB,OAoD9G"}
1
+ {"version":3,"file":"remap-component-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/remap-component-ids.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAK1D,aAAK,kBAAkB,GAAG,MAAM,CAAC;AACjC,aAAK,WAAW,GAAG,MAAM,CAAC;AAE1B,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,QAAQ,EAAE,UAAU,CAAC;IAErB,wCAAwC;IACxC,QAAQ,EAAE,UAAU,CAAC;CACtB;AAED,qBAAa,UAAU;;;IAMrB,GAAG,CAAC,GAAG,IAAI,OAAA;IAIX,GAAG,CAAC,SAAS,EAAE,kBAAkB;IAGjC,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,EAAE,EAAE,WAAW;IAOlD,IAAI,IAAI,WAEP;CACF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,cAAc,EAAE,eAAe;;EAkClG;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE;IAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAAE,SAAS,EAAE,kBAAkB,OAoD9G"}
@@ -56,7 +56,6 @@ function remapComponentIds(components, visitedContext) {
56
56
  return item;
57
57
  }
58
58
  const namespace = (0, get_component_namespace_1.getComponentNamespace)(item.component);
59
- console.log('>>>>>untilNow', item.id);
60
59
  if (untilNow.has(item.id)) {
61
60
  let nextCodeId = `${namespace}1`;
62
61
  let seq = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"renew-id-in-code.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/renew-id-in-code.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAS9E"}
1
+ {"version":3,"file":"renew-id-in-code.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/renew-id-in-code.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAE9E"}
@@ -1,19 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renewIdInCode = void 0;
4
- const resolve_new_id_1 = require("./resolve-new-id");
4
+ const renew_id_in_expr_1 = require("./renew-id-in-expr");
5
5
  /**
6
6
  * 按需将代码中引用的组件旧 ID 更新为新 ID
7
7
  * @param expr 表达式
8
8
  * @param componentIdMap 映射: 组件原始 ID => 新生成 ID
9
9
  */
10
10
  function renewIdInCode(code, componentIdMap) {
11
- return code.replace(/(\$w\.)(\w+)/g, (match, p1, p2) => {
12
- const newId = (0, resolve_new_id_1.resolveNewId)(p2, componentIdMap);
13
- if (newId) {
14
- return `${p1}${newId}`;
15
- }
16
- return match;
17
- });
11
+ return (0, renew_id_in_expr_1.renewIdWithRegexp)(code, componentIdMap);
18
12
  }
19
13
  exports.renewIdInCode = renewIdInCode;
@@ -3,5 +3,6 @@
3
3
  * @param expr 表达式
4
4
  * @param componentIdMap 映射: 组件原始 ID => 新生成 ID
5
5
  */
6
- export declare function renewIdInExpr(expr: string, componentIdMap: Map<string, string>): any;
6
+ export declare function renewIdInExpr(expr: string, componentIdMap: Map<string, string>): string;
7
+ export declare function renewIdWithRegexp(str: string, componentIdMap: Map<string, string>): string;
7
8
  //# sourceMappingURL=renew-id-in-expr.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renew-id-in-expr.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/renew-id-in-expr.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAwC9E"}
1
+ {"version":3,"file":"renew-id-in-expr.d.ts","sourceRoot":"","sources":["../../../../../../src/parser/cals/utils/block/helpers/renew-id-in-expr.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UA0C9E;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAejF"}
@@ -1,30 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.renewIdInExpr = void 0;
27
- const Babel = __importStar(require("@babel/standalone"));
3
+ exports.renewIdWithRegexp = exports.renewIdInExpr = void 0;
4
+ // import * as Babel from '@babel/standalone';
28
5
  const resolve_new_id_1 = require("./resolve-new-id");
29
6
  /**
30
7
  * 按需将表达式中引用的组件旧 ID 更新为新 ID
@@ -35,35 +12,52 @@ function renewIdInExpr(expr, componentIdMap) {
35
12
  if (typeof expr !== 'string' || expr.length === 0 || !expr.includes('$w')) {
36
13
  return expr;
37
14
  }
38
- const output = Babel.transform(expr, {
39
- plugins: [
40
- ({ types: t }) => {
41
- return {
42
- visitor: {
43
- MemberExpression({ node }) {
44
- const { object, property } = node;
45
- if (object.name === '$w') {
46
- const newId = (0, resolve_new_id_1.resolveNewId)(property.name || '', componentIdMap);
47
- if (newId) {
48
- node.property = t.identifier(newId);
49
- }
50
- }
51
- },
52
- },
53
- };
54
- },
55
- ],
56
- });
57
- let code = output.code.replace(/;\s$/, '');
58
- // code wrapped in `()`
59
- // TODO: 是否有必要?
60
- {
61
- const match = code.match(/^\((.*?)\)$/);
62
- if (match === null || match === void 0 ? void 0 : match[1]) {
63
- // eslint-disable-next-line prefer-destructuring
64
- code = match[1];
65
- }
66
- }
67
- return code;
15
+ return renewIdWithRegexp(expr, componentIdMap);
16
+ // const output = Babel.transform(expr, {
17
+ // plugins: [
18
+ // ({ types: t }) => {
19
+ // return {
20
+ // visitor: {
21
+ // MemberExpression({ node }) {
22
+ // const { object, property } = node;
23
+ // if (object.name === '$w') {
24
+ // const newId = resolveNewId(property.name || '', componentIdMap);
25
+ // if (newId) {
26
+ // node.property = t.identifier(newId);
27
+ // }
28
+ // }
29
+ // },
30
+ // },
31
+ // };
32
+ // },
33
+ // ],
34
+ // });
35
+ // let code = output.code.replace(/;\s$/, '');
36
+ // // code wrapped in `()`
37
+ // // TODO: 是否有必要?
38
+ // {
39
+ // const match = code.match(/^\((.*?)\)$/);
40
+ // if (match?.[1]) {
41
+ // // eslint-disable-next-line prefer-destructuring
42
+ // code = match[1];
43
+ // }
44
+ // }
45
+ // return code;
68
46
  }
69
47
  exports.renewIdInExpr = renewIdInExpr;
48
+ function renewIdWithRegexp(str, componentIdMap) {
49
+ return str.replace(/(\$w\.)(\w+)/g, (match, p1, p2, offset) => {
50
+ const before = str[offset - 1];
51
+ const newId = (0, resolve_new_id_1.resolveNewId)(p2, componentIdMap);
52
+ /**
53
+ * 前向匹配
54
+ * 前一个字符存在,且前一个字符费变量安全字 a-z、A-Z、0-9、_、$起始
55
+ * 且前一字符非 . 表示成员访问
56
+ */
57
+ if (newId && !(before && /[a-zA-Z0-9_$.]/.test(before))) {
58
+ return `${p1}${newId}`;
59
+ }
60
+ return match;
61
+ });
62
+ }
63
+ exports.renewIdWithRegexp = renewIdWithRegexp;
@@ -1,4 +1,4 @@
1
- import { IPlatformComponent } from '../../../../types';
1
+ import { IPlatformApp, IPlatformComponent } from '../../../../types';
2
2
  import { IVisitedContext } from './helpers/remap-component-ids';
3
3
  export { renewIdInResource } from './helpers/renew-id-in-resource';
4
4
  export { remapComponentIds, refreshComponentIds } from './helpers/remap-component-ids';
@@ -17,5 +17,13 @@ interface IParseContext {
17
17
  export declare function parseComponentCals(ctx: IParseContext, cals: IPlatformComponent): IParseContext;
18
18
  export declare function regenBlockTemplateComponents(ctx: {
19
19
  visiting: IVisitedContext;
20
+ componentIdMap?: Map<string, string>;
20
21
  }, components: IPlatformComponent[]): IPlatformComponent[];
22
+ interface IMergeCalsMeta {
23
+ cals: IPlatformApp;
24
+ targetOptions?: {
25
+ mode: 'before' | 'after' | 'head' | 'tail';
26
+ };
27
+ }
28
+ export declare function mergeCals(list: IMergeCalsMeta[]): IPlatformApp;
21
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/parser/cals/utils/block/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqB,MAAM,mBAAmB,CAAC;AAI1E,OAAO,EAAE,eAAe,EAA0C,MAAM,+BAA+B,CAAC;AAExG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,UAAU,aAAa;IACrB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AC,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACtC;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,kBAAkB,GAAG,aAAa,CAyD9F;AA+GD,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE;IAAE,QAAQ,EAAE,eAAe,CAAC;IAAC,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EACxE,UAAU,EAAE,kBAAkB,EAAE,GAC/B,kBAAkB,EAAE,CAmBtB;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,YAAY,CAAC;IACnB,aAAa,CAAC,EAAE;QACd,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;KAC5C,CAAC;CACH;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,EAAE,gBA4E/C"}
@@ -3,13 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.regenBlockTemplateComponents = exports.parseComponentCals = exports.VisitedMap = exports.refreshComponentIds = exports.remapComponentIds = exports.renewIdInResource = void 0;
6
+ exports.mergeCals = exports.regenBlockTemplateComponents = exports.parseComponentCals = exports.VisitedMap = exports.refreshComponentIds = exports.remapComponentIds = exports.renewIdInResource = void 0;
7
7
  const get_1 = __importDefault(require("lodash/get"));
8
8
  const set_1 = __importDefault(require("lodash/set"));
9
9
  const expression_1 = require("../../../expression");
10
10
  const remap_component_ids_1 = require("./helpers/remap-component-ids");
11
- var renew_id_in_resource_1 = require("./helpers/renew-id-in-resource");
12
- Object.defineProperty(exports, "renewIdInResource", { enumerable: true, get: function () { return renew_id_in_resource_1.renewIdInResource; } });
11
+ const common_1 = require("../common");
12
+ const get_component_namespace_1 = require("./helpers/get-component-namespace");
13
+ const renew_id_in_resource_1 = require("./helpers/renew-id-in-resource");
14
+ const merge_resources_1 = require("./helpers/merge-resources");
15
+ const merge_dataset_1 = require("./helpers/merge-dataset");
16
+ const merge_listeners_1 = require("./helpers/merge-listeners");
17
+ var renew_id_in_resource_2 = require("./helpers/renew-id-in-resource");
18
+ Object.defineProperty(exports, "renewIdInResource", { enumerable: true, get: function () { return renew_id_in_resource_2.renewIdInResource; } });
13
19
  var remap_component_ids_2 = require("./helpers/remap-component-ids");
14
20
  Object.defineProperty(exports, "remapComponentIds", { enumerable: true, get: function () { return remap_component_ids_2.remapComponentIds; } });
15
21
  Object.defineProperty(exports, "refreshComponentIds", { enumerable: true, get: function () { return remap_component_ids_2.refreshComponentIds; } });
@@ -158,7 +164,10 @@ function parseValueCals(ctx, value) {
158
164
  }
159
165
  }
160
166
  function regenBlockTemplateComponents(ctx, components) {
161
- const { componentIdMap } = (0, remap_component_ids_1.remapComponentIds)(components, ctx.visiting);
167
+ let { componentIdMap } = ctx;
168
+ if (!componentIdMap) {
169
+ componentIdMap = (0, remap_component_ids_1.remapComponentIds)(components, ctx.visiting).componentIdMap;
170
+ }
162
171
  return components.map((component) => {
163
172
  const processed = (0, remap_component_ids_1.refreshComponentIds)({ componentIdMap }, component);
164
173
  // todo: 需要处理extra.dataForm
@@ -166,3 +175,56 @@ function regenBlockTemplateComponents(ctx, components) {
166
175
  });
167
176
  }
168
177
  exports.regenBlockTemplateComponents = regenBlockTemplateComponents;
178
+ function mergeCals(list) {
179
+ var _a, _b;
180
+ const visitedContext = {
181
+ existing: new remap_component_ids_1.VisitedMap(),
182
+ untilNow: new remap_component_ids_1.VisitedMap(),
183
+ };
184
+ // 不修改原始数据
185
+ const clonedCalsList = JSON.parse(JSON.stringify(list));
186
+ // 初始化 `visitedContext.existing` 数据
187
+ for (const { cals } of clonedCalsList) {
188
+ if (cals.items.length > 1) {
189
+ throw new Error('不支持对多页面的 CALS 进行合并');
190
+ }
191
+ // 区块只有一个页面
192
+ const page = cals.items[0];
193
+ page.items = (0, common_1.walkThroughComponents)(page.items, (item) => {
194
+ var _a;
195
+ (_a = item.extra) === null || _a === void 0 ? true : delete _a.xIndex;
196
+ if (!item.component || typeof item.component !== 'string') {
197
+ return;
198
+ }
199
+ const namespace = (0, get_component_namespace_1.getComponentNamespace)(item.component);
200
+ visitedContext.existing.get(namespace).add(namespace, item.id);
201
+ return item;
202
+ });
203
+ }
204
+ /**
205
+ * 根据 `visitedContext` 收集的信息,按需更新组件 ID
206
+ * 组件id是页面隔离的,因此限制约定,只处理 0 号页面
207
+ */
208
+ for (const { cals } of clonedCalsList) {
209
+ const page = cals.items[0];
210
+ const { componentIdMap } = (0, remap_component_ids_1.remapComponentIds)(page.items, visitedContext);
211
+ page.items = regenBlockTemplateComponents({ visiting: visitedContext, componentIdMap }, page.items);
212
+ // 应用资源更新 ID
213
+ cals.resources = (_a = cals.resources) === null || _a === void 0 ? void 0 : _a.map((resource) => (0, renew_id_in_resource_1.renewIdInResource)(resource, componentIdMap));
214
+ // 页面资源更新 ID
215
+ page.resources = (_b = page.resources) === null || _b === void 0 ? void 0 : _b.map((resource) => (0, renew_id_in_resource_1.renewIdInResource)(resource, componentIdMap));
216
+ }
217
+ const mergedCals = clonedCalsList
218
+ .map((meta) => meta.cals)
219
+ .reduce((first, second) => {
220
+ const firstPage = first.items[0];
221
+ const secondPage = second.items[0];
222
+ const mergedPage = Object.assign(Object.assign(Object.assign({}, secondPage), firstPage), { items: [...firstPage.items, ...secondPage.items], resources: (0, merge_resources_1.mergeResources)(firstPage.resources, secondPage.resources) || [], dataset: (0, merge_dataset_1.mergeDataset)(firstPage.dataset, secondPage.dataset) || {}, listeners: (0, merge_listeners_1.mergeListeners)(firstPage.listeners, secondPage.listeners) });
223
+ if (!mergedPage.listeners) {
224
+ delete mergedPage.listeners;
225
+ }
226
+ return Object.assign(Object.assign(Object.assign({}, second), first), { items: [mergedPage], resources: (0, merge_resources_1.mergeResources)(first.resources, second.resources) || [], dataset: (0, merge_dataset_1.mergeDataset)(first.dataset, second.dataset) || {} });
227
+ });
228
+ return mergedCals;
229
+ }
230
+ exports.mergeCals = mergeCals;
@@ -2,7 +2,7 @@ export * from './cals/index';
2
2
  export { upgrageToVersion2 } from './cals/utils/version';
3
3
  export { processComponentModule } from './cals/utils/spinoff';
4
4
  export { calsToCode, codeToCals, type ICodeItem, checkForConflicts, autoResolveConflicts, findAllConflicts, } from './cals/utils/code';
5
- export { parseComponentCals, regenBlockTemplateComponents, renewIdInResource, VisitedMap } from './cals/utils/block';
5
+ export { parseComponentCals, regenBlockTemplateComponents, renewIdInResource, VisitedMap, remapComponentIds, refreshComponentIds, mergeCals, } from './cals/utils/block';
6
6
  export { ActionType, type IDataBind, PropBindType } from './expression/index';
7
7
  export { processCommonStyle2CSSProperties, processCSSProperties2Rem, processCSSPropertiesUnit, } from './cals/utils/style';
8
8
  export { getUsedResources, getNavUsedStaticResource, _simpleGetUsedResourceOfComponent, } from './cals/utils/getUsedResources';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,UAAU,EACV,UAAU,EACV,KAAK,SAAS,EACd,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrH,OAAO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OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.DYNAMIC_KEY_REG = exports.walkThroughComponents = exports.Dependencies = exports.PostcssRpx2Calc = exports.getUsedReference = exports._simpleGetUsedResourceOfComponent = exports.getNavUsedStaticResource = exports.getUsedResources = exports.processCSSPropertiesUnit = exports.processCSSProperties2Rem = exports.processCommonStyle2CSSProperties = exports.PropBindType = exports.ActionType = exports.VisitedMap = exports.renewIdInResource = exports.regenBlockTemplateComponents = exports.parseComponentCals = exports.findAllConflicts = exports.autoResolveConflicts = exports.checkForConflicts = exports.codeToCals = exports.calsToCode = exports.processComponentModule = exports.upgrageToVersion2 = void 0;
20
+ exports.DYNAMIC_KEY_REG = exports.walkThroughComponents = exports.Dependencies = exports.PostcssRpx2Calc = exports.getUsedReference = exports._simpleGetUsedResourceOfComponent = exports.getNavUsedStaticResource = exports.getUsedResources = exports.processCSSPropertiesUnit = exports.processCSSProperties2Rem = exports.processCommonStyle2CSSProperties = exports.PropBindType = exports.ActionType = exports.mergeCals = exports.refreshComponentIds = exports.remapComponentIds = exports.VisitedMap = exports.renewIdInResource = exports.regenBlockTemplateComponents = exports.parseComponentCals = exports.findAllConflicts = exports.autoResolveConflicts = exports.checkForConflicts = exports.codeToCals = exports.calsToCode = exports.processComponentModule = exports.upgrageToVersion2 = void 0;
21
21
  __exportStar(require("./cals/index"), exports);
22
22
  var version_1 = require("./cals/utils/version");
23
23
  Object.defineProperty(exports, "upgrageToVersion2", { enumerable: true, get: function () { return version_1.upgrageToVersion2; } });
@@ -34,6 +34,9 @@ Object.defineProperty(exports, "parseComponentCals", { enumerable: true, get: fu
34
34
  Object.defineProperty(exports, "regenBlockTemplateComponents", { enumerable: true, get: function () { return block_1.regenBlockTemplateComponents; } });
35
35
  Object.defineProperty(exports, "renewIdInResource", { enumerable: true, get: function () { return block_1.renewIdInResource; } });
36
36
  Object.defineProperty(exports, "VisitedMap", { enumerable: true, get: function () { return block_1.VisitedMap; } });
37
+ Object.defineProperty(exports, "remapComponentIds", { enumerable: true, get: function () { return block_1.remapComponentIds; } });
38
+ Object.defineProperty(exports, "refreshComponentIds", { enumerable: true, get: function () { return block_1.refreshComponentIds; } });
39
+ Object.defineProperty(exports, "mergeCals", { enumerable: true, get: function () { return block_1.mergeCals; } });
37
40
  var index_1 = require("./expression/index");
38
41
  Object.defineProperty(exports, "ActionType", { enumerable: true, get: function () { return index_1.ActionType; } });
39
42
  Object.defineProperty(exports, "PropBindType", { enumerable: true, get: function () { return index_1.PropBindType; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "1.0.72-alpha.1",
3
+ "version": "1.0.72-alpha.3",
4
4
  "description": "Common application specifications",
5
5
  "main": "lib/utils/index.js",
6
6
  "source": "src/utils/index.ts",