@cloudbase/lowcode-builder 1.8.95 → 1.8.96
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/core/index.d.ts +9 -0
- package/lib/builder/core/index.js +118 -1
- package/lib/builder/h5/generate.d.ts +1 -1
- package/lib/builder/h5/index.d.ts +2 -2
- package/lib/builder/h5/webpack.d.ts +2 -2
- package/lib/builder/mp/BuildContext.d.ts +18 -14
- package/lib/builder/mp/index.d.ts +11 -1
- package/lib/builder/mp/index.js +97 -84
- package/lib/builder/mp/lowcode.d.ts +5 -3
- package/lib/builder/mp/lowcode.js +14 -5
- package/lib/builder/mp/materials.d.ts +10 -5
- package/lib/builder/mp/materials.js +139 -135
- package/lib/builder/mp/util.d.ts +15 -12
- package/lib/builder/mp/util.js +50 -22
- package/lib/builder/mp/wxml.d.ts +5 -3
- package/lib/builder/mp/wxml.js +29 -27
- package/lib/builder/service/webpack.js +0 -1
- package/lib/builder/util/common.d.ts +0 -1
- package/lib/builder/util/common.js +1 -44
- package/lib/builder/util/generateFiles.d.ts +1 -1
- package/lib/builder/util/generateFiles.js +5 -1
- package/lib/builder.web.js +8 -8
- package/package.json +2 -2
- package/template/html/index.html.ejs +7 -3
- package/template/mp/app/weapps-api.js +1 -1
- package/template/mp/app.js +4 -2
- package/template/mp/common/cloud-sdk.js +28 -0
- package/template/mp/common/data-patch.js +9 -1
- package/template/mp/common/util.js +6 -2
- package/template/mp/common/watch.js +1 -1
- package/template/mp/common/weapp-component.js +5 -5
- package/template/mp/common/weapp-page.js +4 -3
- package/template/mp/common/widget.js +51 -38
- package/template/mp/component/index.js +7 -6
- package/template/mp/datasources/index.js.tpl +2 -30
- package/template/mp/package.json +2 -2
- package/template/webpack/web.prod.js +1 -1
|
@@ -26,15 +26,14 @@ 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.getWxmlTag = exports.filterMaterial = exports.installMaterials = void 0;
|
|
29
|
+
exports.getWxmlTag = exports.filterMaterial = exports.installMaterials = exports.normalizeCompositeDependienciesForBuild = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
|
-
const util_1 = require("util");
|
|
32
31
|
const fs = __importStar(require("fs-extra"));
|
|
33
32
|
const weapps_core_1 = require("@cloudbase/lowcode-generator/lib/weapps-core");
|
|
34
33
|
const config_1 = require("../config");
|
|
35
34
|
const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
const util_1 = require("../util");
|
|
36
|
+
const util_2 = require("./util");
|
|
38
37
|
const wxml_1 = require("./wxml");
|
|
39
38
|
const generateFiles_1 = __importStar(require("../util/generateFiles"));
|
|
40
39
|
const lowcode_1 = require("./lowcode");
|
|
@@ -43,12 +42,63 @@ const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib
|
|
|
43
42
|
const junk = __importStar(require("../util/junk"));
|
|
44
43
|
const cals_1 = require("@cloudbase/cals");
|
|
45
44
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
46
|
-
|
|
45
|
+
function normalizeCompositeDependienciesForBuild(lib) {
|
|
46
|
+
lib.dependencies = lib.dependencies || {};
|
|
47
|
+
lib.components.map((cmp) => {
|
|
48
|
+
// populate cmp.materialName
|
|
49
|
+
cmp.materialName = lib.name;
|
|
50
|
+
cmp.meta.syncProps = {};
|
|
51
|
+
const { dataForm = {} } = cmp;
|
|
52
|
+
for (const prop in dataForm) {
|
|
53
|
+
const { inputProp, syncProp } = dataForm[prop];
|
|
54
|
+
if (syncProp || inputProp) {
|
|
55
|
+
cmp.meta.syncProps[prop] = syncProp || inputProp;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (lib.isComposite) {
|
|
59
|
+
cmp.meta.platforms = {
|
|
60
|
+
mp: {
|
|
61
|
+
path: `${cmp.name}/index`,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
lib.dependencies = { ...lib.dependencies, ...cmp.npmDependencies };
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return lib;
|
|
68
|
+
}
|
|
69
|
+
exports.normalizeCompositeDependienciesForBuild = normalizeCompositeDependienciesForBuild;
|
|
70
|
+
async function generateCompLibs(ctx, outDir, mode) {
|
|
71
|
+
const { materialLibs } = ctx;
|
|
72
|
+
// Collection infomation from components to lib meta
|
|
73
|
+
const compositedLibs = materialLibs.filter((lib) => lib.isComposite);
|
|
74
|
+
const reg = new RegExp(`${cals_1.SPINOFF_SUFFIX}$`);
|
|
75
|
+
// #2 Generate composited libs
|
|
76
|
+
await Promise.all(compositedLibs.map(async (lib) => {
|
|
77
|
+
console.log(`Generate composited library ${lib.name}`);
|
|
78
|
+
await Promise.all(lib.components.map(async (cmp) => {
|
|
79
|
+
return generateCompositeComponent({
|
|
80
|
+
...ctx,
|
|
81
|
+
/**
|
|
82
|
+
* 此处强行覆盖为 rpx 是为了兼容老的复合组件
|
|
83
|
+
* $template, 和单独lib构建应受控,跟随应用的配置
|
|
84
|
+
*/
|
|
85
|
+
processCssUnit: lib.name === cals_1.OFFICIAL_COMPONENT_LIB_NAME || reg.test(lib.name) ? 'rpx' : ctx.processCssUnit,
|
|
86
|
+
// 只生成在主目录中,减少冗余
|
|
87
|
+
// rootPath: app.rootPath || '', // 主包是没有 rootPath 的
|
|
88
|
+
}, cmp, outDir, lib.rootPath !== undefined ? lib.rootPath : path.join(config_1.materialsDirName, lib.name), lib.compLibCommonResource, mode);
|
|
89
|
+
}));
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
async function installMaterials(ctx, outDir, usedMeta, mode) {
|
|
47
93
|
let { materialLibs: _materialLibs, isBrowserMpBuilder } = ctx;
|
|
48
|
-
|
|
49
|
-
|
|
94
|
+
let materialLibs = _materialLibs.filter((lib) => {
|
|
95
|
+
if (!usedMeta) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return usedMeta.component[lib.name] || usedMeta.action[lib.name];
|
|
99
|
+
});
|
|
50
100
|
// #1 Download uploaded libs
|
|
51
|
-
const localPkg = (0,
|
|
101
|
+
const localPkg = (0, util_1.getCurrentPackageJson)();
|
|
52
102
|
await Promise.all(materialLibs
|
|
53
103
|
.filter((lib) => !lib.isComposite)
|
|
54
104
|
.map(async (lib) => {
|
|
@@ -66,7 +116,7 @@ async function installMaterials(ctx, outDir, usedMeta, weapps) {
|
|
|
66
116
|
await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder, noCache);
|
|
67
117
|
}
|
|
68
118
|
function libUpdated(libDir, version) {
|
|
69
|
-
const meta = (0,
|
|
119
|
+
const meta = (0, util_1.readComponentLibMata)(libDir);
|
|
70
120
|
if (!meta) {
|
|
71
121
|
return true;
|
|
72
122
|
}
|
|
@@ -74,120 +124,68 @@ async function installMaterials(ctx, outDir, usedMeta, weapps) {
|
|
|
74
124
|
return true;
|
|
75
125
|
}
|
|
76
126
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
else {
|
|
86
|
-
usingMaterialMap[targetDir] = true;
|
|
87
|
-
}
|
|
88
|
-
if (libUpdated(targetDir, version)) {
|
|
89
|
-
const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
|
|
90
|
-
if (fs.existsSync(materialsSrcDirPath)) {
|
|
91
|
-
console.log(`Copying material ${materialId} from ${isBrowserMpBuilder ? materialsSrcDirPath : materialsSrcDir}/src to ${targetDir}`);
|
|
92
|
-
// #2 从根目录 copy meta 文件
|
|
93
|
-
const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
|
|
94
|
-
if (fs.existsSync(metaJosnPath)) {
|
|
95
|
-
!isBrowserMpBuilder
|
|
96
|
-
? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json'))
|
|
97
|
-
: (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
|
|
98
|
-
}
|
|
99
|
-
// #3 copy 组件库代码文件到项目目录
|
|
100
|
-
!isBrowserMpBuilder
|
|
101
|
-
? await fs.copy(materialsSrcDirPath, targetDir, {
|
|
102
|
-
filter(src, dest) {
|
|
103
|
-
const path = src.split('/');
|
|
104
|
-
return !junk.is(path[path.length - 1]);
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir, {
|
|
108
|
-
filter: filterMaterial,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
|
|
113
|
-
// #2 link material to current project
|
|
127
|
+
const targetDir = path.join(outDir, config_1.materialsDirName, name);
|
|
128
|
+
if (libUpdated(targetDir, version)) {
|
|
129
|
+
const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
|
|
130
|
+
if (fs.existsSync(materialsSrcDirPath)) {
|
|
131
|
+
console.log(`Copying material ${materialId} from ${isBrowserMpBuilder ? materialsSrcDirPath : materialsSrcDir}/src to ${targetDir}`);
|
|
132
|
+
// #2 从根目录 copy meta 文件
|
|
133
|
+
const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
|
|
134
|
+
if (fs.existsSync(metaJosnPath)) {
|
|
114
135
|
!isBrowserMpBuilder
|
|
115
|
-
? await fs.copy(
|
|
116
|
-
|
|
117
|
-
const path = src.split('/');
|
|
118
|
-
return !junk.is(path[path.length - 1]);
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir, {
|
|
122
|
-
filter: filterMaterial,
|
|
123
|
-
});
|
|
136
|
+
? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json'))
|
|
137
|
+
: (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
|
|
124
138
|
}
|
|
139
|
+
// #3 copy 组件库代码文件到项目目录
|
|
140
|
+
!isBrowserMpBuilder
|
|
141
|
+
? await fs.copy(materialsSrcDirPath, targetDir, {
|
|
142
|
+
filter: filterMaterial,
|
|
143
|
+
})
|
|
144
|
+
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir, {
|
|
145
|
+
filter: filterMaterial,
|
|
146
|
+
});
|
|
125
147
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
else {
|
|
149
|
+
console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
|
|
150
|
+
// #2 link material to current project
|
|
151
|
+
!isBrowserMpBuilder
|
|
152
|
+
? await fs.copy(materialsSrcDir, targetDir, {
|
|
153
|
+
filter(src, dest) {
|
|
154
|
+
const path = src.split('/');
|
|
155
|
+
return !junk.is(path[path.length - 1]);
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
: (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir, {
|
|
159
|
+
filter: filterMaterial,
|
|
133
160
|
});
|
|
134
|
-
});
|
|
135
161
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
162
|
+
}
|
|
163
|
+
const libMeta = (0, util_1.readComponentLibMata)(targetDir);
|
|
164
|
+
if (!lib.components) {
|
|
165
|
+
lib.components = Object.keys((libMeta === null || libMeta === void 0 ? void 0 : libMeta.components) || {}).map((name) => {
|
|
166
|
+
var _a;
|
|
167
|
+
return ({
|
|
168
|
+
name,
|
|
169
|
+
meta: (_a = libMeta === null || libMeta === void 0 ? void 0 : libMeta.components[name]) === null || _a === void 0 ? void 0 : _a.meta,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
lib.styles = libMeta === null || libMeta === void 0 ? void 0 : libMeta.styles;
|
|
174
|
+
lib.dependencies = libMeta === null || libMeta === void 0 ? void 0 : libMeta.dependencies;
|
|
139
175
|
}));
|
|
140
176
|
// clean unused comps
|
|
141
|
-
ctx.materialLibs = materialLibs;
|
|
142
177
|
materialLibs.forEach((lib) => {
|
|
143
|
-
lib.components = lib.components.filter((comp) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
lib.components.map((comp) => {
|
|
148
|
-
comp.materialName = lib.name;
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
materialLibs.map((lib) => {
|
|
152
|
-
lib.dependencies = lib.dependencies || {};
|
|
153
|
-
lib.components.map((cmp) => {
|
|
154
|
-
cmp.meta.syncProps = {};
|
|
155
|
-
const { dataForm = {} } = cmp;
|
|
156
|
-
for (const prop in dataForm) {
|
|
157
|
-
const { inputProp, syncProp } = dataForm[prop];
|
|
158
|
-
if (syncProp || inputProp) {
|
|
159
|
-
cmp.meta.syncProps[prop] = syncProp || inputProp;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (lib.isComposite) {
|
|
163
|
-
cmp.meta.platforms = {
|
|
164
|
-
mp: {
|
|
165
|
-
path: `${cmp.name}/index`,
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
lib.dependencies = { ...lib.dependencies, ...cmp.npmDependencies };
|
|
178
|
+
lib.components = lib.components.filter((comp) => {
|
|
179
|
+
var _a, _b;
|
|
180
|
+
if (!usedMeta) {
|
|
181
|
+
return true;
|
|
169
182
|
}
|
|
183
|
+
return (_b = (_a = usedMeta.component[lib.name]) === null || _a === void 0 ? void 0 : _a.has) === null || _b === void 0 ? void 0 : _b.call(_a, comp.name);
|
|
170
184
|
});
|
|
185
|
+
normalizeCompositeDependienciesForBuild(lib);
|
|
171
186
|
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// #2 Generate composited libs
|
|
175
|
-
await Promise.all(compositedLibs.map(async (lib) => {
|
|
176
|
-
console.log(`Generate composited library ${lib.name}`);
|
|
177
|
-
await (0, util_2.writeLibCommonRes2file)(lib, path.join(outDir, config_1.materialsDirName, lib.name, 'libCommonRes'));
|
|
178
|
-
await Promise.all(lib.components.map(async (cmp) => {
|
|
179
|
-
return generateCompositeComponent({
|
|
180
|
-
...ctx,
|
|
181
|
-
/**
|
|
182
|
-
* 此处强行覆盖为 rpx 是为了兼容老的复合组件
|
|
183
|
-
* $template 应该跟随应用的配置
|
|
184
|
-
*/
|
|
185
|
-
processCssUnit: lib.name !== '$template' ? 'rpx' : ctx.processCssUnit,
|
|
186
|
-
// 只生成在主目录中,减少冗余
|
|
187
|
-
// rootPath: app.rootPath || '', // 主包是没有 rootPath 的
|
|
188
|
-
}, cmp, path.join(outDir, config_1.materialsDirName), lib.compLibCommonResource);
|
|
189
|
-
}));
|
|
190
|
-
}));
|
|
187
|
+
ctx.materialLibs = materialLibs;
|
|
188
|
+
await generateCompLibs(ctx, outDir, mode);
|
|
191
189
|
}
|
|
192
190
|
exports.installMaterials = installMaterials;
|
|
193
191
|
/**
|
|
@@ -206,21 +204,17 @@ async function downloadMaterial(zipUrl, dstFolder, isBrowser = false, noCache =
|
|
|
206
204
|
return;
|
|
207
205
|
await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser, noCache);
|
|
208
206
|
}
|
|
209
|
-
async function generateCompositeComponent(
|
|
210
|
-
const compositeCtx = {
|
|
211
|
-
...ctx,
|
|
212
|
-
isPage: false,
|
|
213
|
-
enableLoading: false,
|
|
214
|
-
};
|
|
207
|
+
async function generateCompositeComponent(compositeCtx, compositedComp, lowcalWedaRoot, componentLibRoot, compLibCommonResource, mode = 'inline') {
|
|
215
208
|
const { materialName } = compositedComp;
|
|
216
|
-
const
|
|
209
|
+
const componentRelativeDir = path.posix.join(componentLibRoot, compositedComp.name);
|
|
210
|
+
const componentDir = path.join(lowcalWedaRoot, componentLibRoot, compositedComp.name);
|
|
217
211
|
const LOWCODE_DIR_NAME = 'lowcode';
|
|
218
212
|
console.log(`Generating composited component ${materialName}:${compositedComp.name} to ${componentDir}`);
|
|
219
213
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!compositeCtx.isProduction);
|
|
220
214
|
// # Generating page
|
|
221
215
|
const usingComponents = {};
|
|
222
216
|
const componentGenerics = {};
|
|
223
|
-
const componentInstances = (0,
|
|
217
|
+
const componentInstances = (0, util_2.processRepeaterSchema)(compositeCtx, compositedComp.componentInstances);
|
|
224
218
|
const cmpContainer = Object.values(componentInstances)[0];
|
|
225
219
|
const wxml = (0, wxml_1.generateWxml)(compositeCtx, componentInstances, `Component ${materialName}:${compositedComp.name}`, wxmlDataPrefix, usingComponents, componentGenerics, (cmp, node) => {
|
|
226
220
|
if (cmp === cmpContainer) {
|
|
@@ -233,7 +227,7 @@ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCo
|
|
|
233
227
|
}
|
|
234
228
|
});
|
|
235
229
|
// prepare form field change events
|
|
236
|
-
const { syncProps } = compositedComp.meta;
|
|
230
|
+
const { syncProps = {} } = compositedComp.meta;
|
|
237
231
|
const formEvents = {};
|
|
238
232
|
Object.keys(syncProps).map((prop) => {
|
|
239
233
|
const config = syncProps[prop];
|
|
@@ -251,39 +245,46 @@ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCo
|
|
|
251
245
|
}
|
|
252
246
|
});
|
|
253
247
|
const codes = (0, cals_1.processRuntimeCodeResources)({ id: '$comp' }, compositedComp.lowCodes, 'component');
|
|
254
|
-
const importor = (0,
|
|
248
|
+
const importor = (0, util_1.generateLowcodeImportor)(codes);
|
|
255
249
|
const pageFileData = {
|
|
256
250
|
'index.js': {
|
|
251
|
+
relativeWedaRoot: path.posix.relative(path.posix.join('/', componentRelativeDir), '/') || '.',
|
|
257
252
|
materialName,
|
|
258
253
|
propDefs,
|
|
259
254
|
handlers: compositedComp.lowCodes
|
|
260
255
|
.filter((m) => m.type === cals_1.ECodeType.HANDLER_FN && m.name !== cals_1.ECodeName.PLACEHOLDER)
|
|
261
256
|
.map((m) => m.name),
|
|
262
|
-
eventHandlers: (0,
|
|
263
|
-
// protectEventKeys: builtinMpEvents,
|
|
257
|
+
eventHandlers: (0, util_2.createEventHandlers)(compositeCtx, componentInstances, weapps_core_1.COMPONENT_API_PREFIX),
|
|
264
258
|
emitEvents: (compositedComp.emitEvents || []).map((evt) => evt.eventName),
|
|
265
|
-
widgetProps: (0,
|
|
259
|
+
widgetProps: (0, util_2.createWidgetProps)(compositeCtx, componentInstances),
|
|
266
260
|
compApi: weapps_core_1.COMPONENT_API_PREFIX,
|
|
267
261
|
jsonSchemaType2jsClass: mp_1.jsonSchemaType2jsClass,
|
|
268
|
-
key: `${
|
|
269
|
-
dataBinds: (0,
|
|
262
|
+
key: `${materialName}:${compositedComp.name}`,
|
|
263
|
+
dataBinds: (0, util_2.createDataBinds)(compositeCtx, componentInstances),
|
|
270
264
|
debug: !compositeCtx.isProduction,
|
|
271
|
-
/**
|
|
272
|
-
* @deprecated
|
|
273
|
-
*/
|
|
274
|
-
stringifyObj: util_1.inspect,
|
|
275
265
|
// dataPropNames: wxmlDataPrefix,
|
|
276
266
|
formEvents: Object.keys(formEvents).length > 0 ? formEvents : null,
|
|
277
267
|
config: compositedComp.compConfig,
|
|
278
268
|
importor,
|
|
279
269
|
},
|
|
280
|
-
'index.json': {
|
|
270
|
+
'index.json': {
|
|
271
|
+
usingComponents: Object.entries(usingComponents).reduce((map, [key, value]) => {
|
|
272
|
+
if (new RegExp(`^${path.posix.join('/', compositeCtx.wedaRoot || '', '\\w')}`).test(value)) {
|
|
273
|
+
map[key] = path.posix.relative(path.posix.join('/', compositeCtx.wedaRoot || '', componentRelativeDir), value);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
map[key] = value;
|
|
277
|
+
}
|
|
278
|
+
return map;
|
|
279
|
+
}, {}),
|
|
280
|
+
componentGenerics,
|
|
281
|
+
},
|
|
281
282
|
'index.wxml': {
|
|
282
283
|
content: wxml,
|
|
283
284
|
},
|
|
284
285
|
'index.wxss': {
|
|
285
286
|
importStyles: importor.styles.map((mod) => path.posix.join(LOWCODE_DIR_NAME, (0, weapps_core_1.getCodeModuleFilePath)('global', mod, { style: '.wxss' }))),
|
|
286
|
-
content: (0,
|
|
287
|
+
content: (0, util_2.generateScopedStyleText)(componentInstances),
|
|
287
288
|
},
|
|
288
289
|
};
|
|
289
290
|
// Generating file by template and data
|
|
@@ -315,7 +316,7 @@ async function generateCompositeComponent(ctx, compositedComp, outDir, compLibCo
|
|
|
315
316
|
if (mod.name === 'index') {
|
|
316
317
|
return;
|
|
317
318
|
}
|
|
318
|
-
return (0, lowcode_1.writeCode2file)(compositeCtx, mod, path.join(componentDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode);
|
|
319
|
+
return (0, lowcode_1.writeCode2file)(compositeCtx, mod, path.join(componentDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode, mode === 'lib' ? true : false);
|
|
319
320
|
});
|
|
320
321
|
// await writeLowCodeFiles(weapp, appRoot)
|
|
321
322
|
// await generateFramework(weapp, appRoot)
|
|
@@ -341,6 +342,9 @@ function getWxmlTag(ctx, cmp, nameMangler) {
|
|
|
341
342
|
return { tagName };
|
|
342
343
|
}
|
|
343
344
|
if (materialLib) {
|
|
345
|
+
const libRootInMiniprogram = path.posix.join('/', ctx.wedaRoot || '', (materialLib === null || materialLib === void 0 ? void 0 : materialLib.rootPath)
|
|
346
|
+
? materialLib === null || materialLib === void 0 ? void 0 : materialLib.rootPath
|
|
347
|
+
: path.posix.join(`${config_1.materialsDirName}/${cmp.moduleName}`));
|
|
344
348
|
let cmpMeta = (findComponent === null || findComponent === void 0 ? void 0 : findComponent.meta) || { platforms: undefined };
|
|
345
349
|
if (!cmpMeta.platforms) {
|
|
346
350
|
return { tagName };
|
|
@@ -353,7 +357,7 @@ function getWxmlTag(ctx, cmp, nameMangler) {
|
|
|
353
357
|
compPath =
|
|
354
358
|
compPath.startsWith('/') || compPath.indexOf('://') > 0
|
|
355
359
|
? compPath
|
|
356
|
-
: path.posix.join(
|
|
360
|
+
: path.posix.join(libRootInMiniprogram, compPath);
|
|
357
361
|
tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
|
|
358
362
|
if (nameMangler) {
|
|
359
363
|
tagName = nameMangler.mangle(tagName);
|
package/lib/builder/mp/util.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { IDynamicValue, IWeAppComponentInstance, ActionType, ICompositedComponent, IWeAppPage, IEventListener, IQueryData } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
|
-
import {
|
|
2
|
+
import { IMpCommonBuildContext } from './BuildContext';
|
|
3
3
|
export declare function generatedDynamicData(data: {
|
|
4
4
|
[key: string]: IDynamicValue;
|
|
5
5
|
}, compInfo?: ICompositedComponent, filterBuiltInProps?: boolean): {
|
|
6
6
|
staticProps: {};
|
|
7
7
|
boundProps: {};
|
|
8
8
|
};
|
|
9
|
-
export declare function createWidgetProps(ctx:
|
|
9
|
+
export declare function createWidgetProps(ctx: IMpCommonBuildContext, widgets: {
|
|
10
10
|
[key: string]: IWeAppComponentInstance;
|
|
11
11
|
}): {};
|
|
12
|
-
export declare function createEventHandlers(ctx:
|
|
12
|
+
export declare function createEventHandlers(ctx: IMpCommonBuildContext, widgets: {
|
|
13
13
|
[key: string]: IWeAppComponentInstance;
|
|
14
14
|
}, componentApi: string, page?: IWeAppPage): {};
|
|
15
15
|
export declare function generateSyncListeners(syncConfigs: any): IEventListener[];
|
|
@@ -19,10 +19,10 @@ export declare function generateDataContainerListeners(): {
|
|
|
19
19
|
type: ActionType;
|
|
20
20
|
data: {};
|
|
21
21
|
}[];
|
|
22
|
-
export declare function createTemplateQuery(ctx:
|
|
22
|
+
export declare function createTemplateQuery(ctx: IMpCommonBuildContext, query?: {
|
|
23
23
|
[key: string]: IQueryData;
|
|
24
24
|
}): {};
|
|
25
|
-
export declare function createTemplateEventFlows(ctx:
|
|
25
|
+
export declare function createTemplateEventFlows(ctx: IMpCommonBuildContext, eventFlows?: any[]): any[];
|
|
26
26
|
export declare function generateArgsDynamicValueFromData(args?: {
|
|
27
27
|
[prop: string]: IDynamicValue;
|
|
28
28
|
}, data?: {
|
|
@@ -30,11 +30,11 @@ export declare function generateArgsDynamicValueFromData(args?: {
|
|
|
30
30
|
}): {
|
|
31
31
|
[prop: string]: IDynamicValue;
|
|
32
32
|
} | undefined;
|
|
33
|
-
export declare function createDataBinds(ctx:
|
|
33
|
+
export declare function createDataBinds(ctx: IMpCommonBuildContext, widgets: {
|
|
34
34
|
[key: string]: IWeAppComponentInstance;
|
|
35
35
|
}): {};
|
|
36
36
|
export declare function setDataBind(target: any, prop: string, val: IDynamicValue): void;
|
|
37
|
-
export declare function processRepeaterSchema(ctx:
|
|
37
|
+
export declare function processRepeaterSchema(ctx: Pick<IMpCommonBuildContext, 'materialLibs' | 'miniprogramPlugins'>, componentInstanceMap: {
|
|
38
38
|
[key: string]: IWeAppComponentInstance;
|
|
39
39
|
}): {
|
|
40
40
|
[key: string]: IWeAppComponentInstance;
|
|
@@ -45,8 +45,11 @@ export declare function processRepeaterSchema(ctx: any, componentInstanceMap: {
|
|
|
45
45
|
export declare function findComponentInfo(xComponent: {
|
|
46
46
|
moduleName: string;
|
|
47
47
|
name: string;
|
|
48
|
-
}, { materialLibs, miniprogramPlugins }:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
}, { materialLibs, miniprogramPlugins }: Pick<IMpCommonBuildContext, 'materialLibs' | 'miniprogramPlugins'>): ICompositedComponent | undefined;
|
|
49
|
+
export declare function generateScopedStyleText(widgets: Record<string, IWeAppComponentInstance>, weightPrefix?: string): string;
|
|
50
|
+
export declare function isRepeaterWidget(w: {
|
|
51
|
+
widgetType: string;
|
|
52
|
+
getConfig: () => {
|
|
53
|
+
componentType?: string;
|
|
54
|
+
};
|
|
55
|
+
}, repeaterComponentName: string): true | undefined;
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.setDataBind = exports.createDataBinds = exports.generateArgsDynamicValueFromData = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = exports.createWidgetProps = exports.generatedDynamicData = void 0;
|
|
3
|
+
exports.isRepeaterWidget = exports.generateScopedStyleText = exports.findComponentInfo = exports.processRepeaterSchema = exports.setDataBind = exports.createDataBinds = exports.generateArgsDynamicValueFromData = exports.createTemplateEventFlows = exports.createTemplateQuery = exports.generateDataContainerListeners = exports.generateSyncListeners = exports.createEventHandlers = 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");
|
|
@@ -128,14 +128,8 @@ function createWidgetProps(ctx, widgets) {
|
|
|
128
128
|
materialLibs: ctx.materialLibs,
|
|
129
129
|
miniprogramPlugins: ctx.miniprogramPlugins,
|
|
130
130
|
});
|
|
131
|
-
if (!widegetComp) {
|
|
132
|
-
|
|
133
|
-
(xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
134
|
-
// skip
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
131
|
+
if (!widegetComp && !checkRepeaterComponent(xComponent)) {
|
|
132
|
+
return;
|
|
139
133
|
}
|
|
140
134
|
widgetProps[id] = extractWidgetProps(xProps, widegetComp, ctx.processCssUnit);
|
|
141
135
|
widgetProps[id]._parentId = parentId;
|
|
@@ -157,8 +151,7 @@ function createEventHandlers(ctx, widgets, componentApi, page) {
|
|
|
157
151
|
return;
|
|
158
152
|
}
|
|
159
153
|
let compProto;
|
|
160
|
-
if (xComponent
|
|
161
|
-
(xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME || xComponent.name === config_1.REPEATER.REPEATER_NAME)) {
|
|
154
|
+
if (checkRepeaterComponent(xComponent)) {
|
|
162
155
|
// 内部虚组件,不校验compProto
|
|
163
156
|
}
|
|
164
157
|
else {
|
|
@@ -357,8 +350,7 @@ function createDataBinds(ctx, widgets) {
|
|
|
357
350
|
// skip slot component
|
|
358
351
|
return;
|
|
359
352
|
}
|
|
360
|
-
if (xComponent
|
|
361
|
-
(xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
353
|
+
if (checkRepeaterComponent(xComponent)) {
|
|
362
354
|
// skip exist
|
|
363
355
|
}
|
|
364
356
|
else if (!findComponentInfo(xComponent, { materialLibs: ctx.materialLibs, miniprogramPlugins: ctx.miniprogramPlugins })) {
|
|
@@ -439,16 +431,36 @@ function processRepeaterSchema(ctx, componentInstanceMap) {
|
|
|
439
431
|
// skip slot component
|
|
440
432
|
return;
|
|
441
433
|
}
|
|
442
|
-
|
|
434
|
+
const componentInfo = findComponentInfo(xComponent, {
|
|
435
|
+
materialLibs: ctx.materialLibs,
|
|
436
|
+
miniprogramPlugins: ctx.miniprogramPlugins,
|
|
437
|
+
});
|
|
438
|
+
const simpleWidget = {
|
|
439
|
+
widgetType: `${xComponent.moduleName}:${xComponent.name}`,
|
|
440
|
+
getConfig: () => {
|
|
441
|
+
return (componentInfo === null || componentInfo === void 0 ? void 0 : componentInfo.compConfig) || {};
|
|
442
|
+
},
|
|
443
|
+
};
|
|
444
|
+
if (isRepeaterWidget(simpleWidget, config_1.REPEATER.REPEATER_NAME)) {
|
|
443
445
|
const children = Object.values(properties);
|
|
444
446
|
// 子项已经为 item 的不在处理
|
|
445
447
|
if (children.length === 1) {
|
|
446
448
|
const child = children[0];
|
|
447
449
|
const { xComponent: childXComponent } = child;
|
|
448
|
-
if (childXComponent
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
450
|
+
if (childXComponent) {
|
|
451
|
+
const componentInfo = findComponentInfo(childXComponent, {
|
|
452
|
+
materialLibs: ctx.materialLibs,
|
|
453
|
+
miniprogramPlugins: ctx.miniprogramPlugins,
|
|
454
|
+
});
|
|
455
|
+
const simpleWidget = {
|
|
456
|
+
widgetType: `${xComponent.moduleName}:${xComponent.name}`,
|
|
457
|
+
getConfig: () => {
|
|
458
|
+
return (componentInfo === null || componentInfo === void 0 ? void 0 : componentInfo.compConfig) || {};
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
if (isRepeaterWidget(simpleWidget, config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
452
464
|
}
|
|
453
465
|
}
|
|
454
466
|
// 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
|
|
@@ -483,10 +495,10 @@ function processRepeaterSchema(ctx, componentInstanceMap) {
|
|
|
483
495
|
},
|
|
484
496
|
};
|
|
485
497
|
}
|
|
486
|
-
else if (
|
|
498
|
+
else if (isRepeaterWidget(simpleWidget, config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
487
499
|
return;
|
|
488
500
|
}
|
|
489
|
-
else if (xComponent && !
|
|
501
|
+
else if (xComponent && !componentInfo) {
|
|
490
502
|
component.properties = {};
|
|
491
503
|
}
|
|
492
504
|
return;
|
|
@@ -522,7 +534,7 @@ function findComponentInfo(xComponent, { materialLibs, miniprogramPlugins }) {
|
|
|
522
534
|
return compProto;
|
|
523
535
|
}
|
|
524
536
|
exports.findComponentInfo = findComponentInfo;
|
|
525
|
-
function generateScopedStyleText(widgets) {
|
|
537
|
+
function generateScopedStyleText(widgets, weightPrefix = '#wd-page-root') {
|
|
526
538
|
const cssTextList = [];
|
|
527
539
|
function traverse(target) {
|
|
528
540
|
var _a;
|
|
@@ -535,7 +547,7 @@ function generateScopedStyleText(widgets) {
|
|
|
535
547
|
// 移除换行及其前后的空白符
|
|
536
548
|
.replace(/\s*\n\s*/g, '')
|
|
537
549
|
// 添加 `#wd-page-root` 前缀以增加样式权重
|
|
538
|
-
.replace(/(:scope.*?{)/g,
|
|
550
|
+
.replace(/(:scope.*?{)/g, `\n${weightPrefix} $1`)
|
|
539
551
|
// 替换 `:scope`
|
|
540
552
|
.replace(/:scope/g, `.wd-comp-id-${id}`)
|
|
541
553
|
// `: ` => `:`
|
|
@@ -555,3 +567,19 @@ function generateScopedStyleText(widgets) {
|
|
|
555
567
|
return cssTextList.join('\n');
|
|
556
568
|
}
|
|
557
569
|
exports.generateScopedStyleText = generateScopedStyleText;
|
|
570
|
+
function isRepeaterWidget(w, repeaterComponentName /* 'Repeater' | 'RepeaterItem' */) {
|
|
571
|
+
var _a;
|
|
572
|
+
const { componentType } = ((_a = w === null || w === void 0 ? void 0 : w.getConfig) === null || _a === void 0 ? void 0 : _a.call(w)) || {};
|
|
573
|
+
if (componentType === repeaterComponentName || (w === null || w === void 0 ? void 0 : w.widgetType) === `${config_1.REPEATER.MODULE_NAME}:${repeaterComponentName}`) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
exports.isRepeaterWidget = isRepeaterWidget;
|
|
578
|
+
function checkRepeaterComponent(xComponent) {
|
|
579
|
+
if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
|
|
580
|
+
(xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
|
|
581
|
+
return true;
|
|
582
|
+
// skip
|
|
583
|
+
}
|
|
584
|
+
return false;
|
|
585
|
+
}
|
package/lib/builder/mp/wxml.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { IWeAppComponentInstance, IEventModifiers } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
|
-
import { IBuildContext } from './BuildContext';
|
|
2
|
+
import { IBuildContext, IMpCommonBuildContext } from './BuildContext';
|
|
3
3
|
export declare const WD_EMPTY_PLACEHOLDER = "wd-ph";
|
|
4
4
|
export declare const WD_RUNTIME_TAG: string[];
|
|
5
|
-
export declare function generateWxml(ctx: IBuildContext & {
|
|
5
|
+
export declare function generateWxml(ctx: (IBuildContext & {
|
|
6
6
|
pageUUID?: string;
|
|
7
|
-
}
|
|
7
|
+
}) | (IMpCommonBuildContext & {
|
|
8
|
+
pageUUID?: undefined;
|
|
9
|
+
}), widgets: {
|
|
8
10
|
[key: string]: IWeAppComponentInstance;
|
|
9
11
|
}, docTag: string, wxmlDataPrefix: any, usingComponents: any, componentGenerics: any, nodeTransform?: (cmp: IWeAppComponentInstance, node: any) => void): string;
|
|
10
12
|
export declare function getMpEventHandlerName(widgetId: string, evtName: string, modifier?: IEventModifiers): string;
|