@cloudbase/lowcode-builder 1.2.4 → 1.3.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.
- package/lib/builder/config/index.d.ts +8 -0
- package/lib/builder/config/index.js +18 -9
- package/lib/builder/mp/index.js +25 -14
- package/lib/builder/mp/lowcode.js +2 -5
- package/lib/builder/mp/materials.d.ts +2 -2
- package/lib/builder/mp/materials.js +8 -7
- package/lib/builder/mp/mp_config.d.ts +1 -1
- package/lib/builder/mp/mp_config.js +1 -1
- package/lib/builder/mp/util.d.ts +23 -1
- package/lib/builder/mp/util.js +164 -61
- package/lib/builder/mp/wxml.d.ts +4 -4
- package/lib/builder/mp/wxml.js +67 -60
- package/lib/test.d.ts +11 -0
- package/lib/test.js +717 -0
- package/package.json +3 -3
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/weapps-api.js +11 -2
- package/template/mp/app.js +1 -2
- package/template/mp/common/constant.js +1 -0
- package/template/mp/common/util.js +78 -81
- package/template/mp/common/watch.js +1 -1
- package/template/mp/common/weapp-component.js +55 -43
- package/template/mp/common/weapp-page.js +90 -84
- package/template/mp/common/widget.js +680 -442
- package/template/mp/component/index.js +4 -5
- package/template/mp/package.json +1 -1
- package/template/mp/page/api.js +24 -1
- package/template/mp/page/index.js +4 -6
- package/template/mp/page/index.json +1 -1
- package/template/mp/common/process.js +0 -1
package/lib/builder/mp/wxml.js
CHANGED
|
@@ -11,9 +11,10 @@ const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
|
11
11
|
const materials_1 = require("./materials");
|
|
12
12
|
const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
|
|
13
13
|
const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib/generator/util/name-mangler"));
|
|
14
|
+
const config_1 = require("../config");
|
|
15
|
+
const util_1 = require("./util");
|
|
14
16
|
const error = chalk_1.default.redBright;
|
|
15
|
-
function generateWxml(widgets, docTag, wxmlDataPrefix,
|
|
16
|
-
var _a;
|
|
17
|
+
function generateWxml(ctx, widgets, docTag, wxmlDataPrefix, usingComponents, componentGenerics, nodeTransform) {
|
|
17
18
|
const nameMangler = ctx.isProduction ? new name_mangler_1.default({ blackList: mp_1.builtinMpTags }) : undefined;
|
|
18
19
|
const xmlJson = {
|
|
19
20
|
elements: [
|
|
@@ -32,12 +33,6 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
32
33
|
};
|
|
33
34
|
if (ctx.isPage) {
|
|
34
35
|
const originElements = xmlJson.elements;
|
|
35
|
-
if (originElements === null || originElements === void 0 ? void 0 : originElements.length) {
|
|
36
|
-
if (!((_a = originElements[0]) === null || _a === void 0 ? void 0 : _a.attributes)) {
|
|
37
|
-
originElements[0].attributes = {};
|
|
38
|
-
}
|
|
39
|
-
originElements[0].attributes['data-weui-theme'] = 'light';
|
|
40
|
-
}
|
|
41
36
|
// 登录校验: 向其最外层包裹一层block
|
|
42
37
|
xmlJson.elements = [
|
|
43
38
|
{
|
|
@@ -45,6 +40,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
45
40
|
name: 'block',
|
|
46
41
|
attributes: {
|
|
47
42
|
['wx:if']: '{{weDaHasLogin}}',
|
|
43
|
+
['data-weui-theme']: 'light',
|
|
48
44
|
},
|
|
49
45
|
elements: originElements,
|
|
50
46
|
_order: -1,
|
|
@@ -55,10 +51,11 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
55
51
|
function createXml(widgets, parent = null, parentForNodes = []) {
|
|
56
52
|
var _a, _b, _c, _d, _e, _f;
|
|
57
53
|
const elements = [];
|
|
54
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
58
55
|
for (const id in widgets) {
|
|
59
56
|
const { xComponent, xProps, properties, xIndex, genericComp } = widgets[id];
|
|
60
|
-
const { data:
|
|
61
|
-
const data = { ...
|
|
57
|
+
const { data: _data = {}, listeners = [], directives = {}, staticResourceAttribute = ['src'] } = xProps || {};
|
|
58
|
+
const data = { ..._data };
|
|
62
59
|
if (directives.waIf && directives.waIf.value === false) {
|
|
63
60
|
continue;
|
|
64
61
|
}
|
|
@@ -66,9 +63,8 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
66
63
|
// slot prop
|
|
67
64
|
const slotNodes = createXml(properties, parent, parentForNodes);
|
|
68
65
|
slotNodes.forEach((node) => {
|
|
69
|
-
var _a;
|
|
70
66
|
node.attributes.slot = id;
|
|
71
|
-
|
|
67
|
+
elements === null || elements === void 0 ? void 0 : elements.push(node);
|
|
72
68
|
});
|
|
73
69
|
if (parent) {
|
|
74
70
|
delete parent.attributes[id];
|
|
@@ -77,21 +73,36 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
77
73
|
}
|
|
78
74
|
const componentKey = `${xComponent.moduleName}:${xComponent.name}`;
|
|
79
75
|
const helpMsg = `Please check component(${id}) in component tree of ${docTag}.`;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
let tagName, path, componentProto;
|
|
77
|
+
switch (componentKey) {
|
|
78
|
+
case `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`: {
|
|
79
|
+
const children = createXml(properties, parent, parentForNodes);
|
|
80
|
+
for (let item of children) {
|
|
81
|
+
item._order = xIndex || 0;
|
|
82
|
+
}
|
|
83
|
+
elements.push(...children);
|
|
84
|
+
continue;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`: {
|
|
88
|
+
tagName = 'block';
|
|
89
|
+
path = '';
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
default: {
|
|
93
|
+
componentProto = (0, util_1.findComponentInfo)(xComponent, {
|
|
94
|
+
materialLibs: ctx.materialLibs,
|
|
95
|
+
miniprogramPlugins: ctx.miniprogramPlugins,
|
|
96
|
+
});
|
|
97
|
+
if (!componentProto) {
|
|
98
|
+
console.error(error(`Component(${xComponent.name}) not found in lib(${xComponent.moduleName}). ${helpMsg}`));
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const meta = (0, materials_1.getWxmlTag)(ctx, xComponent, nameMangler);
|
|
102
|
+
tagName = meta.tagName;
|
|
103
|
+
path = meta.path;
|
|
104
|
+
}
|
|
92
105
|
}
|
|
93
|
-
// eslint-disable-next-line prefer-const
|
|
94
|
-
let { tagName, path } = (0, materials_1.getWxmlTag)(xComponent, ctx, nameMangler);
|
|
95
106
|
if (genericComp === null || genericComp === void 0 ? void 0 : genericComp.propName) {
|
|
96
107
|
tagName = getGenericCompTagName(genericComp.propName);
|
|
97
108
|
componentGenerics[tagName] = { default: path || tagName };
|
|
@@ -100,50 +111,46 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
100
111
|
usingComponents[tagName] = path;
|
|
101
112
|
}
|
|
102
113
|
let curForNodes = parentForNodes;
|
|
103
|
-
if ((
|
|
114
|
+
if ((_a = directives.waFor) === null || _a === void 0 ? void 0 : _a.value) {
|
|
104
115
|
curForNodes = [...curForNodes, id];
|
|
105
116
|
}
|
|
106
117
|
const attrPrefix = `${wxmlDataPrefix.widgetProp}${id}${curForNodes
|
|
107
118
|
.map((forNodeId) => `[${wxmlDataPrefix.forIndex}${forNodeId}]`)
|
|
108
119
|
.join('')}`;
|
|
109
|
-
const idAttr = curForNodes.length < 1
|
|
110
|
-
? id
|
|
111
|
-
: `{{'${id}'${curForNodes.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`).join('')}}}`;
|
|
112
120
|
if (tagName === 'slot') {
|
|
113
121
|
const slotNode = {
|
|
114
122
|
type: 'element',
|
|
115
123
|
name: tagName,
|
|
116
124
|
attributes: {
|
|
117
|
-
name:
|
|
125
|
+
name: data.name.type && data.name.type !== 'static' ? `{{${id}.name}}` : data.name.value,
|
|
118
126
|
},
|
|
119
127
|
elements: [],
|
|
120
128
|
_order: xIndex || 0,
|
|
121
129
|
_parent: null,
|
|
122
130
|
};
|
|
123
|
-
if ((
|
|
131
|
+
if ((_b = directives.waIf) === null || _b === void 0 ? void 0 : _b.value) {
|
|
124
132
|
slotNode.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}._waIf`);
|
|
125
133
|
}
|
|
126
134
|
elements.push(slotNode);
|
|
127
135
|
continue;
|
|
128
136
|
}
|
|
137
|
+
const rawTag = ['slot', 'block'].includes(tagName);
|
|
129
138
|
const node = {
|
|
130
139
|
type: 'element',
|
|
131
140
|
name: tagName,
|
|
132
141
|
attributes: {
|
|
133
|
-
id:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
id: curForNodes.length < 1
|
|
143
|
+
? id
|
|
144
|
+
: `{{'${id}'${curForNodes
|
|
145
|
+
.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`)
|
|
146
|
+
.join('')}}}`,
|
|
147
|
+
style: rawTag || ((_c = componentProto === null || componentProto === void 0 ? void 0 : componentProto.meta) === null || _c === void 0 ? void 0 : _c.mustEmptyStyle) ? undefined : `{{${attrPrefix}.style}}`,
|
|
148
|
+
[(0, mp_1.getClassAttrName)(tagName)]: rawTag ? undefined : `{{${attrPrefix}.className}}`,
|
|
138
149
|
},
|
|
139
150
|
elements: [],
|
|
140
151
|
_order: xIndex || 0,
|
|
141
152
|
_parent: parent,
|
|
142
153
|
};
|
|
143
|
-
const { mustEmptyStyle } = componentProto.meta || {};
|
|
144
|
-
if (mustEmptyStyle) {
|
|
145
|
-
delete node.attributes.style;
|
|
146
|
-
}
|
|
147
154
|
if ((_d = directives.waIf) === null || _d === void 0 ? void 0 : _d.value) {
|
|
148
155
|
node.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}._waIf`);
|
|
149
156
|
}
|
|
@@ -154,7 +161,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
154
161
|
node.attributes['wx:for-index'] = wxmlDataPrefix.forIndex + id;
|
|
155
162
|
node.attributes['wx:key'] = ((_f = directives.waForKey) === null || _f === void 0 ? void 0 : _f.value) ? '_key' : '$$i';
|
|
156
163
|
}
|
|
157
|
-
const compSchema = componentProto.dataForm;
|
|
164
|
+
const compSchema = componentProto === null || componentProto === void 0 ? void 0 : componentProto.dataForm;
|
|
158
165
|
for (const prop of Object.keys(data || {})) {
|
|
159
166
|
if (compSchema) {
|
|
160
167
|
const fieldDef = compSchema[prop];
|
|
@@ -175,7 +182,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
175
182
|
// handle generic component, https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/generics.html
|
|
176
183
|
const passedComp = data[prop].value;
|
|
177
184
|
const [libName, compName] = passedComp.split(':');
|
|
178
|
-
const { tagName, path } = (0, materials_1.getWxmlTag)({ moduleName: libName, name: compName },
|
|
185
|
+
const { tagName, path } = (0, materials_1.getWxmlTag)(ctx, { moduleName: libName, name: compName }, nameMangler);
|
|
179
186
|
node.attributes[`generic:${getGenericCompTagName(prop)}`] = tagName;
|
|
180
187
|
usingComponents[tagName] = path;
|
|
181
188
|
continue;
|
|
@@ -186,28 +193,28 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
186
193
|
: `${attrPrefix}['${prop}']`;
|
|
187
194
|
xmlJsonSetCustomAttr(node, prop, getAttrBind(data[prop], widgetBind, staticResourceAttribute.includes(prop)), xComponent);
|
|
188
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* 来自外部引用的组件,添加系统系别的事件绑定
|
|
198
|
+
*/
|
|
199
|
+
if (componentGenerics[tagName] || usingComponents[tagName]) {
|
|
200
|
+
node.attributes['bind:attached'] = '__mnt__';
|
|
201
|
+
node.attributes['bind:detached'] = '__unmnt__';
|
|
202
|
+
}
|
|
189
203
|
// Event binding
|
|
190
|
-
const { inputProps, syncProps } = componentProto.meta || {};
|
|
204
|
+
const { inputProps, syncProps } = (componentProto === null || componentProto === void 0 ? void 0 : componentProto.meta) || {};
|
|
191
205
|
const syncConfigs = syncProps || inputProps || {};
|
|
192
|
-
|
|
193
|
-
const configs = Array.isArray(config) ? config : [config];
|
|
194
|
-
configs.forEach(({ changeEvent: evtName }) => {
|
|
195
|
-
// 兼容微信 7.0.13 安卓版本 textarea 组件的 bindinput 事件,bind:input 写法,事件会失效
|
|
196
|
-
const sep = getEventBindSep(tagName);
|
|
197
|
-
node.attributes[`bind${sep}${evtName}`] = getMpEventHanlderName(id, evtName);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
listeners.forEach((l) => {
|
|
201
|
-
const evtName = getMpEventName(l.trigger);
|
|
202
|
-
const modifiers = l;
|
|
203
|
-
node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
|
|
204
|
-
});
|
|
206
|
+
const processedListeners = [...(0, util_1.generateSyncListeners)(syncConfigs), ...listeners];
|
|
205
207
|
// 扩展组件配置
|
|
206
|
-
const { compConfig } = componentProto;
|
|
208
|
+
const { compConfig } = componentProto || {};
|
|
207
209
|
// 如果是数据容器,则增加一个onDataChange事件 bind:onDataChange="onid1$onDataChange"
|
|
208
210
|
if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
|
|
209
|
-
|
|
211
|
+
processedListeners.push(...(0, util_1.generateDataContainerListeners)());
|
|
210
212
|
}
|
|
213
|
+
processedListeners.forEach((l) => {
|
|
214
|
+
const evtName = getMpEventName(l.trigger);
|
|
215
|
+
const modifiers = l;
|
|
216
|
+
node.attributes[getMpEventAttr(evtName, modifiers, tagName)] = getMpEventHanlderName(id, evtName, modifiers);
|
|
217
|
+
});
|
|
211
218
|
if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.pluginConfig) {
|
|
212
219
|
if (compConfig.pluginConfig.attributes) {
|
|
213
220
|
Object.assign(node.attributes, compConfig.pluginConfig.attributes);
|
|
@@ -233,7 +240,7 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
233
240
|
}*/
|
|
234
241
|
node.elements = node.elements.concat(createXml(properties, node, curForNodes));
|
|
235
242
|
// 特殊处理 swiper,对swiper 子节点包裹议程 swiperItem
|
|
236
|
-
if (tagName === 'swiper' || componentKey === 'weda:Swiper' || componentKey ===
|
|
243
|
+
if (tagName === 'swiper' || componentKey === 'weda:Swiper' || componentKey === `${config_1.OFFICIAL_LIB_KEY}:Swiper`) {
|
|
237
244
|
node.elements = node.elements.map((item, index) => {
|
|
238
245
|
var _a, _b;
|
|
239
246
|
let { ['wx:for']: wxFor, ['wx:for-index']: wxForIndex, ['wx:key']: wxKey, ['wx:if']: wxIf, ...itemRestKey } = item.attributes || {};
|
package/lib/test.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function resolveWidgetData(props: any): any;
|
|
2
|
+
export declare function createWidgets(widgetProps: any, dataBinds: any, ownerMpInst: any): {
|
|
3
|
+
widgets: {};
|
|
4
|
+
rootWidget: any;
|
|
5
|
+
};
|
|
6
|
+
export declare function generateForContextOfWidget(widget: any): any;
|
|
7
|
+
export declare const ID_SEPARATOR = "-";
|
|
8
|
+
export declare function getWidget(widgets: any, id: any): any;
|
|
9
|
+
export declare function disposeWidget(widget: any, noRecursive?: boolean): void;
|
|
10
|
+
export declare function createInitData(widgets: any, dataBinds: any, keyPrefix?: string): {};
|
|
11
|
+
export declare function generateWidgetAPIContext($w: {} | undefined, widget: any, forContext: any): {};
|