@cloudbase/lowcode-builder 0.1.5-mpbeta.0 → 0.1.5-mpbeta.3
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/README.md +59 -0
- package/lib/builder/config/index.js +1 -5
- package/lib/builder/h5/copy.js +1 -5
- package/lib/builder/h5/material.js +1 -5
- package/lib/builder/mp/index.js +1 -5
- package/lib/builder/mp/materials.js +1 -5
- package/lib/builder/mp/mixMode.js +1 -5
- package/lib/builder/mp/mp_config.js +3 -7
- package/lib/builder/mp/plugin.js +1 -5
- package/lib/builder/mp/util.js +14 -1
- package/lib/builder/mp/wxml.js +22 -14
- package/lib/builder/util/generateFiles.js +1 -5
- package/lib/builder/util/index.js +1 -5
- package/lib/builder/util/mp.js +1 -5
- package/lib/builder/util/net.js +1 -5
- package/lib/index.js +1 -5
- package/package.json +11 -11
- package/template/mp/common/util.js +2 -2
- package/template/mp/common/weapp-component.js +3 -3
- package/template/mp/common/weapp-page.js +4 -3
- package/template/mp/common/widget.js +10 -10
- package/template/mp/component/index.js +6 -4
- package/template/mp/page/index.js +7 -4
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
## 本包说明
|
|
2
|
+
- @cloudbase/lowcode-builder是微搭用于将DSL构建为小程序和web的构建包。
|
|
3
|
+
- 例子在__tests__/build.ts下
|
|
4
|
+
- 主要是在node环境下运行。由于微信IDE的背景,提供了web构建出小程序版本的功能。两种方式如何使用见以下示例
|
|
5
|
+
|
|
6
|
+
## node端使用
|
|
7
|
+
使用示例:
|
|
8
|
+
```javascript
|
|
9
|
+
import { buildWedaApp } from '@cloudbase/lowcode-builder';
|
|
10
|
+
import { simpleData as data, options } from './data';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import fs from 'fs-extra';
|
|
13
|
+
|
|
14
|
+
const outPath = path.resolve(__dirname, '.temp');
|
|
15
|
+
fs.emptyDirSync(outPath);
|
|
16
|
+
buildWedaApp({
|
|
17
|
+
...data,
|
|
18
|
+
...options,
|
|
19
|
+
buildTypeList: ['web' as any],
|
|
20
|
+
output: { path: outPath },
|
|
21
|
+
}).then((dir) => {
|
|
22
|
+
console.log(dir);
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## web端使用
|
|
27
|
+
使用示例:
|
|
28
|
+
```javascript
|
|
29
|
+
export async function builderToZip(builderData: any, selectedPageId: string, outputPath: string) {
|
|
30
|
+
return import('@cloudbase/lowcode-builder/lib/builder.web').then(async (result) => {
|
|
31
|
+
try {
|
|
32
|
+
console.log('rose builderToZip import result ', result);
|
|
33
|
+
const { buildWedaApp, getFiles, fileToZip, strToBuf } = result;
|
|
34
|
+
|
|
35
|
+
// 1、构建到指定路径,返回构建文件存放路径
|
|
36
|
+
const buildPath = await buildWedaApp(builderData);
|
|
37
|
+
|
|
38
|
+
// 2、从指定路径获取文件
|
|
39
|
+
const files = await getFiles(buildPath, {}, `${outputPath}/`);
|
|
40
|
+
|
|
41
|
+
// 3、修改app.json入口地址
|
|
42
|
+
const finalFiles = setEntryPage(files, selectedPageId, strToBuf);
|
|
43
|
+
|
|
44
|
+
// 4、得到zip包,返回主进程,传给微信hybrid
|
|
45
|
+
const zipFiles = await fileToZip(finalFiles, 'arraybuffer'); // blob or arraybuffer
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
zipFiles,
|
|
49
|
+
strFiles: '', // TODO暂时保留,用于返回zip包内容
|
|
50
|
+
};
|
|
51
|
+
} catch (err) {
|
|
52
|
+
error('builder.worker.js->builderToZip->catch:', err);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/h5/copy.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -106,8 +102,8 @@ function generateMpConfig(weapps, ctx) {
|
|
|
106
102
|
appConfig.plugins = plugins;
|
|
107
103
|
}
|
|
108
104
|
miniprogramPlugins.forEach((plugin) => {
|
|
109
|
-
var _a;
|
|
110
|
-
if (!((_a = appConfig === null ||
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if (!((_b = (_a = appConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b[plugin.name])) {
|
|
111
107
|
(0, lodash_1.set)(appConfig, `plugins.${plugin.name}`, {
|
|
112
108
|
version: plugin.version,
|
|
113
109
|
provider: plugin.pluginAppId,
|
package/lib/builder/mp/plugin.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -111,7 +111,7 @@ exports.createWidgetProps = createWidgetProps;
|
|
|
111
111
|
function createEventHanlders(widgets, componentApi, ctx) {
|
|
112
112
|
const eventHanlders = {};
|
|
113
113
|
(0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
|
|
114
|
-
var _a, _b;
|
|
114
|
+
var _a, _b, _c;
|
|
115
115
|
const { xComponent } = widget;
|
|
116
116
|
const xProps = widget.xProps || {};
|
|
117
117
|
if (!xComponent) {
|
|
@@ -175,6 +175,19 @@ function createEventHanlders(widgets, componentApi, ctx) {
|
|
|
175
175
|
type: l.type,
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
|
+
// 如果是数据容器,则生成一个onDataChange事件处理
|
|
179
|
+
if ((_c = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _c === void 0 ? void 0 : _c.isDataContainer) {
|
|
180
|
+
const customName = (0, wxml_1.getMpEventHanlderName)(id, 'onDataChange', {});
|
|
181
|
+
eventHanlders[customName] = [{
|
|
182
|
+
key: '',
|
|
183
|
+
handler: `({event})=>{
|
|
184
|
+
app.utils.set(context, '${id}.data', event?.detail?.data);
|
|
185
|
+
}`,
|
|
186
|
+
handlerModule: weapps_core_1.ActionType.Platform,
|
|
187
|
+
data: {},
|
|
188
|
+
boundData: {},
|
|
189
|
+
}];
|
|
190
|
+
}
|
|
178
191
|
});
|
|
179
192
|
return eventHanlders;
|
|
180
193
|
}
|
package/lib/builder/mp/wxml.js
CHANGED
|
@@ -101,8 +101,20 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
101
101
|
else if (path) {
|
|
102
102
|
usingComponents[tagName] = path;
|
|
103
103
|
}
|
|
104
|
+
let curForNodes = parentForNodes;
|
|
105
|
+
if (directives.waFor && directives.waFor.value) {
|
|
106
|
+
curForNodes = [...curForNodes, id];
|
|
107
|
+
}
|
|
108
|
+
const attrPrefix = `${wxmlDataPrefix.widgetProp}${id}${curForNodes
|
|
109
|
+
.map((forNodeId) => `[${wxmlDataPrefix.forIndex}${forNodeId}]`)
|
|
110
|
+
.join('')}`;
|
|
111
|
+
const idAttr = curForNodes.length < 1
|
|
112
|
+
? id
|
|
113
|
+
: `{{'${id}'${curForNodes
|
|
114
|
+
.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`)
|
|
115
|
+
.join('')}}}`;
|
|
104
116
|
if (tagName === 'slot') {
|
|
105
|
-
|
|
117
|
+
const slotNode = {
|
|
106
118
|
type: 'element',
|
|
107
119
|
name: tagName,
|
|
108
120
|
attributes: {
|
|
@@ -113,21 +125,13 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
113
125
|
elements: [],
|
|
114
126
|
_order: xIndex || 0,
|
|
115
127
|
_parent: null,
|
|
116
|
-
}
|
|
128
|
+
};
|
|
129
|
+
if (directives.waIf && directives.waIf.value) {
|
|
130
|
+
slotNode.attributes['wx:if'] = getAttrBind(directives.waIf, `${attrPrefix}_waIf`);
|
|
131
|
+
}
|
|
132
|
+
elements.push(slotNode);
|
|
117
133
|
continue;
|
|
118
134
|
}
|
|
119
|
-
let curForNodes = parentForNodes;
|
|
120
|
-
if (directives.waFor && directives.waFor.value) {
|
|
121
|
-
curForNodes = [...curForNodes, id];
|
|
122
|
-
}
|
|
123
|
-
const attrPrefix = `${wxmlDataPrefix.widgetProp}${id}${curForNodes
|
|
124
|
-
.map((forNodeId) => `[${wxmlDataPrefix.forIndex}${forNodeId}]`)
|
|
125
|
-
.join('')}`;
|
|
126
|
-
const idAttr = curForNodes.length < 1
|
|
127
|
-
? id
|
|
128
|
-
: `{{'${id}'${curForNodes
|
|
129
|
-
.map((forNodeId) => `+ '-' + ${wxmlDataPrefix.forIndex}${forNodeId}`)
|
|
130
|
-
.join('')}}}`;
|
|
131
135
|
const node = {
|
|
132
136
|
type: 'element',
|
|
133
137
|
name: tagName,
|
|
@@ -205,6 +209,10 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
|
|
|
205
209
|
});
|
|
206
210
|
// 扩展组件配置
|
|
207
211
|
const compConfig = componentProto.compConfig;
|
|
212
|
+
// 如果是数据容器,则增加一个onDataChange事件 bind:onDataChange="onid1$onDataChange"
|
|
213
|
+
if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
|
|
214
|
+
node.attributes['bind:onDataChange'] = getMpEventHanlderName(id, 'onDataChange');
|
|
215
|
+
}
|
|
208
216
|
if (compConfig && compConfig.pluginConfig) {
|
|
209
217
|
if (compConfig.pluginConfig.attributes) {
|
|
210
218
|
Object.assign(node.attributes, compConfig.pluginConfig.attributes);
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/util/mp.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/builder/util/net.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.1.5-mpbeta.
|
|
3
|
+
"version": "0.1.5-mpbeta.3",
|
|
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",
|
|
@@ -25,29 +25,28 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "tsc -w",
|
|
27
27
|
"develop": "tsc -w",
|
|
28
|
-
"build": "rm -rf lib && tsc",
|
|
28
|
+
"build": "rm -rf lib && tsc && npm run build:web",
|
|
29
29
|
"test": "jest",
|
|
30
30
|
"test:build": "ts-node ./__test__/build.ts",
|
|
31
|
-
"dev:
|
|
32
|
-
"build:
|
|
33
|
-
"prepublish": "npm run build"
|
|
31
|
+
"dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
|
|
32
|
+
"build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js"
|
|
34
33
|
},
|
|
35
34
|
"bugs": {
|
|
36
35
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
38
|
"@cloudbase/cals": "^0.3.3",
|
|
40
|
-
"@cloudbase/lowcode-generator": "0.6.17-mpbeta.
|
|
39
|
+
"@cloudbase/lowcode-generator": "0.6.17-mpbeta.1",
|
|
41
40
|
"axios": "^0.21.0",
|
|
42
41
|
"browserfs": "^1.4.3",
|
|
43
42
|
"browserify-zlib": "^0.2.0",
|
|
44
43
|
"chalk": "^2.4.2",
|
|
45
44
|
"compare-versions": "^3.6.0",
|
|
46
45
|
"compressing": "^1.4.0",
|
|
47
|
-
"cross-spawn": "^6.0.5",
|
|
48
|
-
"fs-extra": "^7.0.1",
|
|
49
46
|
"constants-browserify": "^1.0.0",
|
|
47
|
+
"cross-spawn": "^6.0.5",
|
|
50
48
|
"crypto-browserify": "^3.12.0",
|
|
49
|
+
"fs-extra": "^7.0.1",
|
|
51
50
|
"jszip": "^3.7.1",
|
|
52
51
|
"lodash": "^4.17.11",
|
|
53
52
|
"lodash.clone": "^4.5.0",
|
|
@@ -61,7 +60,6 @@
|
|
|
61
60
|
"xml-js": "^1.6.11"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
|
-
"worker-loader": "^3.0.8",
|
|
65
63
|
"@rollup/plugin-alias": "^3.1.9",
|
|
66
64
|
"@types/archiver": "^3.1.0",
|
|
67
65
|
"@types/command-exists": "^1.2.0",
|
|
@@ -79,7 +77,9 @@
|
|
|
79
77
|
"ts-loader": "^8.3.0",
|
|
80
78
|
"ts-node": "^10.4.0",
|
|
81
79
|
"typescript": "^4.4.2",
|
|
80
|
+
"uglifyjs-webpack-plugin": "^2.2.0",
|
|
82
81
|
"webpack-cli": "^4.9.1",
|
|
83
|
-
"webpack-dev-server": "^4.7.3"
|
|
82
|
+
"webpack-dev-server": "^4.7.3",
|
|
83
|
+
"worker-loader": "^3.0.8"
|
|
84
84
|
}
|
|
85
|
-
}
|
|
85
|
+
}
|
|
@@ -27,7 +27,7 @@ export function createComputed(funcs, bindContext = null) {
|
|
|
27
27
|
return computed
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export function createEventHandlers(evtListeners) {
|
|
30
|
+
export function createEventHandlers(evtListeners, context) {
|
|
31
31
|
const evtHandlers = {}
|
|
32
32
|
for (const name in evtListeners) {
|
|
33
33
|
const listeners = evtListeners[name]
|
|
@@ -45,7 +45,7 @@ export function createEventHandlers(evtListeners) {
|
|
|
45
45
|
let { data = {}, boundData = {} } = l
|
|
46
46
|
data = { ...data }
|
|
47
47
|
for (const k in boundData) {
|
|
48
|
-
set(data, k, boundData[k].call(owner, owner, lists, itemsById, event))
|
|
48
|
+
set(data, k, boundData[k].call(owner, owner, lists, itemsById, event, context))
|
|
49
49
|
}
|
|
50
50
|
try {
|
|
51
51
|
let res = await l.handler.call(owner, { event, lists, forItems: itemsById, data })
|
|
@@ -10,7 +10,7 @@ import sdk from './weapp-sdk'
|
|
|
10
10
|
*/
|
|
11
11
|
export const compLowcodes = {}
|
|
12
12
|
|
|
13
|
-
export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes) {
|
|
13
|
+
export function createComponent(key, behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps, index, lifeCycle, stateFn, computedFuncs, config, libCommonRes, undefined, context) {
|
|
14
14
|
|
|
15
15
|
compLowcodes[key] = {
|
|
16
16
|
index,
|
|
@@ -56,7 +56,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
56
56
|
|
|
57
57
|
$comp.props.events = createPropEvents(events, this)
|
|
58
58
|
$comp.widgets = {}
|
|
59
|
-
const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, $comp.widgets, this)
|
|
59
|
+
const { widgets, rootWidget: virtualRootWidget } = createWidgets(widgetProps, dataBinds, $comp.widgets, context, this)
|
|
60
60
|
this._virtualRootWidget = virtualRootWidget
|
|
61
61
|
|
|
62
62
|
try {
|
|
@@ -104,7 +104,7 @@ export function createComponent(key, behaviors, properties, events, handler, dat
|
|
|
104
104
|
},
|
|
105
105
|
|
|
106
106
|
methods: {
|
|
107
|
-
...createEventHandlers(evtListeners),
|
|
107
|
+
...createEventHandlers(evtListeners, context),
|
|
108
108
|
...mergeRenderer,
|
|
109
109
|
getWeAppInst() {
|
|
110
110
|
const $comp = this.$WEAPPS_COMP
|
|
@@ -17,9 +17,10 @@ export function createPage(
|
|
|
17
17
|
dataBinds,
|
|
18
18
|
app,
|
|
19
19
|
handler,
|
|
20
|
-
pageContext = {}
|
|
20
|
+
pageContext = {},
|
|
21
|
+
context
|
|
21
22
|
) {
|
|
22
|
-
const evtHandlers = createEventHandlers(evtListeners);
|
|
23
|
+
const evtHandlers = createEventHandlers(evtListeners, context);
|
|
23
24
|
|
|
24
25
|
function extractLifecyles() {
|
|
25
26
|
const result = { };
|
|
@@ -144,7 +145,7 @@ export function createPage(
|
|
|
144
145
|
});
|
|
145
146
|
};
|
|
146
147
|
|
|
147
|
-
const { rootWidget } = createWidgets(widgetProps, dataBinds, $page.widgets, this)
|
|
148
|
+
const { rootWidget } = createWidgets(widgetProps, dataBinds, $page.widgets, context, this)
|
|
148
149
|
$page._rootWidget = rootWidget
|
|
149
150
|
|
|
150
151
|
return $page
|
|
@@ -35,10 +35,10 @@ export function resolveWidgetData(props) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
export function createWidgets(widgetProps, dataBinds, widgetHolder, ownerMpInst) {
|
|
38
|
+
export function createWidgets(widgetProps, dataBinds, widgetHolder, context, ownerMpInst) {
|
|
39
39
|
const rootNode = createWidgetDataTree(widgetProps, dataBinds)
|
|
40
40
|
const failedBinds = []
|
|
41
|
-
const result = createSubWidgetTree(rootNode, widgetProps, dataBinds, ownerMpInst, widgetHolder, 0, {}, null, failedBinds)
|
|
41
|
+
const result = createSubWidgetTree(rootNode, widgetProps, dataBinds, ownerMpInst, widgetHolder, 0, {}, null, failedBinds, undefined, context)
|
|
42
42
|
retryFailedBinds(failedBinds, true)
|
|
43
43
|
return result
|
|
44
44
|
}
|
|
@@ -51,7 +51,7 @@ export function createWidgets(widgetProps, dataBinds, widgetHolder, ownerMpInst)
|
|
|
51
51
|
*/
|
|
52
52
|
function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, widgetHolder = {},
|
|
53
53
|
index = 0, forItems = {}, ownerForWidgetHolder = null,
|
|
54
|
-
failedBinds = [], defaultParent = { children: observable([]), _disposers: [] }) {
|
|
54
|
+
failedBinds = [], defaultParent = { children: observable([]), _disposers: [] }, context) {
|
|
55
55
|
const indexPostfix = (forItems.lists || []).slice().reverse().map(list => idSeparator + list.currentIndex).join('')
|
|
56
56
|
|
|
57
57
|
// traverse down the tree to set up all widgets
|
|
@@ -75,7 +75,7 @@ function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, wi
|
|
|
75
75
|
} else {
|
|
76
76
|
disposeWidget(existedWidget, true)
|
|
77
77
|
}
|
|
78
|
-
setUpWidgetDataBinds(w, dataBinds[node.id], forItems, failedBinds, ownerMpInst.getWeAppInst())
|
|
78
|
+
setUpWidgetDataBinds(w, dataBinds[node.id], forItems, failedBinds, ownerMpInst.getWeAppInst(), context)
|
|
79
79
|
widgetHolder[node.id] = w
|
|
80
80
|
} else if (!existedWidget) {
|
|
81
81
|
const len = parentForWidgetArr.push(observable([]))
|
|
@@ -91,7 +91,7 @@ function createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, wi
|
|
|
91
91
|
if (node.forCount === curForNode.forCount + 1 && dataBinds[node.id] && dataBinds[node.id]._waFor) {
|
|
92
92
|
// find the node bound with next level for
|
|
93
93
|
const parent = node.parent ? widgetHolder[node.parent.id] : defaultParent
|
|
94
|
-
const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forItems, widgetHolder, failedBinds, parent)
|
|
94
|
+
const dispose = runFor(node, widgetProps, dataBinds, ownerMpInst, forItems, widgetHolder, failedBinds, parent, context)
|
|
95
95
|
parent._disposers.push(dispose) // Add the for bind dispose to the parent node of forNode
|
|
96
96
|
}
|
|
97
97
|
})
|
|
@@ -119,12 +119,12 @@ function retryFailedBinds(failedBinds, finalTry) {
|
|
|
119
119
|
* @param {*} parentWidget
|
|
120
120
|
* @returns top level widgets or for dispose
|
|
121
121
|
*/
|
|
122
|
-
function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, ownerForWidgetHolder, failedBinds, defaultParent) {
|
|
122
|
+
function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, ownerForWidgetHolder, failedBinds, defaultParent, context) {
|
|
123
123
|
const nodeId = curForNode.id
|
|
124
124
|
const dispose = autorun(() => {
|
|
125
125
|
let forList = []
|
|
126
126
|
try {
|
|
127
|
-
forList = dataBinds[nodeId]._waFor.call(ownerMpInst.getWeAppInst(), ownerMpInst.getWeAppInst(), forItems.lists, forItems.itemsById)
|
|
127
|
+
forList = dataBinds[nodeId]._waFor.call(ownerMpInst.getWeAppInst(), ownerMpInst.getWeAppInst(), forItems.lists, forItems.itemsById, undefined, context)
|
|
128
128
|
if (!Array.isArray(forList)) {
|
|
129
129
|
forList = []
|
|
130
130
|
}
|
|
@@ -162,7 +162,7 @@ function runFor(curForNode, widgetProps, dataBinds, ownerMpInst, forItems, owner
|
|
|
162
162
|
lists: [{ currentItem: item, currentIndex: index }, ...lists],
|
|
163
163
|
itemsById: { ...itemsById, [nodeId]: item },
|
|
164
164
|
}
|
|
165
|
-
const { rootWidget } = createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, {}, index, _forItems, ownerForWidgetHolder, failedBinds, defaultParent)
|
|
165
|
+
const { rootWidget } = createSubWidgetTree(curForNode, widgetProps, dataBinds, ownerMpInst, {}, index, _forItems, ownerForWidgetHolder, failedBinds, defaultParent, context)
|
|
166
166
|
rootWidget._forItems = _forItems
|
|
167
167
|
})
|
|
168
168
|
})
|
|
@@ -198,7 +198,7 @@ function createAWidget(props, id, parent, ownerMpInst) {
|
|
|
198
198
|
return w
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
|
|
201
|
+
function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx, context) {
|
|
202
202
|
Object.keys(dataBinds || {}).map(prop => {
|
|
203
203
|
if (prop === '_waFor') { return }
|
|
204
204
|
const setUpDataBind = (isFinalTry) => {
|
|
@@ -207,7 +207,7 @@ function setUpWidgetDataBinds(w, dataBinds, forItems, failedBinds, ctx) {
|
|
|
207
207
|
const dispose = autorun((reaction) => {
|
|
208
208
|
try {
|
|
209
209
|
// Computed data bind in the next tick since data bind may read widgets data
|
|
210
|
-
w[prop] = dataBinds[prop].call(ctx,ctx,forItems.lists, forItems.itemsById)
|
|
210
|
+
w[prop] = dataBinds[prop].call(ctx,ctx,forItems.lists, forItems.itemsById, undefined, context)
|
|
211
211
|
} catch (e) {
|
|
212
212
|
if (prop === '_waIf') {
|
|
213
213
|
w[prop] = false
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observable } from 'mobx';
|
|
1
2
|
import { createComponent } from '../../../common/weapp-component'
|
|
2
3
|
import { concatClassList, px2rpx } from '../../../common/style'
|
|
3
4
|
import app from '../../../common/weapp-sdk'
|
|
@@ -11,6 +12,7 @@ import * as constObj from '../libCommonRes/const'
|
|
|
11
12
|
import * as toolsObj from '../libCommonRes/tools'
|
|
12
13
|
|
|
13
14
|
const libCode = '<%= materialName %>'
|
|
15
|
+
const context = observable({});
|
|
14
16
|
|
|
15
17
|
const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
|
|
16
18
|
|
|
@@ -18,9 +20,9 @@ const evtListeners = {<% Object.entries(eventHandlers).map(([handlerName, listen
|
|
|
18
20
|
<%= handlerName%>: [
|
|
19
21
|
<%listeners.map(l=> { %>{
|
|
20
22
|
key: '<%= l.key %>',
|
|
21
|
-
handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
|
|
23
|
+
handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems, $context}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
|
|
22
24
|
data: <%= stringifyObj(l.data, {depth: null}) %>,
|
|
23
|
-
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event) => {const $for=forItems;return (
|
|
25
|
+
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event, $context) => {const $for=forItems;return (
|
|
24
26
|
<%= expr %>
|
|
25
27
|
)},
|
|
26
28
|
<%}) %>}
|
|
@@ -50,7 +52,7 @@ const handler = {<% handlers.forEach(h => {%>
|
|
|
50
52
|
|
|
51
53
|
const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
52
54
|
<%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
|
|
53
|
-
<%= prop %>: function ($comp, lists, forItems, event) {const $for=forItems; return (
|
|
55
|
+
<%= prop %>: function ($comp, lists, forItems, event, $context) {const $for=forItems; return (
|
|
54
56
|
<%= expr %>
|
|
55
57
|
); },<% }) %>
|
|
56
58
|
},<%}) %>
|
|
@@ -59,4 +61,4 @@ const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
|
59
61
|
const config = <%= JSON.stringify(config || {})%>
|
|
60
62
|
|
|
61
63
|
createComponent('<%= key %>', behaviors, properties, events, handler, dataBinds, evtListeners, widgetProps,
|
|
62
|
-
index, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode)
|
|
64
|
+
index, lifeCycle, stateFn, computedFuncs, config, { const: constObj, tools: toolsObj }, libCode, context)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observable } from 'mobx';
|
|
1
2
|
import { createPage } from '<%= subLevelPath %>../../common/weapp-page'
|
|
2
3
|
import { concatClassList, px2rpx } from '<%= subLevelPath %>../../common/style'
|
|
3
4
|
import { app } from '<%= subLevelPath %>../../app/weapps-api'
|
|
@@ -7,7 +8,9 @@ import lifecyle from '../../lowcode/<%= pageName %>/lifecycle'
|
|
|
7
8
|
import state from '../../lowcode/<%= pageName %>/state'
|
|
8
9
|
import computed from '../../lowcode/<%= pageName %>/computed'
|
|
9
10
|
import { $page } from './api'
|
|
11
|
+
|
|
10
12
|
const $app = app;
|
|
13
|
+
const context = observable({});
|
|
11
14
|
|
|
12
15
|
const widgetProps = <%= stringifyObj(widgetProps, {depth: null}) %>
|
|
13
16
|
/** widget event listeners **/
|
|
@@ -15,9 +18,9 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
|
|
|
15
18
|
<%= handlerName%>: [
|
|
16
19
|
<%listeners.map(l=> { %>{
|
|
17
20
|
key: '<%= l.key %>',
|
|
18
|
-
handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems}, $page){const $for = forItems; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
|
|
21
|
+
handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems, $context}, $page){const $for = forItems; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
|
|
19
22
|
data: <%= stringifyObj(l.data, {depth: null}) %>,
|
|
20
|
-
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event) => {const $for = forItems; return (
|
|
23
|
+
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event, $context) => {const $for = forItems; return (
|
|
21
24
|
<%= expr %>
|
|
22
25
|
)},
|
|
23
26
|
<%}) %>}
|
|
@@ -26,10 +29,10 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
|
|
|
26
29
|
}
|
|
27
30
|
const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
28
31
|
<%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
|
|
29
|
-
<%= prop %>: function ($page, lists, forItems, event) {const $for = forItems; return (
|
|
32
|
+
<%= prop %>: function ($page, lists, forItems, event, $context) {const $for = forItems; return (
|
|
30
33
|
<%= expr %>
|
|
31
34
|
); },<% }) %>
|
|
32
35
|
},<%}) %>
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
createPage('<%= pageName %>', '<%= pageUUID %>', widgetProps, {}, lifecyle, state, computed, evtListeners, dataBinds, app, handlers, $page)
|
|
38
|
+
createPage('<%= pageName %>', '<%= pageUUID %>', widgetProps, {}, lifecyle, state, computed, evtListeners, dataBinds, app, handlers, $page, context)
|