@cloudbase/lowcode-builder 0.1.21 → 0.1.24
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.
- package/lib/builder/mp/util.d.ts +3 -3
- package/lib/builder/mp/util.js +26 -7
- package/lib/builder/mp/wxml.js +10 -24
- package/package.json +1 -1
- package/template/mp/common/weapp-component.js +3 -3
- package/template/mp/common/widget.js +2 -0
- package/template/package.json +1 -1
- package/lib/builder.web.js +0 -71
package/lib/builder/mp/util.d.ts
CHANGED
|
@@ -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
|
};
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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/lib/builder/mp/wxml.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getUsedComponents = exports.getMpEventHanlderName = exports.generateWxml = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
|
|
9
8
|
const xml_js_1 = require("xml-js");
|
|
10
9
|
const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
11
10
|
const materials_1 = require("./materials");
|
|
@@ -14,9 +13,7 @@ const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib
|
|
|
14
13
|
const error = chalk_1.default.redBright;
|
|
15
14
|
function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, componentGenerics, nodeTransform) {
|
|
16
15
|
var _a;
|
|
17
|
-
const nameMangler = ctx.isProduction
|
|
18
|
-
? new name_mangler_1.default({ blackList: mp_1.builtinMpTags })
|
|
19
|
-
: undefined;
|
|
16
|
+
const nameMangler = ctx.isProduction ? new name_mangler_1.default({ blackList: mp_1.builtinMpTags }) : undefined;
|
|
20
17
|
const xmlJson = {
|
|
21
18
|
elements: [
|
|
22
19
|
{
|
|
@@ -57,9 +54,9 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
57
54
|
function createXml(widgets, parent = null, parentForNodes = []) {
|
|
58
55
|
var _a, _b, _c, _d, _e;
|
|
59
56
|
const elements = [];
|
|
60
|
-
for (const id
|
|
57
|
+
for (const id of Object.keys(widgets !== null && widgets !== void 0 ? widgets : {})) {
|
|
61
58
|
const { xComponent, xProps, properties, xIndex, genericComp } = widgets[id];
|
|
62
|
-
const { data: data0 = {}, listeners = [], directives = {}, staticResourceAttribute = ['src']
|
|
59
|
+
const { data: data0 = {}, listeners = [], directives = {}, staticResourceAttribute = ['src'] } = xProps || {};
|
|
63
60
|
const data = { ...data0 };
|
|
64
61
|
if (directives.waIf && directives.waIf.value === false) {
|
|
65
62
|
continue;
|
|
@@ -110,17 +107,13 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
110
107
|
.join('')}`;
|
|
111
108
|
const idAttr = curForNodes.length < 1
|
|
112
109
|
? id
|
|
113
|
-
: `{{'${id}'${curForNodes
|
|
114
|
-
.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`)
|
|
115
|
-
.join('')}}}`;
|
|
110
|
+
: `{{'${id}'${curForNodes.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`).join('')}}}`;
|
|
116
111
|
if (tagName === 'slot') {
|
|
117
112
|
const slotNode = {
|
|
118
113
|
type: 'element',
|
|
119
114
|
name: tagName,
|
|
120
115
|
attributes: {
|
|
121
|
-
name: data0.name.type && data0.name.type !== 'static'
|
|
122
|
-
? `{{${id}.name}}`
|
|
123
|
-
: data0.name.value,
|
|
116
|
+
name: data0.name.type && data0.name.type !== 'static' ? `{{${id}.name}}` : data0.name.value,
|
|
124
117
|
},
|
|
125
118
|
elements: [],
|
|
126
119
|
_order: xIndex || 0,
|
|
@@ -206,8 +199,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
206
199
|
listeners.forEach((l) => {
|
|
207
200
|
const evtName = getMpEventName(l.trigger);
|
|
208
201
|
const modifiers = l;
|
|
209
|
-
node.attributes[getMpEventAttr(evtName, modifiers, tagName)] =
|
|
210
|
-
getMpEventHanlderName(id, evtName, modifiers);
|
|
202
|
+
node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
|
|
211
203
|
});
|
|
212
204
|
// 扩展组件配置
|
|
213
205
|
const compConfig = componentProto.compConfig;
|
|
@@ -240,9 +232,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
240
232
|
}*/
|
|
241
233
|
node.elements = node.elements.concat(createXml(properties, node, curForNodes));
|
|
242
234
|
// 特殊处理 swiper,对swiper 子节点包裹议程 swiperItem
|
|
243
|
-
if (tagName === 'swiper' ||
|
|
244
|
-
componentKey === 'weda:Swiper' ||
|
|
245
|
-
componentKey === 'gsd-h5-react:Swiper') {
|
|
235
|
+
if (tagName === 'swiper' || componentKey === 'weda:Swiper' || componentKey === 'gsd-h5-react:Swiper') {
|
|
246
236
|
node.elements = node.elements.map((item, index) => {
|
|
247
237
|
var _a, _b;
|
|
248
238
|
let { ['wx:for']: wxFor, ['wx:for-index']: wxForIndex, ['wx:key']: wxKey, ['wx:if']: wxIf, ...itemRestKey } = item.attributes || {};
|
|
@@ -362,10 +352,8 @@ function getUsedComponents(widgets, usedCmps = {}) {
|
|
|
362
352
|
exports.getUsedComponents = getUsedComponents;
|
|
363
353
|
function getAttrBind(dVale, widgetBind, isStaticResource) {
|
|
364
354
|
const { type, value } = dVale;
|
|
365
|
-
const attrVal =
|
|
366
|
-
return isStaticResource
|
|
367
|
-
? `{{wxsUtils._getStaticResourceAttribute(${attrVal})}}`
|
|
368
|
-
: `{{${attrVal}}}`;
|
|
355
|
+
const attrVal = widgetBind;
|
|
356
|
+
return isStaticResource ? `{{wxsUtils._getStaticResourceAttribute(${attrVal})}}` : `{{${attrVal}}}`;
|
|
369
357
|
}
|
|
370
358
|
function getGenericCompTagName(propName) {
|
|
371
359
|
return `g--${propName}`;
|
|
@@ -404,7 +392,5 @@ function isGlobalAttr(prop = '') {
|
|
|
404
392
|
'title',
|
|
405
393
|
'translate',
|
|
406
394
|
];
|
|
407
|
-
return
|
|
408
|
-
prop.startsWith('data-') ||
|
|
409
|
-
prop.startsWith('aria-'));
|
|
395
|
+
return globalAttrs.indexOf(prop) > -1 || prop.startsWith('data-') || prop.startsWith('aria-');
|
|
410
396
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
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",
|
|
@@ -5,7 +5,7 @@ import mergeRenderer from './merge-renderer'
|
|
|
5
5
|
import { runWatchers } from './watch'
|
|
6
6
|
import sdk from './weapp-sdk'
|
|
7
7
|
import lodashGet from 'lodash.get';
|
|
8
|
-
|
|
8
|
+
import { createInitData } from './widget';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Lowcodes of all components
|
|
@@ -13,7 +13,7 @@ import lodashGet from 'lodash.get';
|
|
|
13
13
|
export const compLowcodes = {}
|
|
14
14
|
|
|
15
15
|
export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, undefined, context) {
|
|
16
|
-
|
|
16
|
+
const initData = createInitData(widgetProps, dataBinds, '');
|
|
17
17
|
compLowcodes[key] = {
|
|
18
18
|
index,
|
|
19
19
|
stateFn,
|
|
@@ -45,7 +45,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
45
45
|
...properties,
|
|
46
46
|
},
|
|
47
47
|
|
|
48
|
-
data:
|
|
48
|
+
data: initData,
|
|
49
49
|
|
|
50
50
|
lifetimes: {
|
|
51
51
|
created() {
|
|
@@ -303,6 +303,8 @@ export function createInitData(widgets, dataBinds, keyPrefix = '') {
|
|
|
303
303
|
return Object.keys(widgets).reduce((result, id) => {
|
|
304
304
|
if (!isWidgetInFor(id, widgets, dataBinds)) {
|
|
305
305
|
result[keyPrefix + id] = resolveWidgetData(widgets[id])
|
|
306
|
+
} else {
|
|
307
|
+
result[keyPrefix + id] = []
|
|
306
308
|
}
|
|
307
309
|
return result
|
|
308
310
|
}, {})
|
package/template/package.json
CHANGED