@cloudbase/lowcode-builder 1.2.3 → 1.3.0
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 +163 -61
- package/lib/builder/mp/wxml.d.ts +4 -4
- package/lib/builder/mp/wxml.js +67 -60
- 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 +81 -83
- package/template/mp/common/watch.js +1 -1
- package/template/mp/common/weapp-component.js +52 -43
- package/template/mp/common/weapp-page.js +89 -84
- package/template/mp/common/widget.js +236 -58
- package/template/mp/component/index.js +4 -5
- package/template/mp/package.json +1 -1
- package/template/mp/page/api.js +21 -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
|
@@ -24,3 +24,11 @@ export interface ICDN_ENDPOINTS_COFIG {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const CDN_ENDPONTS_CONFIG: ICDN_ENDPOINTS_COFIG;
|
|
26
26
|
export declare function generateCdnEndpoints(endpoints?: ICDN_ENDPOINTS_COFIG): ICDN_ENDPOINTS_COFIG;
|
|
27
|
+
/**
|
|
28
|
+
* 循环组件的信息
|
|
29
|
+
*/
|
|
30
|
+
export declare const REPEATER: {
|
|
31
|
+
MODULE_NAME: string;
|
|
32
|
+
REPEATER_NAME: string;
|
|
33
|
+
REPEATER_ITEM_NAME: string;
|
|
34
|
+
};
|
|
@@ -26,17 +26,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.generateCdnEndpoints = exports.CDN_ENDPONTS_CONFIG = exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
|
|
29
|
+
exports.REPEATER = exports.generateCdnEndpoints = exports.CDN_ENDPONTS_CONFIG = exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const os_1 = __importDefault(require("os"));
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Object.defineProperty(exports, "
|
|
35
|
-
Object.defineProperty(exports, "
|
|
36
|
-
Object.defineProperty(exports, "
|
|
37
|
-
Object.defineProperty(exports, "
|
|
38
|
-
Object.defineProperty(exports, "
|
|
39
|
-
Object.defineProperty(exports, "
|
|
32
|
+
const index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
|
|
33
|
+
var index_2 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
|
|
34
|
+
Object.defineProperty(exports, "REPLACE_SIGN", { enumerable: true, get: function () { return index_2.REPLACE_SIGN; } });
|
|
35
|
+
Object.defineProperty(exports, "MP_CONFIG_MODULE_NAME", { enumerable: true, get: function () { return index_2.MP_CONFIG_MODULE_NAME; } });
|
|
36
|
+
Object.defineProperty(exports, "KBONE_PAGE_KEYS", { enumerable: true, get: function () { return index_2.KBONE_PAGE_KEYS; } });
|
|
37
|
+
Object.defineProperty(exports, "npmRegistry", { enumerable: true, get: function () { return index_2.npmRegistry; } });
|
|
38
|
+
Object.defineProperty(exports, "remConfig", { enumerable: true, get: function () { return index_2.remConfig; } });
|
|
39
|
+
Object.defineProperty(exports, "rpxConfig", { enumerable: true, get: function () { return index_2.rpxConfig; } });
|
|
40
|
+
Object.defineProperty(exports, "OFFICIAL_LIB_KEY", { enumerable: true, get: function () { return index_2.OFFICIAL_LIB_KEY; } });
|
|
40
41
|
exports.sharedMaterialsDir = path.join(os_1.default.homedir(), '.weapps-materials');
|
|
41
42
|
exports.appTemplateDir = path.resolve(__dirname, '../../../template');
|
|
42
43
|
exports.materialsDirName = 'materials'; // materials diretory of current project
|
|
@@ -69,3 +70,11 @@ function generateCdnEndpoints(endpoints = exports.CDN_ENDPONTS_CONFIG) {
|
|
|
69
70
|
return endpoints;
|
|
70
71
|
}
|
|
71
72
|
exports.generateCdnEndpoints = generateCdnEndpoints;
|
|
73
|
+
/**
|
|
74
|
+
* 循环组件的信息
|
|
75
|
+
*/
|
|
76
|
+
exports.REPEATER = {
|
|
77
|
+
MODULE_NAME: index_1.OFFICIAL_LIB_KEY,
|
|
78
|
+
REPEATER_NAME: 'Repeater',
|
|
79
|
+
REPEATER_ITEM_NAME: 'RepeaterItem',
|
|
80
|
+
};
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -61,11 +61,15 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
61
61
|
console.time(operationLabel);
|
|
62
62
|
console.log(`Generating ${em('Wexin MiniProgram')} to ${projDir}`);
|
|
63
63
|
const { allAppUsedComps } = handleUsedComponents({ buildContext, weapps });
|
|
64
|
+
/**
|
|
65
|
+
* 修改 buildContext 进行 miniprogramPlugins 精简
|
|
66
|
+
* 应该提前处理,不应该修改 buildContext
|
|
67
|
+
*/
|
|
64
68
|
buildContext.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => allAppUsedComps[plugin.name]);
|
|
65
69
|
// 安装依赖库,生成 materials 目录
|
|
66
|
-
await (0, materials_1.installMaterials)(projDir, allAppUsedComps, weapps
|
|
70
|
+
await (0, materials_1.installMaterials)(buildContext, projDir, allAppUsedComps, weapps);
|
|
67
71
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
|
|
68
|
-
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(
|
|
72
|
+
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(buildContext, weapps, { mpAppId: options.mpAppId });
|
|
69
73
|
// #1 generate project files
|
|
70
74
|
if (!mainAppData.mpPkgUrl) {
|
|
71
75
|
const projectFileData = {
|
|
@@ -79,11 +83,11 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
79
83
|
const projectConfigJsonPath = path_1.default.join(projDir, mainAppData.rootPath || '', 'project.config.json');
|
|
80
84
|
let projectConfigJson = await fs.readJSON(projectConfigJsonPath);
|
|
81
85
|
const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
|
|
82
|
-
await generateFramework(mainAppData, miniprogramRoot
|
|
86
|
+
await generateFramework(buildContext, mainAppData, miniprogramRoot);
|
|
83
87
|
// #3 生成主包根路径文件
|
|
84
88
|
let appFileData = {};
|
|
85
89
|
if (weapps.find((item) => !item.mpPkgUrl)) {
|
|
86
|
-
await generateFramework(mainAppData, miniprogramRoot
|
|
90
|
+
await generateFramework(buildContext, mainAppData, miniprogramRoot);
|
|
87
91
|
// 有了 framework app 之后,并且是源码的方式,追加 app 引用
|
|
88
92
|
if (mainAppData.mpPkgUrl) {
|
|
89
93
|
let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
|
|
@@ -101,7 +105,6 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
101
105
|
},
|
|
102
106
|
'common/widget.js': {},
|
|
103
107
|
'common/url.js': {},
|
|
104
|
-
'common/weapp-sdk.js': {},
|
|
105
108
|
'common/weapp-page.js': {
|
|
106
109
|
dataPropNames: wxmlDataPrefix,
|
|
107
110
|
debug: buildContext.debugMode,
|
|
@@ -111,10 +114,16 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
111
114
|
dataPropNames: wxmlDataPrefix,
|
|
112
115
|
debug: buildContext.debugMode,
|
|
113
116
|
},
|
|
114
|
-
'common/process.js': {},
|
|
115
117
|
'common/data-patch.js': {},
|
|
116
118
|
'common/event-emitter.js': {},
|
|
117
119
|
'common/watch.js': {},
|
|
120
|
+
'common/constant.js': {
|
|
121
|
+
REPEATER: JSON.stringify(config_1.REPEATER, undefined, 2),
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* 调试用
|
|
125
|
+
*/
|
|
126
|
+
// 'common/behaviors.js': {},
|
|
118
127
|
};
|
|
119
128
|
}
|
|
120
129
|
if (mainAppData.mpPkgUrl) {
|
|
@@ -201,7 +210,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
201
210
|
rootPath: app.rootPath,
|
|
202
211
|
};
|
|
203
212
|
await generatePkg(subpackageBuildCtx, app, subpackageRootPath, pageConfigs[index]);
|
|
204
|
-
await generateFramework(app, subpackageRootPath
|
|
213
|
+
await generateFramework(subpackageBuildCtx, app, subpackageRootPath);
|
|
205
214
|
// 生成package.json
|
|
206
215
|
let packageJsonPath = path_1.default.join(subpackageRootPath, 'package.json');
|
|
207
216
|
if (!fs.existsSync(packageJsonPath)) {
|
|
@@ -297,18 +306,21 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
297
306
|
const rootPath = weapp.rootPath || '';
|
|
298
307
|
const usingComponents = {};
|
|
299
308
|
const componentGenerics = {};
|
|
300
|
-
const
|
|
309
|
+
const componentInstances = (0, util_2.processRepeaterSchema)(ctx, page.componentInstances);
|
|
310
|
+
const wxml = (0, wxml_1.generateWxml)({ ...ctx, rootPath, isPage: true }, componentInstances, `Page ${rootPath ? path_1.default.join(rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, usingComponents, componentGenerics);
|
|
301
311
|
const importor = (0, util_3.generateLowcodeImportor)(page.lowCodes);
|
|
302
312
|
const pageFileName = (0, lodash_1.get)(pageConfigs, `${page.id}.pageFileName`, 'index');
|
|
303
313
|
const pageFileData = {
|
|
304
|
-
[`api.js|api.js`]: {
|
|
314
|
+
[`api.js|api.js`]: {
|
|
315
|
+
subLevelPath: rootPath ? `${path_1.default.posix.relative(rootPath, '')}/` : '',
|
|
316
|
+
},
|
|
305
317
|
[`index.js|${pageFileName}.js`]: {
|
|
306
|
-
widgetProps: (0, util_2.createWidgetProps)(ctx,
|
|
318
|
+
widgetProps: (0, util_2.createWidgetProps)(ctx, componentInstances),
|
|
307
319
|
pageUUID: rootPath ? `${rootPath}/${page.id}` : page.id,
|
|
308
320
|
pageName: page.id,
|
|
309
321
|
pageSource: page.data.src || '',
|
|
310
|
-
eventHanlders: (0, util_2.createEventHanlders)(ctx,
|
|
311
|
-
dataBinds: (0, util_2.createDataBinds)(ctx,
|
|
322
|
+
eventHanlders: (0, util_2.createEventHanlders)(ctx, componentInstances, 'this', page),
|
|
323
|
+
dataBinds: (0, util_2.createDataBinds)(ctx, componentInstances),
|
|
312
324
|
pageAttributes: {
|
|
313
325
|
...(((_a = page.data) === null || _a === void 0 ? void 0 : _a.appShareMessage) ? { appShareMessage: page.data.appShareMessage.value } : {}),
|
|
314
326
|
},
|
|
@@ -323,7 +335,6 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
323
335
|
extra: getAppendableJson(pageConfigs[page.id]),
|
|
324
336
|
},
|
|
325
337
|
[`index.wxml|${pageFileName}.wxml`]: {
|
|
326
|
-
// raw: JSON.stringify(page.componentInstances),
|
|
327
338
|
content: wxml,
|
|
328
339
|
},
|
|
329
340
|
[`index.wxss|${pageFileName}.wxss`]: {
|
|
@@ -343,7 +354,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
343
354
|
await writeLowCodeFiles(ctx, weapp, appRoot);
|
|
344
355
|
}
|
|
345
356
|
}
|
|
346
|
-
async function generateFramework(appData, outDir
|
|
357
|
+
async function generateFramework(ctx, appData, outDir) {
|
|
347
358
|
let fileData = {};
|
|
348
359
|
if (appData.mpPkgUrl) {
|
|
349
360
|
if (!appData.rootPath) {
|
|
@@ -19,10 +19,7 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
|
|
|
19
19
|
const baseDir = path_1.default.relative(path_1.default.dirname(file), appDir).replace(/\\/g, '/');
|
|
20
20
|
// 子包混合模式需要添加相对索引到根目录
|
|
21
21
|
const relativeRoot = (ctx === null || ctx === void 0 ? void 0 : ctx.isMixMode) && ctx.rootPath ? `${path_1.default.relative(ctx.rootPath, '')}/` : '';
|
|
22
|
-
let weappsApiPrefix = [
|
|
23
|
-
`import { app, process } from '${relativeRoot}${baseDir}/app/weapps-api';`,
|
|
24
|
-
'const $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});',
|
|
25
|
-
]; // windows compatibility
|
|
22
|
+
let weappsApiPrefix = [`import { app, $app, $w } from '${relativeRoot}${baseDir}/app/weapps-api';`]; // windows compatibility
|
|
26
23
|
if (pageId !== 'global') {
|
|
27
24
|
weappsApiPrefix.push(`import { $page } from '${baseDir}/pages/${pageId}/api'`);
|
|
28
25
|
}
|
|
@@ -30,7 +27,7 @@ async function writeCode2file(ctx, mod, lowcodeRootDir, opts = {}, themeCode) {
|
|
|
30
27
|
}
|
|
31
28
|
else {
|
|
32
29
|
// Generate component lowcode
|
|
33
|
-
code = `import
|
|
30
|
+
code = `import { app, $app, $w } from '${mod.type === 'handler-fn' ? '../' : ''}../../../../app/weapps-api';\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
@@ -2,7 +2,7 @@ import { IMaterialItem, ICompositedComponent, IWeAppComponentInstance, IWeAppDat
|
|
|
2
2
|
import { IBuildContext } from './BuildContext';
|
|
3
3
|
import NameMangler from '@cloudbase/lowcode-generator/lib/generator/util/name-mangler';
|
|
4
4
|
import { IUsedComps } from '../types/common';
|
|
5
|
-
export declare function installMaterials(projDir: string, usedComps: IUsedComps, weapps: IWeAppData[]
|
|
5
|
+
export declare function installMaterials(ctx: IBuildContext, projDir: string, usedComps: IUsedComps, weapps: IWeAppData[]): Promise<void>;
|
|
6
6
|
/**
|
|
7
7
|
* 过滤组件库文件
|
|
8
8
|
* @param src 源文件
|
|
@@ -18,7 +18,7 @@ export declare function extractUsedCompsRecursively(comps: IUsedComps, checkedCo
|
|
|
18
18
|
* }
|
|
19
19
|
* }
|
|
20
20
|
*/
|
|
21
|
-
export declare function getWxmlTag(cmp: Required<IWeAppComponentInstance>['xComponent'],
|
|
21
|
+
export declare function getWxmlTag(ctx: IBuildContext, cmp: Required<IWeAppComponentInstance>['xComponent'], nameMangler?: NameMangler): {
|
|
22
22
|
tagName: string;
|
|
23
23
|
path?: undefined;
|
|
24
24
|
} | {
|
|
@@ -39,7 +39,7 @@ const net_1 = require("../util/net");
|
|
|
39
39
|
const junk = __importStar(require("../util/junk"));
|
|
40
40
|
const cals_1 = require("@cloudbase/cals");
|
|
41
41
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
42
|
-
async function installMaterials(projDir, usedComps, weapps
|
|
42
|
+
async function installMaterials(ctx, projDir, usedComps, weapps) {
|
|
43
43
|
let { materialLibs, isBrowserMpBuilder } = ctx;
|
|
44
44
|
const weappsList = ctx.isMixMode ? weapps : weapps.filter((item) => !item.rootPath);
|
|
45
45
|
// #1 Download uploaded libs
|
|
@@ -246,8 +246,9 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
|
|
|
246
246
|
// # Generating page
|
|
247
247
|
const usingComponents = {};
|
|
248
248
|
const componentGenerics = {};
|
|
249
|
-
const
|
|
250
|
-
const
|
|
249
|
+
const componentInstances = (0, util_3.processRepeaterSchema)(compositeCtx, compositedComp.componentInstances);
|
|
250
|
+
const cmpContainer = Object.values(componentInstances)[0];
|
|
251
|
+
const wxml = (0, wxml_1.generateWxml)(compositeCtx, componentInstances, `Component ${materialName}:${compositedComp.name}`, wxmlDataPrefix, usingComponents, componentGenerics, (cmp, node) => {
|
|
251
252
|
if (cmp === cmpContainer) {
|
|
252
253
|
// Set className & style passed from parent for root component
|
|
253
254
|
const { attributes } = node;
|
|
@@ -284,14 +285,14 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
|
|
|
284
285
|
handlers: compositedComp.lowCodes
|
|
285
286
|
.filter((m) => m.type === cals_1.ECodeType.HANDLER_FN && m.name !== cals_1.ECodeName.PLACEHOLDER)
|
|
286
287
|
.map((m) => m.name),
|
|
287
|
-
eventHandlers: (0, util_3.createEventHanlders)(compositeCtx,
|
|
288
|
+
eventHandlers: (0, util_3.createEventHanlders)(compositeCtx, componentInstances, weapps_core_1.COMPONENT_API_PREFIX),
|
|
288
289
|
// protectEventKeys: builtinMpEvents,
|
|
289
290
|
emitEvents: compositedComp.emitEvents.map((evt) => evt.eventName),
|
|
290
|
-
widgetProps: (0, util_3.createWidgetProps)(compositeCtx,
|
|
291
|
+
widgetProps: (0, util_3.createWidgetProps)(compositeCtx, componentInstances),
|
|
291
292
|
compApi: weapps_core_1.COMPONENT_API_PREFIX,
|
|
292
293
|
jsonSchemaType2jsClass: mp_1.jsonSchemaType2jsClass,
|
|
293
294
|
key: `${compositedComp.materialName}:${compositedComp.name}`,
|
|
294
|
-
dataBinds: (0, util_3.createDataBinds)(compositeCtx,
|
|
295
|
+
dataBinds: (0, util_3.createDataBinds)(compositeCtx, componentInstances),
|
|
295
296
|
debug: !compositeCtx.isProduction,
|
|
296
297
|
stringifyObj: util_1.inspect,
|
|
297
298
|
// dataPropNames: wxmlDataPrefix,
|
|
@@ -350,7 +351,7 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
|
|
|
350
351
|
* }
|
|
351
352
|
* }
|
|
352
353
|
*/
|
|
353
|
-
function getWxmlTag(
|
|
354
|
+
function getWxmlTag(ctx, cmp, nameMangler) {
|
|
354
355
|
var _a, _b, _c, _d, _e, _f;
|
|
355
356
|
const { moduleName, name } = cmp;
|
|
356
357
|
const materialLib = ctx.materialLibs.find((lib) => lib.name === moduleName);
|
|
@@ -6,7 +6,7 @@ import { IBuildContext } from './BuildContext';
|
|
|
6
6
|
* @param kboneConfig https://wechat-miniprogram.github.io/kbone/docs/config/
|
|
7
7
|
* @param appConfigs app config from prop edit panel
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateMpConfig(weapps: IWeAppData[],
|
|
9
|
+
export declare function generateMpConfig(ctx: IBuildContext, weapps: IWeAppData[], options: {
|
|
10
10
|
mpAppId?: string;
|
|
11
11
|
}): {
|
|
12
12
|
appConfig: any;
|
|
@@ -40,7 +40,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
40
40
|
* @param kboneConfig https://wechat-miniprogram.github.io/kbone/docs/config/
|
|
41
41
|
* @param appConfigs app config from prop edit panel
|
|
42
42
|
*/
|
|
43
|
-
function generateMpConfig(
|
|
43
|
+
function generateMpConfig(ctx, weapps, options) {
|
|
44
44
|
var _a;
|
|
45
45
|
const appConfig = {
|
|
46
46
|
useExtendedLib: { weui: true },
|
package/lib/builder/mp/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDynamicValue, IWeAppComponentInstance, ICompositedComponent, IWeAppPage } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
1
|
+
import { IDynamicValue, IWeAppComponentInstance, ActionType, ICompositedComponent, IWeAppPage, IEventListener } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IBuildContext } from './BuildContext';
|
|
3
3
|
export declare function generatedDynamicData(data: {
|
|
4
4
|
[key: string]: IDynamicValue;
|
|
@@ -12,6 +12,28 @@ export declare function createWidgetProps(ctx: IBuildContext, widgets: {
|
|
|
12
12
|
export declare function createEventHanlders(ctx: IBuildContext, widgets: {
|
|
13
13
|
[key: string]: IWeAppComponentInstance;
|
|
14
14
|
}, componentApi: string, page?: IWeAppPage): {};
|
|
15
|
+
export declare function generateSyncListeners(syncConfigs: any): IEventListener[];
|
|
16
|
+
export declare function generateDataContainerListeners(): {
|
|
17
|
+
trigger: string;
|
|
18
|
+
jsCode: string;
|
|
19
|
+
type: ActionType;
|
|
20
|
+
data: {};
|
|
21
|
+
}[];
|
|
15
22
|
export declare function createDataBinds(ctx: IBuildContext, widgets: {
|
|
16
23
|
[key: string]: IWeAppComponentInstance;
|
|
17
24
|
}): {};
|
|
25
|
+
export declare function processRepeaterSchema(ctx: any, componentInstanceMap: {
|
|
26
|
+
[key: string]: IWeAppComponentInstance;
|
|
27
|
+
}): {
|
|
28
|
+
[key: string]: IWeAppComponentInstance;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 查找符合小程序平台组件的 info
|
|
32
|
+
*/
|
|
33
|
+
export declare function findComponentInfo(xComponent: {
|
|
34
|
+
moduleName: string;
|
|
35
|
+
name: string;
|
|
36
|
+
}, { materialLibs, miniprogramPlugins }: {
|
|
37
|
+
materialLibs: any;
|
|
38
|
+
miniprogramPlugins: any;
|
|
39
|
+
}): any;
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDataBinds = exports.createEventHanlders = exports.createWidgetProps = exports.generatedDynamicData = void 0;
|
|
3
|
+
exports.findComponentInfo = exports.processRepeaterSchema = exports.createDataBinds = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHanlders = exports.createWidgetProps = exports.generatedDynamicData = void 0;
|
|
4
4
|
const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
|
|
5
5
|
const lowcode_generator_1 = require("@cloudbase/lowcode-generator");
|
|
6
6
|
const weapp_1 = require("@cloudbase/lowcode-generator/lib/generator/util/weapp");
|
|
7
7
|
const wxml_1 = require("./wxml");
|
|
8
8
|
const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
9
9
|
const cals_1 = require("@cloudbase/cals");
|
|
10
|
+
const config_1 = require("../config");
|
|
10
11
|
function extractWidgetProps(props, compInfo, processCssUnit = 'rpx') {
|
|
11
12
|
var _a, _b;
|
|
12
13
|
const { classList } = props;
|
|
@@ -61,13 +62,13 @@ function generateDataBindMeta(bind) {
|
|
|
61
62
|
expr = `$for.${value}`;
|
|
62
63
|
}
|
|
63
64
|
else if (type === weapps_core_1.PropBindType.expression) {
|
|
65
|
+
expr = value ? value.replace(/\/\/[\s\S]*?\r?\n?$/gm, '').replace(/;\s*$/, '') : value;
|
|
64
66
|
try {
|
|
65
|
-
imports += (0, lowcode_generator_1.generateExpressionAlias)(
|
|
67
|
+
imports += (0, lowcode_generator_1.generateExpressionAlias)(expr);
|
|
66
68
|
}
|
|
67
69
|
catch (e) {
|
|
68
|
-
console.error('parse expression error',
|
|
70
|
+
console.error('parse expression error', expr, e === null || e === void 0 ? void 0 : e.message);
|
|
69
71
|
}
|
|
70
|
-
expr = value;
|
|
71
72
|
}
|
|
72
73
|
else if (type === weapps_core_1.PropBindType.prop) {
|
|
73
74
|
const isNegated = value.startsWith('!');
|
|
@@ -104,28 +105,29 @@ function generateDataBindMeta(bind) {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
|
-
return { imports, expression: expr };
|
|
108
|
+
return { imports, expression: expr ? expr.replace(/;\s*$/, '') : expr };
|
|
108
109
|
}
|
|
109
110
|
function createWidgetProps(ctx, widgets) {
|
|
110
111
|
const widgetProps = {};
|
|
111
112
|
(0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
|
|
112
|
-
var _a;
|
|
113
113
|
const { xComponent } = widget;
|
|
114
114
|
const xProps = widget.xProps || {};
|
|
115
115
|
if (!xComponent) {
|
|
116
116
|
// skip slot component
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const widegetComp = materialLib === null || materialLib === void 0 ? void 0 : materialLib.components.find((comp) => comp.name === xComponent.name);
|
|
119
|
+
const widegetComp = findComponentInfo(xComponent, {
|
|
120
|
+
materialLibs: ctx.materialLibs,
|
|
121
|
+
miniprogramPlugins: ctx.miniprogramPlugins,
|
|
122
|
+
});
|
|
126
123
|
if (!widegetComp) {
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
|
|
125
|
+
(xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
126
|
+
// skip
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
129
131
|
}
|
|
130
132
|
widgetProps[id] = extractWidgetProps(xProps, widegetComp, ctx.processCssUnit);
|
|
131
133
|
widgetProps[id]._parentId = parentId;
|
|
@@ -139,64 +141,73 @@ function createEventHanlders(ctx, widgets, componentApi, page) {
|
|
|
139
141
|
let eventHandlers = {};
|
|
140
142
|
const { listeners: pageListeners = [], id: pageId = '' } = page || {};
|
|
141
143
|
(0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
|
|
142
|
-
var _a
|
|
144
|
+
var _a;
|
|
143
145
|
const { xComponent } = widget;
|
|
144
146
|
const xProps = widget.xProps || {};
|
|
145
147
|
if (!xComponent) {
|
|
146
148
|
// skip slot component
|
|
147
149
|
return;
|
|
148
150
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return;
|
|
151
|
+
let compProto;
|
|
152
|
+
if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
|
|
153
|
+
(xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME || xComponent.name === config_1.REPEATER.REPEATER_NAME)) {
|
|
154
|
+
// 内部虚组件,不校验compProto
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
else {
|
|
157
|
+
compProto = findComponentInfo(xComponent, {
|
|
158
|
+
materialLibs: ctx.materialLibs,
|
|
159
|
+
miniprogramPlugins: ctx.miniprogramPlugins,
|
|
160
|
+
});
|
|
161
|
+
if (!compProto) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
160
164
|
}
|
|
161
|
-
const listeners = (xProps.listeners || []).slice();
|
|
162
165
|
// Generate form input value change builtin handler
|
|
163
|
-
const { inputProps, syncProps } = compProto.meta || {};
|
|
166
|
+
const { inputProps, syncProps } = (compProto === null || compProto === void 0 ? void 0 : compProto.meta) || {};
|
|
164
167
|
const syncConfigs = syncProps || inputProps || {};
|
|
165
|
-
|
|
166
|
-
const config = syncConfigs[valuProp];
|
|
167
|
-
const configs = Array.isArray(config) ? config : [config];
|
|
168
|
-
configs.forEach(({ changeEvent, valueFromEvent = 'event.detail.value' }) => {
|
|
169
|
-
listeners.unshift({
|
|
170
|
-
trigger: changeEvent,
|
|
171
|
-
jsCode: `event.currentTarget.${valuProp} = ${valueFromEvent}`,
|
|
172
|
-
type: weapps_core_1.ActionType.Inline,
|
|
173
|
-
data: {},
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
eventHandlers = Object.assign(eventHandlers, getListenersHandlers(listeners, id, componentApi));
|
|
168
|
+
const listeners = [...generateSyncListeners(syncConfigs), ...(xProps.listeners || [])];
|
|
178
169
|
// 如果是数据容器,则生成一个onDataChange事件处理
|
|
179
|
-
if ((
|
|
180
|
-
|
|
181
|
-
eventHandlers[customName] = [
|
|
182
|
-
{
|
|
183
|
-
key: '',
|
|
184
|
-
handler: `({event})=>{
|
|
185
|
-
app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
|
|
186
|
-
app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
|
|
187
|
-
}`,
|
|
188
|
-
handlerModule: weapps_core_1.ActionType.Platform,
|
|
189
|
-
data: {},
|
|
190
|
-
boundData: {},
|
|
191
|
-
},
|
|
192
|
-
];
|
|
170
|
+
if ((_a = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _a === void 0 ? void 0 : _a.isDataContainer) {
|
|
171
|
+
listeners.unshift(...generateDataContainerListeners());
|
|
193
172
|
}
|
|
173
|
+
eventHandlers = Object.assign(eventHandlers, getListenersHandlers(listeners, id, componentApi));
|
|
194
174
|
});
|
|
195
175
|
// 增加页面事件节点 handlers
|
|
196
176
|
eventHandlers = Object.assign(eventHandlers, getListenersHandlers(pageListeners, pageId, componentApi));
|
|
197
177
|
return eventHandlers;
|
|
198
178
|
}
|
|
199
179
|
exports.createEventHanlders = createEventHanlders;
|
|
180
|
+
function generateSyncListeners(syncConfigs) {
|
|
181
|
+
const listeners = [];
|
|
182
|
+
for (const valuProp in syncConfigs) {
|
|
183
|
+
const config = syncConfigs[valuProp];
|
|
184
|
+
const configs = Array.isArray(config) ? config : [config];
|
|
185
|
+
configs.forEach(({ changeEvent, valueFromEvent = 'event.detail.value' }) => {
|
|
186
|
+
listeners.push({
|
|
187
|
+
trigger: changeEvent,
|
|
188
|
+
jsCode: `({ event }) => {event.currentTarget.${valuProp} = ${valueFromEvent};}`,
|
|
189
|
+
type: weapps_core_1.ActionType.Inline,
|
|
190
|
+
data: {},
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return listeners;
|
|
195
|
+
}
|
|
196
|
+
exports.generateSyncListeners = generateSyncListeners;
|
|
197
|
+
function generateDataContainerListeners() {
|
|
198
|
+
return [
|
|
199
|
+
{
|
|
200
|
+
trigger: 'onDataChange',
|
|
201
|
+
jsCode: `({event})=>{
|
|
202
|
+
app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
|
|
203
|
+
app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
|
|
204
|
+
}`,
|
|
205
|
+
type: weapps_core_1.ActionType.Inline,
|
|
206
|
+
data: {},
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
}
|
|
210
|
+
exports.generateDataContainerListeners = generateDataContainerListeners;
|
|
200
211
|
/**
|
|
201
212
|
* 根据 listeners 创建 handlers
|
|
202
213
|
* @param listeners {IEventListener[]}
|
|
@@ -229,7 +240,7 @@ function getListenersHandlers(listeners, id, componentApi) {
|
|
|
229
240
|
}
|
|
230
241
|
eventHandlers[handlerName].push({
|
|
231
242
|
key: l.key || '',
|
|
232
|
-
handler
|
|
243
|
+
handler,
|
|
233
244
|
handlerModule: (_c = l.handler) === null || _c === void 0 ? void 0 : _c.moduleName,
|
|
234
245
|
data: params.staticProps,
|
|
235
246
|
boundData: params.boundProps,
|
|
@@ -242,17 +253,17 @@ function createDataBinds(ctx, widgets) {
|
|
|
242
253
|
const dataBinds = {};
|
|
243
254
|
const { processCssUnit = 'rpx' } = ctx;
|
|
244
255
|
(0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
|
|
245
|
-
var _a;
|
|
246
256
|
const { xComponent } = widget;
|
|
247
257
|
const xProps = widget.xProps || {};
|
|
248
258
|
if (!xComponent) {
|
|
249
259
|
// skip slot component
|
|
250
260
|
return;
|
|
251
261
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
262
|
+
if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
|
|
263
|
+
(xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
264
|
+
// skip exist
|
|
265
|
+
}
|
|
266
|
+
else if (!findComponentInfo(xComponent, { materialLibs: ctx.materialLibs, miniprogramPlugins: ctx.miniprogramPlugins })) {
|
|
256
267
|
return;
|
|
257
268
|
}
|
|
258
269
|
dataBinds[id] = {};
|
|
@@ -300,3 +311,94 @@ function setDataBind(target, prop, val) {
|
|
|
300
311
|
// }
|
|
301
312
|
}
|
|
302
313
|
}
|
|
314
|
+
function processRepeaterSchema(ctx, componentInstanceMap) {
|
|
315
|
+
(0, weapp_1.walkThroughWidgets)(componentInstanceMap, (id, component, parentId) => {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
const { xComponent, xProps, properties = {} } = component;
|
|
318
|
+
if (!xComponent) {
|
|
319
|
+
// skip slot component
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (`${xComponent.moduleName}:${xComponent.name}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`) {
|
|
323
|
+
const children = Object.values(properties);
|
|
324
|
+
// 子项已经为 item 的不在处理
|
|
325
|
+
if (children.length === 1) {
|
|
326
|
+
const child = children[0];
|
|
327
|
+
const { xComponent: childXComponent } = child;
|
|
328
|
+
if (childXComponent &&
|
|
329
|
+
`${childXComponent.moduleName}:${childXComponent.name}` ===
|
|
330
|
+
`${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
|
|
335
|
+
const repeaterItemId = `${id}_item`;
|
|
336
|
+
component.properties = {
|
|
337
|
+
[repeaterItemId]: {
|
|
338
|
+
xComponent: {
|
|
339
|
+
moduleName: config_1.REPEATER.MODULE_NAME,
|
|
340
|
+
name: config_1.REPEATER.REPEATER_ITEM_NAME,
|
|
341
|
+
},
|
|
342
|
+
xProps: {
|
|
343
|
+
data: {},
|
|
344
|
+
directives: {
|
|
345
|
+
waFor: (_a = xProps === null || xProps === void 0 ? void 0 : xProps.data) === null || _a === void 0 ? void 0 : _a.data,
|
|
346
|
+
waForKey: (_b = xProps === null || xProps === void 0 ? void 0 : xProps.data) === null || _b === void 0 ? void 0 : _b.key,
|
|
347
|
+
},
|
|
348
|
+
style: {},
|
|
349
|
+
styleBind: {
|
|
350
|
+
type: 'static',
|
|
351
|
+
value: {},
|
|
352
|
+
},
|
|
353
|
+
classList: [],
|
|
354
|
+
classListBind: {
|
|
355
|
+
type: 'static',
|
|
356
|
+
value: [],
|
|
357
|
+
},
|
|
358
|
+
commonStyle: {},
|
|
359
|
+
customDataForm: {},
|
|
360
|
+
staticResourceAttribute: [],
|
|
361
|
+
},
|
|
362
|
+
properties,
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
else if (`${xComponent.moduleName}:${xComponent.name}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
else if (xComponent && !findComponentInfo(xComponent, ctx)) {
|
|
370
|
+
component.properties = {};
|
|
371
|
+
}
|
|
372
|
+
return;
|
|
373
|
+
});
|
|
374
|
+
return componentInstanceMap;
|
|
375
|
+
}
|
|
376
|
+
exports.processRepeaterSchema = processRepeaterSchema;
|
|
377
|
+
/**
|
|
378
|
+
* 查找符合小程序平台组件的 info
|
|
379
|
+
*/
|
|
380
|
+
function findComponentInfo(xComponent, { materialLibs, miniprogramPlugins }) {
|
|
381
|
+
var _a, _b;
|
|
382
|
+
if (!xComponent) {
|
|
383
|
+
// skip slot component
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const materialLib = materialLibs.find((lib) => lib.name === xComponent.moduleName);
|
|
387
|
+
const miniprogramPlugin = miniprogramPlugins === null || miniprogramPlugins === void 0 ? void 0 : miniprogramPlugins.find((plugin) => plugin.name === xComponent.moduleName);
|
|
388
|
+
if (!materialLib && !miniprogramPlugin) {
|
|
389
|
+
console.error('Component lib not found', `${xComponent.moduleName}:${xComponent.name}`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const compProto = materialLib
|
|
393
|
+
? materialLib.components.find((comp) => comp.name === xComponent.name)
|
|
394
|
+
: (_a = miniprogramPlugin === null || miniprogramPlugin === void 0 ? void 0 : miniprogramPlugin.componentConfigs) === null || _a === void 0 ? void 0 : _a.find((comp) => comp.name === xComponent.name);
|
|
395
|
+
const platform = (_b = compProto === null || compProto === void 0 ? void 0 : compProto.meta) === null || _b === void 0 ? void 0 : _b.platform;
|
|
396
|
+
if (platform && Array.isArray(platform) && platform.length) {
|
|
397
|
+
if (!platform.includes('MP') && !platform.includes('小程序')) {
|
|
398
|
+
console.error('Component lib not found in mp platform', `${xComponent.moduleName}:${xComponent.name}`);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return compProto;
|
|
403
|
+
}
|
|
404
|
+
exports.findComponentInfo = findComponentInfo;
|
package/lib/builder/mp/wxml.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IWeAppComponentInstance, IEventModifiers } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IBuildContext } from './BuildContext';
|
|
3
|
-
export declare function generateWxml(
|
|
4
|
-
[key: string]: IWeAppComponentInstance;
|
|
5
|
-
}, docTag: string, wxmlDataPrefix: any, ctx: IBuildContext & {
|
|
3
|
+
export declare function generateWxml(ctx: IBuildContext & {
|
|
6
4
|
isPage: boolean;
|
|
7
|
-
},
|
|
5
|
+
}, widgets: {
|
|
6
|
+
[key: string]: IWeAppComponentInstance;
|
|
7
|
+
}, docTag: string, wxmlDataPrefix: any, usingComponents: any, componentGenerics: any, nodeTransform?: (cmp: IWeAppComponentInstance, node: any) => void): string;
|
|
8
8
|
export declare function getMpEventHanlderName(widgetId: string, evtName: string, modifier?: IEventModifiers): string;
|
|
9
9
|
export declare function getUsedComponents(widgets: {
|
|
10
10
|
[key: string]: IWeAppComponentInstance;
|