@cloudbase/lowcode-builder 0.1.21 → 0.1.22

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,9 +1,9 @@
1
- import { IDynamicValue, IWeAppComponentInstance } from '@cloudbase/lowcode-generator/lib/weapps-core';
1
+ import { IDynamicValue, IWeAppComponentInstance, ICompositedComponent } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { IBuildContext } from './BuildContext';
3
- export declare function extractWidgetProps(props: Required<IWeAppComponentInstance>['xProps']): any;
3
+ export declare function extractWidgetProps(props: Required<IWeAppComponentInstance>['xProps'], compInfo: ICompositedComponent): any;
4
4
  export declare function generatedDynamicData(data: {
5
5
  [key: string]: IDynamicValue;
6
- }): {
6
+ }, compInfo?: ICompositedComponent): {
7
7
  staticProps: {};
8
8
  boundProps: {};
9
9
  };
@@ -5,7 +5,7 @@ const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
5
5
  const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
6
6
  const wxml_1 = require("./wxml");
7
7
  const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
8
- function extractWidgetProps(props) {
8
+ function extractWidgetProps(props, compInfo) {
9
9
  const { classList } = props;
10
10
  const staticProps = {
11
11
  style: (0, weapps_core_1.toCssStyle)(props.commonStyle, {
@@ -15,19 +15,31 @@ function extractWidgetProps(props) {
15
15
  classList: classList || [],
16
16
  };
17
17
  const { data = {} } = props;
18
- Object.assign(staticProps, generatedDynamicData(data).staticProps);
18
+ Object.assign(staticProps, generatedDynamicData(data, compInfo).staticProps);
19
19
  return staticProps;
20
20
  }
21
21
  exports.extractWidgetProps = extractWidgetProps;
22
- function generatedDynamicData(data) {
22
+ function generatedDynamicData(data, compInfo) {
23
23
  const staticProps = {};
24
24
  const boundProps = {};
25
- for (const key in data) {
25
+ for (const key of Object.keys(data)) {
26
26
  if (mp_1.builtinWigetProps.indexOf(key) > -1)
27
27
  continue;
28
28
  const { type, value } = data[key];
29
29
  if (!type || type === 'static') {
30
30
  staticProps[key] = value;
31
+ if (value === undefined) {
32
+ /* 为了避免绑定undefined的时候,与组件properties类型声明不匹配
33
+ 在小程序基础库2.18后会爆warning
34
+ 所以提前给他准备空值
35
+ */
36
+ if ((compInfo === null || compInfo === void 0 ? void 0 : compInfo.dataForm[key]) && mp_1.jsonSchemaType2jsClass[compInfo.dataForm[key].type]) {
37
+ const globalNamespace = typeof globalThis === 'undefined' ? global : globalThis;
38
+ const constructorName = mp_1.jsonSchemaType2jsClass[compInfo.dataForm[key].type];
39
+ const defaultValue = globalNamespace[constructorName]();
40
+ staticProps[key] = defaultValue;
41
+ }
42
+ }
31
43
  }
32
44
  else {
33
45
  boundProps[key] = generateDataBind(data[key]);
@@ -100,7 +112,12 @@ function createWidgetProps(widgets, ctx) {
100
112
  console.error('Component lib not found', xComponent);
101
113
  return;
102
114
  }
103
- widgetProps[id] = extractWidgetProps(xProps);
115
+ const widegetComp = materialLib === null || materialLib === void 0 ? void 0 : materialLib.components.find((comp) => comp.name === xComponent.name);
116
+ if (!widegetComp) {
117
+ console.error('Component not found in lib', widegetComp);
118
+ return;
119
+ }
120
+ widgetProps[id] = extractWidgetProps(xProps, widegetComp);
104
121
  widgetProps[id]._parentId = parentId;
105
122
  widgetProps[id]._order = widget.xIndex;
106
123
  widgetProps[id].widgetType = xComponent.moduleName + ':' + xComponent.name;
@@ -178,7 +195,8 @@ function createEventHanlders(widgets, componentApi, ctx) {
178
195
  // 如果是数据容器,则生成一个onDataChange事件处理
179
196
  if ((_c = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _c === void 0 ? void 0 : _c.isDataContainer) {
180
197
  const customName = (0, wxml_1.getMpEventHanlderName)(id, 'onDataChange', {});
181
- eventHanlders[customName] = [{
198
+ eventHanlders[customName] = [
199
+ {
182
200
  key: '',
183
201
  handler: `({event})=>{
184
202
  app.utils.set(context, '${id}.data', event?.detail?.data);
@@ -186,7 +204,8 @@ function createEventHanlders(widgets, componentApi, ctx) {
186
204
  handlerModule: weapps_core_1.ActionType.Platform,
187
205
  data: {},
188
206
  boundData: {},
189
- }];
207
+ },
208
+ ];
190
209
  }
191
210
  });
192
211
  return eventHanlders;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
5
5
  "author": "yhsunshining@gmail.com",
6
6
  "homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
@@ -7,7 +7,7 @@
7
7
  "dependencies": {
8
8
  "@cloudbase/js-sdk": "2.4.0-beta.0",
9
9
  "@tcwd/weapps-core": "2.2.6",
10
- "@tcwd/weapps-sdk": "1.2.9",
10
+ "@tcwd/weapps-sdk": "1.2.10",
11
11
  "@zxing/library": "^0.18.6",
12
12
  "@cloudbase/weda-client": "^0.2.4",
13
13
  "fastclick": "^1.0.6",