@cloudbase/cals 1.0.3-alpha.8 → 1.0.3-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/lib/parser/cals/index.d.ts +379 -366
  2. package/lib/parser/cals/index.d.ts.map +1 -1
  3. package/lib/parser/cals/index.js +75 -13
  4. package/lib/parser/cals/utils/block/index.d.ts +14 -14
  5. package/lib/parser/cals/utils/block/index.d.ts.map +0 -0
  6. package/lib/parser/cals/utils/block/index.js +3 -3
  7. package/lib/parser/cals/utils/code/index.d.ts +30 -30
  8. package/lib/parser/cals/utils/code/index.d.ts.map +0 -0
  9. package/lib/parser/cals/utils/code/index.js +12 -13
  10. package/lib/parser/cals/utils/common.d.ts +11 -11
  11. package/lib/parser/cals/utils/common.d.ts.map +0 -0
  12. package/lib/parser/cals/utils/common.js +0 -0
  13. package/lib/parser/cals/utils/runtime.d.ts +13 -13
  14. package/lib/parser/cals/utils/runtime.d.ts.map +1 -1
  15. package/lib/parser/cals/utils/runtime.js +2 -2
  16. package/lib/parser/cals/utils/spinoff/index.d.ts +9 -9
  17. package/lib/parser/cals/utils/spinoff/index.d.ts.map +0 -0
  18. package/lib/parser/cals/utils/spinoff/index.js +0 -0
  19. package/lib/parser/cals/utils/style.d.ts +42 -42
  20. package/lib/parser/cals/utils/style.d.ts.map +1 -1
  21. package/lib/parser/cals/utils/style.js +3 -3
  22. package/lib/parser/cals/utils/template.d.ts +5 -5
  23. package/lib/parser/cals/utils/template.d.ts.map +0 -0
  24. package/lib/parser/cals/utils/template.js +6 -3
  25. package/lib/parser/cals/utils/version/common.d.ts +4 -4
  26. package/lib/parser/cals/utils/version/common.d.ts.map +0 -0
  27. package/lib/parser/cals/utils/version/common.js +34 -11
  28. package/lib/parser/cals/utils/version/config.d.ts +13 -13
  29. package/lib/parser/cals/utils/version/config.d.ts.map +0 -0
  30. package/lib/parser/cals/utils/version/config.js +0 -0
  31. package/lib/parser/cals/utils/version/index.d.ts +2 -2
  32. package/lib/parser/cals/utils/version/index.d.ts.map +0 -0
  33. package/lib/parser/cals/utils/version/index.js +0 -0
  34. package/lib/parser/cals/utils/version/parses.d.ts +15 -15
  35. package/lib/parser/cals/utils/version/parses.d.ts.map +0 -0
  36. package/lib/parser/cals/utils/version/parses.js +37 -14
  37. package/lib/parser/cals/utils/version/utils.d.ts +13 -13
  38. package/lib/parser/cals/utils/version/utils.d.ts.map +1 -1
  39. package/lib/parser/cals/utils/version/utils.js +2 -2
  40. package/lib/parser/constants.d.ts +2 -0
  41. package/lib/parser/constants.d.ts.map +1 -0
  42. package/lib/parser/constants.js +4 -0
  43. package/lib/parser/expression/index.d.ts +122 -122
  44. package/lib/parser/expression/index.d.ts.map +0 -0
  45. package/lib/parser/expression/index.js +0 -0
  46. package/lib/parser/index.d.ts +8 -8
  47. package/lib/parser/index.d.ts.map +0 -0
  48. package/lib/parser/index.js +0 -0
  49. package/lib/parser/plugins/postcss-rpx2clac.d.ts +17 -17
  50. package/lib/parser/plugins/postcss-rpx2clac.js +2 -2
  51. package/lib/types/basic/app.d.ts +72 -72
  52. package/lib/types/basic/app.d.ts.map +0 -0
  53. package/lib/types/basic/app.js +0 -0
  54. package/lib/types/basic/common.d.ts +88 -88
  55. package/lib/types/basic/common.d.ts.map +1 -1
  56. package/lib/types/basic/common.js +0 -0
  57. package/lib/types/basic/component.d.ts +213 -208
  58. package/lib/types/basic/component.d.ts.map +1 -1
  59. package/lib/types/basic/component.js +0 -0
  60. package/lib/types/basic/datasource.d.ts +49 -49
  61. package/lib/types/basic/datasource.d.ts.map +0 -0
  62. package/lib/types/basic/datasource.js +0 -0
  63. package/lib/types/index.d.ts +10 -9
  64. package/lib/types/index.d.ts.map +1 -1
  65. package/lib/types/index.js +1 -14
  66. package/lib/types/lcds.d.ts +334 -447
  67. package/lib/types/lcds.d.ts.map +1 -1
  68. package/lib/types/lcds.js +0 -0
  69. package/lib/types/platform/app.d.ts +176 -176
  70. package/lib/types/platform/app.d.ts.map +0 -0
  71. package/lib/types/platform/app.js +0 -0
  72. package/lib/types/platform/common.d.ts +147 -137
  73. package/lib/types/platform/common.d.ts.map +1 -1
  74. package/lib/types/platform/common.js +0 -0
  75. package/lib/types/platform/component.d.ts +145 -140
  76. package/lib/types/platform/component.d.ts.map +1 -1
  77. package/lib/types/platform/component.js +0 -0
  78. package/lib/types/platform/datasource.d.ts +466 -466
  79. package/lib/types/platform/datasource.d.ts.map +0 -0
  80. package/lib/types/platform/datasource.js +0 -0
  81. package/lib/types/platform/eventFlow.d.ts +20 -0
  82. package/lib/types/platform/eventFlow.d.ts.map +1 -0
  83. package/lib/types/platform/eventFlow.js +2 -0
  84. package/lib/types/platform/query.d.ts +58 -0
  85. package/lib/types/platform/query.d.ts.map +1 -0
  86. package/lib/types/platform/query.js +2 -0
  87. package/lib/types/platform/widget/form.d.ts +89 -89
  88. package/lib/types/platform/widget/form.d.ts.map +0 -0
  89. package/lib/types/platform/widget/form.js +0 -0
  90. package/lib/types/platform/widget/meta.d.ts +59 -59
  91. package/lib/types/platform/widget/meta.d.ts.map +0 -0
  92. package/lib/types/platform/widget/meta.js +0 -0
  93. package/lib/utils/CSSProperty.d.ts +63 -63
  94. package/lib/utils/CSSProperty.d.ts.map +0 -0
  95. package/lib/utils/CSSProperty.js +0 -0
  96. package/lib/utils/build.d.ts +1 -1
  97. package/lib/utils/build.d.ts.map +0 -0
  98. package/lib/utils/build.js +6 -3
  99. package/lib/utils/constant.d.ts +40 -40
  100. package/lib/utils/constant.d.ts.map +0 -0
  101. package/lib/utils/constant.js +0 -0
  102. package/lib/utils/dts/auto-generated.d.ts +1 -1
  103. package/lib/utils/dts/auto-generated.d.ts.map +1 -1
  104. package/lib/utils/dts/auto-generated.js +35 -1227
  105. package/lib/utils/dts/build.d.ts +1 -1
  106. package/lib/utils/dts/build.js +4 -1
  107. package/lib/utils/dts/index.d.ts +93 -130
  108. package/lib/utils/dts/index.d.ts.map +1 -1
  109. package/lib/utils/dts/index.js +66 -359
  110. package/lib/utils/index.d.ts +7 -7
  111. package/lib/utils/index.d.ts.map +0 -0
  112. package/lib/utils/index.js +0 -0
  113. package/lib/utils/version/common.d.ts +2 -2
  114. package/lib/utils/version/featureChecker.d.ts +2 -2
  115. package/lib/utils/version/featureChecker.d.ts.map +1 -1
  116. package/lib/utils/version/migrations/version4.d.ts +2 -2
  117. package/lib/utils/version/migrations/version4.js +2 -2
  118. package/lib/utils/version-migrations/common.d.ts +5 -0
  119. package/lib/utils/version-migrations/common.d.ts.map +1 -0
  120. package/lib/utils/version-migrations/common.js +29 -0
  121. package/lib/utils/version-migrations/version4.d.ts +3 -0
  122. package/lib/utils/version-migrations/version4.d.ts.map +1 -0
  123. package/lib/utils/version-migrations/version4.js +199 -0
  124. package/package.json +3 -13
  125. package/lib/cloudbase.cals.umd.min.js +0 -5
