@cloudbase/cals 1.0.28 → 1.0.29-alpha.1

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,6 +1,5 @@
1
- import { IPlatformListener, IPlatformDataset } from '../../types/platform/common';
2
- import { IAttributes, IPlatformApp, IPageComponent, IPlatformComponent, IDataSourceVariable, IDataVarMethod, // 勿删,为了生成d.ts
3
- IPlatformDataSource, IDependencies, LCDS } from '../../types';
1
+ import { IPlatformDataset, IPlatformListener } from '../../types/platform/common';
2
+ import { IAttributes, IDataSourceVariable, IDependencies, IPageComponent, IPlatformApp, IPlatformComponent, LCDS } from '../../types';
4
3
  import { IDynamicValue, PropBindType } from '../expression';
5
4
  import { IEventFlow } from '../../types/platform/eventFlow';
6
5
  export { getUsedComps } from './utils/common';
@@ -82,6 +81,12 @@ export declare function deserializeAttributes(ctx: IDeserializeContext, attribut
82
81
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
83
82
  */
84
83
  export declare function serializeDataset(ctx: ISerializeContext, dataset: any): any;
84
+ /**
85
+ * 反序列化布局模板
86
+ * @param ctx
87
+ * @param templates
88
+ */
89
+ export declare function deserializeTemplates(ctx: IDeserializeContext, templates: any): {};
85
90
  /**
86
91
  * 将dataset({state: {}, params: {}})从 cals 结构转换为weapp结构
87
92
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
@@ -94,8 +99,8 @@ export declare function deserializeDataVariables(_: any, data: IDataSourceVariab
94
99
  varType: "datasource";
95
100
  dataType?: "record-collection" | "new-record" | "single-record" | "single-record-edit";
96
101
  dataSourceName: string;
97
- initMethod?: IDataVarMethod;
98
- updateMethod?: IDataVarMethod;
102
+ initMethod?: import("../../types").IDataVarMethod;
103
+ updateMethod?: import("../../types").IDataVarMethod;
99
104
  };
100
105
  export declare function serializeComponent(ctx: ISerializeContext & ({
101
106
  page: Required<ISerializeContext>['page'];
@@ -137,6 +142,26 @@ export declare function deserializeComponent(ctx: IDeserializeContext, component
137
142
  [key: string]: object;
138
143
  };
139
144
  export declare function serializePage(ctx: Pick<ISerializeContext, 'app' | 'dependencies' | 'dependenciesMap'>, page: any): IPageComponent;
145
+ /**
146
+ * 序列化布局
147
+ */
148
+ export declare function serializeLayouts(ctx: ISerializeContext, layouts?: {
149
+ [key: string]: {
150
+ data?: string;
151
+ name?: string;
152
+ label?: string;
153
+ };
154
+ }): {
155
+ name: string;
156
+ label: string;
157
+ data: {};
158
+ id: string;
159
+ items?: IPlatformComponent[];
160
+ dataset?: IPlatformDataset;
161
+ module?: string;
162
+ ':class'?: string;
163
+ ':style'?: string;
164
+ }[];
140
165
  export declare function deserializePage(ctx: {
141
166
  dependencies: IDeserializeContext['dependencies'];
142
167
  homePageId: string;
@@ -149,8 +174,8 @@ export declare function deserializePage(ctx: {
149
174
  varType: "datasource";
150
175
  dataType?: "record-collection" | "new-record" | "single-record" | "single-record-edit";
151
176
  dataSourceName: string;
152
- initMethod?: IDataVarMethod;
153
- updateMethod?: IDataVarMethod;
177
+ initMethod?: import("../../types").IDataVarMethod;
178
+ updateMethod?: import("../../types").IDataVarMethod;
154
179
  }[];
155
180
  };
156
181
  data: {
@@ -209,6 +234,7 @@ export declare function deserializePage(ctx: {
209
234
  * [WeApps协议] to [CALS协议]
210
235
  *
211
236
  * @param data
237
+ * @param optsions
212
238
  */
213
239
  export declare function serializePlatformApp(data: any, optsions: {
214
240
  dependencies: object[];
@@ -238,8 +264,8 @@ export declare function deserializePlatformApp(data: IPlatformApp, optsions: {
238
264
  varType: "datasource";
239
265
  dataType?: "record-collection" | "new-record" | "single-record" | "single-record-edit";
240
266
  dataSourceName: string;
241
- initMethod?: IDataVarMethod;
242
- updateMethod?: IDataVarMethod;
267
+ initMethod?: import("../../types").IDataVarMethod;
268
+ updateMethod?: import("../../types").IDataVarMethod;
243
269
  }[];
244
270
  };
245
271
  data: {
@@ -301,7 +327,7 @@ export declare function deserializePlatformApp(data: IPlatformApp, optsions: {
301
327
  path?: string;
302
328
  name: string;
303
329
  }[];
304
- datasources: IPlatformDataSource[];
330
+ datasources: import("../../types").IPlatformDataSource[];
305
331
  dataset: any;
306
332
  vars: {
307
333
  data: {
@@ -310,8 +336,8 @@ export declare function deserializePlatformApp(data: IPlatformApp, optsions: {
310
336
  varType: "datasource";
311
337
  dataType?: "record-collection" | "new-record" | "single-record" | "single-record-edit";
312
338
  dataSourceName: string;
313
- initMethod?: IDataVarMethod;
314
- updateMethod?: IDataVarMethod;
339
+ initMethod?: import("../../types").IDataVarMethod;
340
+ updateMethod?: import("../../types").IDataVarMethod;
315
341
  }[];
316
342
  };
317
343
  compHiddenConfig: {
@@ -356,6 +382,7 @@ export declare function deserializePlatformApp(data: IPlatformApp, optsions: {
356
382
  };
357
383
  dependencies: IDependencies;
358
384
  schemaVersion: string;
385
+ layouts: {};
359
386
  };
360
387
  declare type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
361
388
  export declare function deserializeCompositeComponent(component: ArrayElement<IPlatformApp['templates']>, options: any): {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/parser/cals/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuC,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEvH,OAAO,EACL,WAAW,EACX,YAAY,EAGZ,cAAc,EACd,kBAAkB,EAElB,mBAAmB,EACnB,cAAc,EAAE,cAAc;AAC9B,mBAAmB,EACnB,aAAa,EACb,IAAI,EAEL,MAAM,aAAa,CAAC;AAErB,OAAO,EAAkC,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAgB5F,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,UAAU,mBAAmB;IAC3B,GAAG,C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,EAAE,MAAM,UAWvD;AAED,wBAAgB,+BAA+B,CAAC,SAAS,QAAK;;;;;;;;;;;;;;;;;QA4BtD;;;WAGG;;;;;;;EAcV"}
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.processTemplatesToDependiencies = exports.parseDependenciesVersion = exports.processDependenciesVersionMap = exports.processListeners = exports.parseVersion = exports.processRuntimeCodeResources = exports.deserializeComponentLibraryMeta = exports.deserializeRuntimeComponent = exports.serializeRuntimeComponent = exports.serializeRuntimeDataset = exports.serializeRuntimePage = exports.deserializeCompositeComponent = exports.deserializePlatformApp = exports.serializePlatformApp = exports.deserializePage = exports.serializePage = exports.deserializeComponent = exports.serializeComponent = exports.deserializeDataVariables = exports.normalizeQuery = exports.deserializeDataset = exports.serializeDataset = exports.deserializeAttributes = exports.serializeAttributes = exports.deserializeDynamicMap = exports.serializeDynamicMap = exports.deserializeValue = exports.serializeValue = exports.generateDefaultCode = exports.getUsedComps = void 0;
17
+ exports.processTemplatesToDependiencies = exports.parseDependenciesVersion = exports.processDependenciesVersionMap = exports.processListeners = exports.parseVersion = exports.processRuntimeCodeResources = exports.deserializeComponentLibraryMeta = exports.deserializeRuntimeComponent = exports.serializeRuntimeComponent = exports.serializeRuntimeDataset = exports.serializeRuntimePage = exports.deserializeCompositeComponent = exports.deserializePlatformApp = exports.serializePlatformApp = exports.deserializePage = exports.serializeLayouts = exports.serializePage = exports.deserializeComponent = exports.serializeComponent = exports.deserializeDataVariables = exports.normalizeQuery = exports.deserializeDataset = exports.deserializeTemplates = exports.serializeDataset = exports.deserializeAttributes = exports.serializeAttributes = exports.deserializeDynamicMap = exports.serializeDynamicMap = exports.deserializeValue = exports.serializeValue = exports.generateDefaultCode = exports.getUsedComps = void 0;
18
18
  const get_1 = __importDefault(require("lodash/get"));
19
19
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
20
20
  const unset_1 = __importDefault(require("lodash/unset"));
@@ -130,7 +130,8 @@ function deserializeValue(ctx, key, value, extra) {
130
130
  try {
131
131
  value = value.replace(/\$app\./g, 'app.').replace(/\$for./g, 'forItems.');
132
132
  }
133
- catch (e) { }
133
+ catch (e) {
134
+ }
134
135
  }
135
136
  }
136
137
  return {
@@ -393,6 +394,30 @@ function serializeDataset(ctx, dataset) {
393
394
  return result;
394
395
  }
395
396
  exports.serializeDataset = serializeDataset;
397
+ /**
398
+ * 反序列化布局模板
399
+ * @param ctx
400
+ * @param templates
401
+ */
402
+ function deserializeTemplates(ctx, templates) {
403
+ const layout = {};
404
+ templates.forEach((template) => {
405
+ const { listeners = [] } = processListeners((template === null || template === void 0 ? void 0 : template.listeners) || []);
406
+ layout[template.id] = {
407
+ id: template.id,
408
+ name: template.name,
409
+ label: template.label,
410
+ data: (template === null || template === void 0 ? void 0 : template.data) || {},
411
+ dataset: deserializeDataset(ctx, template.dataset),
412
+ componentInstances: deserializeComponent(ctx, template.items || []),
413
+ listeners: (listeners === null || listeners === void 0 ? void 0 : listeners.map((item) => {
414
+ return deserializeListener(ctx, item);
415
+ })) || [],
416
+ };
417
+ });
418
+ return layout;
419
+ }
420
+ exports.deserializeTemplates = deserializeTemplates;
396
421
  /**
397
422
  * 将dataset({state: {}, params: {}})从 cals 结构转换为weapp结构
398
423
  * 目前仅转换 state 中的 initMethod.params 和 updateMethod.params
@@ -799,6 +824,19 @@ function serializePage(ctx, page) {
799
824
  return processedPage;
800
825
  }
801
826
  exports.serializePage = serializePage;
827
+ /**
828
+ * 序列化布局
829
+ */
830
+ function serializeLayouts(ctx, layouts = {}) {
831
+ return Object.entries(layouts).map(([layoutId, layout]) => {
832
+ var _a;
833
+ const layoutExtraDetail = { name: layout.name, label: layout.label };
834
+ const temp = Object.assign({}, serializePage(ctx, layout));
835
+ const { type, component, attributes, directives, resources, dataVariables, listeners, extra } = temp, rest = __rest(temp, ["type", "component", "attributes", "directives", "resources", "dataVariables", "listeners", "extra"]);
836
+ return Object.assign(Object.assign(Object.assign({}, rest), { data: (_a = layout === null || layout === void 0 ? void 0 : layout.data) !== null && _a !== void 0 ? _a : {} }), layoutExtraDetail);
837
+ });
838
+ }
839
+ exports.serializeLayouts = serializeLayouts;
802
840
  function deserializePage(ctx, page) {
803
841
  var _a, _b, _c, _d, _e;
804
842
  const { homePageId } = ctx, _pageCtx = __rest(ctx, ["homePageId"]);
@@ -833,10 +871,11 @@ function deserializeInstance(ctx, instance, scope = 'page') {
833
871
  * [WeApps协议] to [CALS协议]
834
872
  *
835
873
  * @param data
874
+ * @param optsions
836
875
  */
837
876
  function serializePlatformApp(data, optsions) {
838
877
  var _a;
839
- 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"]);
878
+ let { version, author, name, label, description, selectedPageId, pageInstanceList, lowCodes = [], datasources, vars, dataset, extra, dependencies: calsDependencies, miniprogramPlugins, lastDependencies, externalResources, schemaVersion, layouts } = data, restData = __rest(data, ["version", "author", "name", "label", "description", "selectedPageId", "pageInstanceList", "lowCodes", "datasources", "vars", "dataset", "extra", "dependencies", "miniprogramPlugins", "lastDependencies", "externalResources", "schemaVersion", "layouts"]);
840
879
  let { dependencies = [] } = optsions || {};
841
880
  const _b = extra || {}, { name: extraName, label: extraLabel, author: extraAuthor, description: extraDescription } = _b, restExtra = __rest(_b, ["name", "label", "author", "description"]);
842
881
  const ctx = {
@@ -860,6 +899,7 @@ function serializePlatformApp(data, optsions) {
860
899
  dataset: serializeDataset(ctx, dataset),
861
900
  dataVariables: (0, runtime_1.getValidValue)(vars === null || vars === void 0 ? void 0 : vars.data.map((item) => serializeDataVariables(ctx, item))),
862
901
  dependencies: calsDependencies,
902
+ templates: serializeLayouts(ctx, layouts),
863
903
  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 }),
864
904
  };
865
905
  return processed;
@@ -917,6 +957,7 @@ function deserializePlatformApp(data, optsions) {
917
957
  // TODO
918
958
  // emitEvents: [], { "name": "自定义校验规则", "eventName": "validator" }
919
959
  schemaVersion: data.schemaVersion,
960
+ layouts: deserializeTemplates(ctx, data.templates || []),
920
961
  };
921
962
  return processed;
922
963
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "1.0.28",
3
+ "version": "1.0.29-alpha.1",
4
4
  "description": "Common application specifications",
5
5
  "main": "lib/utils/index.js",
6
6
  "source": "src/utils/index.ts",
@@ -1,5 +0,0 @@
1
- export declare function semverComp(a: string, b: string): number;
2
- export declare function toFixed(num: number, precision: number): number;
3
- export declare const OFFICIAL_COMPONENT_LIB_NAME = "CLOUDBASE_STANDARD";
4
- export declare const OFFICIAL_MATERIAL_LIB_NAME = "gsd-h5-react";
5
- //# sourceMappingURL=common.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/utils/version-migrations/common.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAYvD;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAI9D;AAED,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAChE,eAAO,MAAM,0BAA0B,iBAAiB,CAAC"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OFFICIAL_MATERIAL_LIB_NAME = exports.OFFICIAL_COMPONENT_LIB_NAME = exports.toFixed = exports.semverComp = void 0;
4
- function semverComp(a, b) {
5
- const pa = a.split('.');
6
- const pb = b.split('.');
7
- for (let i = 0; i < 3; i++) {
8
- const na = Number(pa[i]);
9
- const nb = Number(pb[i]);
10
- if (na > nb)
11
- return 1;
12
- if (nb > na)
13
- return -1;
14
- if (!isNaN(na) && isNaN(nb))
15
- return 1;
16
- if (isNaN(na) && !isNaN(nb))
17
- return -1;
18
- }
19
- return 0;
20
- }
21
- exports.semverComp = semverComp;
22
- function toFixed(num, precision) {
23
- const multiplier = Math.pow(10, (precision + 1));
24
- const wholeNumber = Math.floor(num * multiplier);
25
- return (Math.round(wholeNumber / 10) * 10) / multiplier;
26
- }
27
- exports.toFixed = toFixed;
28
- exports.OFFICIAL_COMPONENT_LIB_NAME = 'CLOUDBASE_STANDARD';
29
- exports.OFFICIAL_MATERIAL_LIB_NAME = 'gsd-h5-react';
@@ -1,3 +0,0 @@
1
- import type { IPlatformApp } from '../../types';
2
- export declare function version4(cals: IPlatformApp, isUpgrade: boolean, setSchemaVersionCallback?: (version: string | undefined) => void): IPlatformApp;
3
- //# sourceMappingURL=version4.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version4.d.ts","sourceRoot":"","sources":["../../../src/utils/version-migrations/version4.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,aAAa,CAAC;AAGhE,wBAAgB,QAAQ,CACtB,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,OAAO,EAClB,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GAC/D,YAAY,CAEd"}
@@ -1,199 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.version4 = void 0;
7
- const postcss_1 = __importDefault(require("postcss"));
8
- const postcss_less_1 = __importDefault(require("postcss-less"));
9
- const __1 = require("..");
10
- const common_1 = require("./common");
11
- function version4(cals, isUpgrade, setSchemaVersionCallback) {
12
- return transformPxLowcodeCompAndSourceComp(cals, isUpgrade, setSchemaVersionCallback);
13
- }
14
- exports.version4 = version4;
15
- const transformPxLowcodeCompAndSourceComp = (cals, isUpgrade, setSchemaVersionCallback) => {
16
- var _a, _b, _c, _d;
17
- {
18
- function transformCals(items, isUpgradeToPx) {
19
- return items.map((item) => {
20
- var _a;
21
- // 对于表单操作区的按钮组件的父容器添加.wd-form__action, 兼容组件规范化按钮升级样式
22
- if ((item === null || item === void 0 ? void 0 : item.module) === common_1.OFFICIAL_COMPONENT_LIB_NAME && (item === null || item === void 0 ? void 0 : item.component) === 'Form') {
23
- item = addClassToButtonContainer(item);
24
- }
25
- if ((_a = item === null || item === void 0 ? void 0 : item.extra) === null || _a === void 0 ? void 0 : _a.commonStyle) {
26
- item.extra.commonStyle = convertCommonStyle(item.extra.commonStyle, isUpgradeToPx);
27
- if (item.extra.commonStyle.self) {
28
- // 处理 margin padding shorthand 同步
29
- const newSelf = (0, __1.processCommonStyle2CSSProperties)(item.extra.commonStyle, {
30
- toRem: false,
31
- ignoreSelf: true,
32
- addPXUnit: true,
33
- });
34
- ['margin', 'padding', 'border'].forEach((k) => {
35
- if (item.extra.commonStyle.self[k]) {
36
- item.extra.commonStyle.self[k] = newSelf[k];
37
- }
38
- });
39
- }
40
- }
41
- if (item === null || item === void 0 ? void 0 : item.resources) {
42
- item.resources = item.resources.map((n) => {
43
- if (n.codeType === 'style') {
44
- n = convertLowCodesStyle(n, isUpgradeToPx);
45
- return n;
46
- }
47
- return n;
48
- });
49
- }
50
- if (item.items) {
51
- item.items = transformCals(item.items, isUpgradeToPx);
52
- }
53
- return item;
54
- });
55
- }
56
- let pages = cals['items'];
57
- let isDivision;
58
- if (isUpgrade && (0, common_1.semverComp)((_a = cals['schemaVersion']) !== null && _a !== void 0 ? _a : '3.0.0', '4.0.0') < 0) {
59
- // 组件库版本高于目标版本,且schemaVersion小于4, 将应用 CALS 数据中的 CSS 和 style 中的无单位和有单位的小写 px统一改写为 1/2 px
60
- isDivision = true;
61
- pages = transformCals(pages, isDivision);
62
- cals.resources = (_b = cals.resources) === null || _b === void 0 ? void 0 : _b.map((n) => {
63
- if (n.codeType === 'style') {
64
- n = convertLowCodesStyle(n, isDivision);
65
- return n;
66
- }
67
- return n;
68
- });
69
- cals['schemaVersion'] = '4.0.0';
70
- setSchemaVersionCallback === null || setSchemaVersionCallback === void 0 ? void 0 : setSchemaVersionCallback('4.0.0');
71
- }
72
- else if (!isUpgrade && (0, common_1.semverComp)((_c = cals['schemaVersion']) !== null && _c !== void 0 ? _c : '3.0.0', '4.0.0') >= 0) {
73
- // 组件库低于目标版本,并且schemaVersion大于4 将应用 CALS 数据中的 CSS 和 style 中的无单位和有单位的小写 px统一改写为 2倍 px
74
- isDivision = false;
75
- pages = transformCals(pages, isDivision);
76
- cals.resources = (_d = cals.resources) === null || _d === void 0 ? void 0 : _d.map((n) => {
77
- if (n.codeType === 'style') {
78
- n = convertLowCodesStyle(n, isDivision);
79
- return n;
80
- }
81
- return n;
82
- });
83
- delete cals['schemaVersion'];
84
- setSchemaVersionCallback === null || setSchemaVersionCallback === void 0 ? void 0 : setSchemaVersionCallback(undefined);
85
- }
86
- cals['items'] = pages;
87
- return cals;
88
- }
89
- };
90
- function hasSubmitButton(item) {
91
- var _a;
92
- if ((_a = item === null || item === void 0 ? void 0 : item.items) === null || _a === void 0 ? void 0 : _a.length) {
93
- const children = item.items;
94
- return children.some((i) => { var _a; return (i === null || i === void 0 ? void 0 : i.module) === common_1.OFFICIAL_COMPONENT_LIB_NAME && i.component === 'Button' && ((_a = i === null || i === void 0 ? void 0 : i.attributes) === null || _a === void 0 ? void 0 : _a.formType) === 'submit'; });
95
- }
96
- return false;
97
- }
98
- function addClassToButtonContainer(item) {
99
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
100
- if ((item === null || item === void 0 ? void 0 : item.module) === common_1.OFFICIAL_MATERIAL_LIB_NAME && item.component === 'Container') {
101
- if (hasSubmitButton(item)) {
102
- if (((_a = item.attributes) === null || _a === void 0 ? void 0 : _a.class) && !((_b = item.attributes) === null || _b === void 0 ? void 0 : _b.class.includes('wd-form__action'))) {
103
- if (typeof ((_c = item.attributes) === null || _c === void 0 ? void 0 : _c.class) === 'string') {
104
- item.attributes = Object.assign(Object.assign({}, item.attributes), { class: `${(_d = item.attributes) === null || _d === void 0 ? void 0 : _d.class} wd-form__action` });
105
- }
106
- else if (Array.isArray((_e = item.attributes) === null || _e === void 0 ? void 0 : _e.class)) {
107
- item.attributes = Object.assign(Object.assign({}, item.attributes), { class: [...(_f = item.attributes) === null || _f === void 0 ? void 0 : _f.class, 'wd-form__action'] });
108
- }
109
- }
110
- else if (!((_g = item.attributes) === null || _g === void 0 ? void 0 : _g.class)) {
111
- item.attributes = Object.assign(Object.assign({}, item.attributes), { class: 'wd-form__action' });
112
- }
113
- // 移除旧的padding配置
114
- if ((_j = (_h = item === null || item === void 0 ? void 0 : item.extra) === null || _h === void 0 ? void 0 : _h.commonStyle) === null || _j === void 0 ? void 0 : _j.padding) {
115
- delete item.extra.commonStyle.padding;
116
- }
117
- }
118
- }
119
- if ((_k = item === null || item === void 0 ? void 0 : item.items) === null || _k === void 0 ? void 0 : _k.length) {
120
- item.items = item.items.map((i) => addClassToButtonContainer(i));
121
- }
122
- return item;
123
- }
124
- function jsonTranverse(json, reviver) {
125
- return JSON.parse(JSON.stringify(json, reviver, 2));
126
- }
127
- function convertCommonStyle(value, isUpgrade) {
128
- return jsonTranverse(value, (key, value) => {
129
- if (__1.isUnitlessNumber[key]) {
130
- return value;
131
- }
132
- if (typeof value === 'number') {
133
- if (isUpgrade) {
134
- value = value / 2;
135
- }
136
- else {
137
- value = value * 2;
138
- }
139
- }
140
- else if (/^((\d+\.)?\d+)(px)?$/.test(value)) {
141
- value = !value ? value : value === null || value === void 0 ? void 0 : value.replace('px', '');
142
- if (isUpgrade) {
143
- // console.log(key, value, Number(value) / 2);
144
- value = !value ? value : `${(0, common_1.toFixed)(Number(value) / 2, 3)}px`;
145
- }
146
- else {
147
- value = !value ? value : `${Number(value) * 2}px`;
148
- }
149
- }
150
- return value;
151
- });
152
- }
153
- const rem2PxPlugin = (opts) => {
154
- const rem2pxSym = Symbol('rem2pxSym');
155
- const { isUpgrade } = opts;
156
- return {
157
- postcssPlugin: 'postcss-rem2px',
158
- Declaration(decl, rule) {
159
- // Modified From https://github.com/cuth/postcss-pxtorem/blob/122649015322214f8e9d1ac852eb11c0791b634b/lib/pixel-unit-regex.js#L9
160
- // eslint-disable-next-line no-useless-escape
161
- const pxRegex = /"[^"]+"|'[^']+'|(\d*\.?\d+)px/gm;
162
- if (decl.value.indexOf('px') < 0) {
163
- return;
164
- }
165
- if (decl[rem2pxSym]) {
166
- return;
167
- }
168
- if (isUpgrade) {
169
- const value = decl.value.replace(pxRegex, (match, p1) => {
170
- if (p1 !== null && p1 !== undefined) {
171
- const r = (0, common_1.toFixed)(Number(p1) / 2, 3);
172
- const rs = r.toString();
173
- return `${rs}px`;
174
- }
175
- return match;
176
- });
177
- decl.value = value;
178
- }
179
- else {
180
- const value = decl.value.replace(pxRegex, (match, p1) => {
181
- if (p1 !== null && p1 !== undefined) {
182
- return `${Number(p1) * 2}px`;
183
- }
184
- return match;
185
- });
186
- decl.value = value;
187
- }
188
- decl[rem2pxSym] = true;
189
- },
190
- };
191
- };
192
- rem2PxPlugin.postcss = true;
193
- function convertLowCodesStyle(value, isUpgrade) {
194
- const result = (0, postcss_1.default)([rem2PxPlugin({ isUpgrade })]).process(value.code, {
195
- syntax: postcss_less_1.default,
196
- });
197
- value.code = result.css;
198
- return value;
199
- }