@@ -0,0 +1,29 @@
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';
@@ -0,0 +1,3 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,199 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cals",
3
- "version": "1.0.3-alpha.8",
3
+ "version": "1.0.3-alpha.9",
4
4
  "description": "Common application specifications",
5
5
  "main": "lib/utils/index.js",
6
6
  "source": "src/utils/index.ts",
@@ -15,7 +15,6 @@
15
15
  "build": "tsc",
16
16
  "build:schema": "ts-node src/utils/build.ts",
17
17
  "build:dts": "ts-node src/utils/dts/build.ts",
18
- "build:umd": "tsc && rollup -c rollup.config.js --bundleConfigAsCjs",
19
18
  "build:dts:watch": "ts-node src/utils/dts/build.ts --watch",
20
19
  "develop": "tsc --watch",
21
20
  "docs": "typedoc --options typedoc.json types",
@@ -31,18 +30,15 @@
31
30
  "license": "MIT",
32
31
  "dependencies": {
33
32
  "acorn": "^8.0.4",
34
- "json-easy-filter": "^0.3.1",
35
33
  "json-schema-to-typescript-for-browser": "^11.0.3",
36
- "lodash-es": "^4.17.19",
34
+ "lodash": "^4.17.20",
37
35
  "postcss": "^8.4.20",
38
36
  "postcss-less": "^6.0.0"
39
37
  },
40
38
  "devDependencies": {
41
- "@rollup/plugin-node-resolve": "^15.0.2",
42
- "@rollup/plugin-typescript": "^11.1.0",
43
39
  "@types/acorn": "^4.0.5",
44
40
  "@types/jest": "^27.4.0",
45
- "@types/lodash-es": "^4.17.6",
41
+ "@types/lodash": "^4.14.168",
46
42
  "@types/node": "^14.14.6",
47
43
  "@types/react": "^18.0.17",
48
44
  "@types/web": "^0.0.78",
@@ -52,12 +48,6 @@
52
48
  "jest-fetch-mock": "^3.0.3",
53
49
  "jsdom-worker": "^0.3.0",
54
50
  "node-watch": "^0.7.3",
55
- "rollup": "^3.21.6",
56
- "rollup-plugin-babel": "^4.4.0",
57
- "rollup-plugin-commonjs": "^10.1.0",
58
- "rollup-plugin-size-snapshot": "^0.12.0",
59
- "rollup-plugin-terser": "^7.0.2",
60
- "rollup-plugin-typescript2": "0.31.2",
61
51
  "ts-jest": "^27.1.5",
62
52
  "ts-node": "^10.4.0",
63
53
  "typescript": "^4.7.4",