@cloudbase/lowcode-builder 1.2.4 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- var index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
33
- Object.defineProperty(exports, "REPLACE_SIGN", { enumerable: true, get: function () { return index_1.REPLACE_SIGN; } });
34
- Object.defineProperty(exports, "MP_CONFIG_MODULE_NAME", { enumerable: true, get: function () { return index_1.MP_CONFIG_MODULE_NAME; } });
35
- Object.defineProperty(exports, "KBONE_PAGE_KEYS", { enumerable: true, get: function () { return index_1.KBONE_PAGE_KEYS; } });
36
- Object.defineProperty(exports, "npmRegistry", { enumerable: true, get: function () { return index_1.npmRegistry; } });
37
- Object.defineProperty(exports, "remConfig", { enumerable: true, get: function () { return index_1.remConfig; } });
38
- Object.defineProperty(exports, "rpxConfig", { enumerable: true, get: function () { return index_1.rpxConfig; } });
39
- Object.defineProperty(exports, "OFFICIAL_LIB_KEY", { enumerable: true, get: function () { return index_1.OFFICIAL_LIB_KEY; } });
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
+ };
@@ -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, buildContext);
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)(weapps, buildContext, { mpAppId: options.mpAppId });
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, buildContext);
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, buildContext);
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, subpackageBuildCtx);
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 wxml = (0, wxml_1.generateWxml)(page.componentInstances, `Page ${rootPath ? path_1.default.join(rootPath, 'pages') : ''}/${page.id}`, wxmlDataPrefix, { ...ctx, rootPath, isPage: true }, usingComponents, componentGenerics);
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, page.componentInstances),
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, page.componentInstances, 'this', page),
311
- dataBinds: (0, util_2.createDataBinds)(ctx, page.componentInstances),
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, ctx) {
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 process from '${mod.type === 'handler-fn' ? '../' : ''}../../../../common/process'\nimport { app } from '${mod.type === 'handler-fn' ? '../' : ''}../../../../app/weapps-api';\nconst $app = new Proxy({}, { get: function(obj, prop){ return app[prop] }});\n${code.replace(/\$comp/g, weapps_core_1.COMPONENT_API_PREFIX)}`;
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[], ctx: IBuildContext): Promise<void>;
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'], ctx: IBuildContext, nameMangler?: NameMangler): {
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, ctx) {
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 cmpContainer = Object.values(compositedComp.componentInstances)[0];
250
- const wxml = (0, wxml_1.generateWxml)(compositedComp.componentInstances, `Component ${materialName}:${compositedComp.name}`, wxmlDataPrefix, compositeCtx, usingComponents, componentGenerics, (cmp, node) => {
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, compositedComp.componentInstances, weapps_core_1.COMPONENT_API_PREFIX),
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, compositedComp.componentInstances),
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, compositedComp.componentInstances),
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(cmp, ctx, nameMangler) {
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[], ctx: IBuildContext, options: {
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(weapps, ctx, options) {
43
+ function generateMpConfig(ctx, weapps, options) {
44
44
  var _a;
45
45
  const appConfig = {
46
46
  useExtendedLib: { weui: true },
@@ -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;
@@ -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,14 @@ 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;
66
+ expr = value;
64
67
  try {
65
- imports += (0, lowcode_generator_1.generateExpressionAlias)(value);
68
+ imports += (0, lowcode_generator_1.generateExpressionAlias)(expr);
66
69
  }
67
70
  catch (e) {
68
- console.error('parse expression error', value, e === null || e === void 0 ? void 0 : e.message);
71
+ console.error('parse expression error', expr, e === null || e === void 0 ? void 0 : e.message);
69
72
  }
70
- expr = value;
71
73
  }
72
74
  else if (type === weapps_core_1.PropBindType.prop) {
73
75
  const isNegated = value.startsWith('!');
@@ -104,28 +106,29 @@ function generateDataBindMeta(bind) {
104
106
  }
105
107
  }
106
108
  }
107
- return { imports, expression: expr };
109
+ return { imports, expression: expr ? expr.replace(/;\s*$/, '') : expr };
108
110
  }
109
111
  function createWidgetProps(ctx, widgets) {
110
112
  const widgetProps = {};
111
113
  (0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
112
- var _a;
113
114
  const { xComponent } = widget;
114
115
  const xProps = widget.xProps || {};
115
116
  if (!xComponent) {
116
117
  // skip slot component
117
118
  return;
118
119
  }
119
- const materialLib = ctx.materialLibs.find((lib) => lib.name === xComponent.moduleName);
120
- const miniprogramPlugin = (_a = ctx.miniprogramPlugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.name === xComponent.moduleName);
121
- if (!materialLib && !miniprogramPlugin) {
122
- console.error('Component lib not found', xComponent);
123
- return;
124
- }
125
- const widegetComp = materialLib === null || materialLib === void 0 ? void 0 : materialLib.components.find((comp) => comp.name === xComponent.name);
120
+ const widegetComp = findComponentInfo(xComponent, {
121
+ materialLibs: ctx.materialLibs,
122
+ miniprogramPlugins: ctx.miniprogramPlugins,
123
+ });
126
124
  if (!widegetComp) {
127
- console.error('Component not found in lib', widegetComp);
128
- return;
125
+ if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
126
+ (xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
127
+ // skip
128
+ }
129
+ else {
130
+ return;
131
+ }
129
132
  }
130
133
  widgetProps[id] = extractWidgetProps(xProps, widegetComp, ctx.processCssUnit);
131
134
  widgetProps[id]._parentId = parentId;
@@ -139,64 +142,73 @@ function createEventHanlders(ctx, widgets, componentApi, page) {
139
142
  let eventHandlers = {};
140
143
  const { listeners: pageListeners = [], id: pageId = '' } = page || {};
141
144
  (0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
142
- var _a, _b, _c;
145
+ var _a;
143
146
  const { xComponent } = widget;
144
147
  const xProps = widget.xProps || {};
145
148
  if (!xComponent) {
146
149
  // skip slot component
147
150
  return;
148
151
  }
149
- const materialLib = ctx.materialLibs.find((lib) => lib.name === xComponent.moduleName);
150
- const miniprogramPlugin = (_a = ctx.miniprogramPlugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.name === xComponent.moduleName);
151
- if (!materialLib && !miniprogramPlugin) {
152
- console.error('Component lib not found', xComponent);
153
- return;
152
+ let compProto;
153
+ if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
154
+ (xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME || xComponent.name === config_1.REPEATER.REPEATER_NAME)) {
155
+ // 内部虚组件,不校验compProto
154
156
  }
155
- const compProto = materialLib
156
- ? materialLib.components.find((comp) => comp.name === xComponent.name)
157
- : (_b = miniprogramPlugin === null || miniprogramPlugin === void 0 ? void 0 : miniprogramPlugin.componentConfigs) === null || _b === void 0 ? void 0 : _b.find((comp) => comp.name === xComponent.name);
158
- if (!compProto) {
159
- return;
157
+ else {
158
+ compProto = findComponentInfo(xComponent, {
159
+ materialLibs: ctx.materialLibs,
160
+ miniprogramPlugins: ctx.miniprogramPlugins,
161
+ });
162
+ if (!compProto) {
163
+ return;
164
+ }
160
165
  }
161
- const listeners = (xProps.listeners || []).slice();
162
166
  // Generate form input value change builtin handler
163
- const { inputProps, syncProps } = compProto.meta || {};
167
+ const { inputProps, syncProps } = (compProto === null || compProto === void 0 ? void 0 : compProto.meta) || {};
164
168
  const syncConfigs = syncProps || inputProps || {};
165
- for (const valuProp in syncConfigs) {
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));
169
+ const listeners = [...generateSyncListeners(syncConfigs), ...(xProps.listeners || [])];
178
170
  // 如果是数据容器,则生成一个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
- 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
- ];
171
+ if ((_a = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _a === void 0 ? void 0 : _a.isDataContainer) {
172
+ listeners.unshift(...generateDataContainerListeners());
193
173
  }
174
+ eventHandlers = Object.assign(eventHandlers, getListenersHandlers(listeners, id, componentApi));
194
175
  });
195
176
  // 增加页面事件节点 handlers
196
177
  eventHandlers = Object.assign(eventHandlers, getListenersHandlers(pageListeners, pageId, componentApi));
197
178
  return eventHandlers;
198
179
  }
199
180
  exports.createEventHanlders = createEventHanlders;
181
+ function generateSyncListeners(syncConfigs) {
182
+ const listeners = [];
183
+ for (const valuProp in syncConfigs) {
184
+ const config = syncConfigs[valuProp];
185
+ const configs = Array.isArray(config) ? config : [config];
186
+ configs.forEach(({ changeEvent, valueFromEvent = 'event.detail.value' }) => {
187
+ listeners.push({
188
+ trigger: changeEvent,
189
+ jsCode: `({ event }) => {event.currentTarget.${valuProp} = ${valueFromEvent};}`,
190
+ type: weapps_core_1.ActionType.Inline,
191
+ data: {},
192
+ });
193
+ });
194
+ }
195
+ return listeners;
196
+ }
197
+ exports.generateSyncListeners = generateSyncListeners;
198
+ function generateDataContainerListeners() {
199
+ return [
200
+ {
201
+ trigger: 'onDataChange',
202
+ jsCode: `({event})=>{
203
+ app.utils.set(event.currentTarget._scope, 'dataContext.data', event?.detail?.data);
204
+ app.utils.set(event.currentTarget._scope, 'dataContext.state', event?.detail?.state);
205
+ }`,
206
+ type: weapps_core_1.ActionType.Inline,
207
+ data: {},
208
+ },
209
+ ];
210
+ }
211
+ exports.generateDataContainerListeners = generateDataContainerListeners;
200
212
  /**
201
213
  * 根据 listeners 创建 handlers
202
214
  * @param listeners {IEventListener[]}
@@ -229,7 +241,7 @@ function getListenersHandlers(listeners, id, componentApi) {
229
241
  }
230
242
  eventHandlers[handlerName].push({
231
243
  key: l.key || '',
232
- handler: handler,
244
+ handler,
233
245
  handlerModule: (_c = l.handler) === null || _c === void 0 ? void 0 : _c.moduleName,
234
246
  data: params.staticProps,
235
247
  boundData: params.boundProps,
@@ -242,17 +254,17 @@ function createDataBinds(ctx, widgets) {
242
254
  const dataBinds = {};
243
255
  const { processCssUnit = 'rpx' } = ctx;
244
256
  (0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
245
- var _a;
246
257
  const { xComponent } = widget;
247
258
  const xProps = widget.xProps || {};
248
259
  if (!xComponent) {
249
260
  // skip slot component
250
261
  return;
251
262
  }
252
- const materialLib = ctx.materialLibs.find((lib) => lib.name === xComponent.moduleName);
253
- const miniprogramPlugin = (_a = ctx.miniprogramPlugins) === null || _a === void 0 ? void 0 : _a.find((plugin) => plugin.name === xComponent.moduleName);
254
- if (!materialLib && !miniprogramPlugin) {
255
- console.error('Component lib not found', xComponent);
263
+ if (xComponent.moduleName === config_1.REPEATER.MODULE_NAME &&
264
+ (xComponent.name === config_1.REPEATER.REPEATER_NAME || xComponent.name === config_1.REPEATER.REPEATER_ITEM_NAME)) {
265
+ // skip exist
266
+ }
267
+ else if (!findComponentInfo(xComponent, { materialLibs: ctx.materialLibs, miniprogramPlugins: ctx.miniprogramPlugins })) {
256
268
  return;
257
269
  }
258
270
  dataBinds[id] = {};
@@ -300,3 +312,94 @@ function setDataBind(target, prop, val) {
300
312
  // }
301
313
  }
302
314
  }
315
+ function processRepeaterSchema(ctx, componentInstanceMap) {
316
+ (0, weapp_1.walkThroughWidgets)(componentInstanceMap, (id, component, parentId) => {
317
+ var _a, _b;
318
+ const { xComponent, xProps, properties = {} } = component;
319
+ if (!xComponent) {
320
+ // skip slot component
321
+ return;
322
+ }
323
+ if (`${xComponent.moduleName}:${xComponent.name}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`) {
324
+ const children = Object.values(properties);
325
+ // 子项已经为 item 的不在处理
326
+ if (children.length === 1) {
327
+ const child = children[0];
328
+ const { xComponent: childXComponent } = child;
329
+ if (childXComponent &&
330
+ `${childXComponent.moduleName}:${childXComponent.name}` ===
331
+ `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`) {
332
+ return;
333
+ }
334
+ }
335
+ // 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
336
+ const repeaterItemId = `${id}_item`;
337
+ component.properties = {
338
+ [repeaterItemId]: {
339
+ xComponent: {
340
+ moduleName: config_1.REPEATER.MODULE_NAME,
341
+ name: config_1.REPEATER.REPEATER_ITEM_NAME,
342
+ },
343
+ xProps: {
344
+ data: {},
345
+ directives: {
346
+ waFor: (_a = xProps === null || xProps === void 0 ? void 0 : xProps.data) === null || _a === void 0 ? void 0 : _a.data,
347
+ waForKey: (_b = xProps === null || xProps === void 0 ? void 0 : xProps.data) === null || _b === void 0 ? void 0 : _b.key,
348
+ },
349
+ style: {},
350
+ styleBind: {
351
+ type: 'static',
352
+ value: {},
353
+ },
354
+ classList: [],
355
+ classListBind: {
356
+ type: 'static',
357
+ value: [],
358
+ },
359
+ commonStyle: {},
360
+ customDataForm: {},
361
+ staticResourceAttribute: [],
362
+ },
363
+ properties,
364
+ },
365
+ };
366
+ }
367
+ else if (`${xComponent.moduleName}:${xComponent.name}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_ITEM_NAME}`) {
368
+ return;
369
+ }
370
+ else if (xComponent && !findComponentInfo(xComponent, ctx)) {
371
+ component.properties = {};
372
+ }
373
+ return;
374
+ });
375
+ return componentInstanceMap;
376
+ }
377
+ exports.processRepeaterSchema = processRepeaterSchema;
378
+ /**
379
+ * 查找符合小程序平台组件的 info
380
+ */
381
+ function findComponentInfo(xComponent, { materialLibs, miniprogramPlugins }) {
382
+ var _a, _b;
383
+ if (!xComponent) {
384
+ // skip slot component
385
+ return;
386
+ }
387
+ const materialLib = materialLibs.find((lib) => lib.name === xComponent.moduleName);
388
+ const miniprogramPlugin = miniprogramPlugins === null || miniprogramPlugins === void 0 ? void 0 : miniprogramPlugins.find((plugin) => plugin.name === xComponent.moduleName);
389
+ if (!materialLib && !miniprogramPlugin) {
390
+ console.error('Component lib not found', `${xComponent.moduleName}:${xComponent.name}`);
391
+ return;
392
+ }
393
+ const compProto = materialLib
394
+ ? materialLib.components.find((comp) => comp.name === xComponent.name)
395
+ : (_a = miniprogramPlugin === null || miniprogramPlugin === void 0 ? void 0 : miniprogramPlugin.componentConfigs) === null || _a === void 0 ? void 0 : _a.find((comp) => comp.name === xComponent.name);
396
+ const platform = (_b = compProto === null || compProto === void 0 ? void 0 : compProto.meta) === null || _b === void 0 ? void 0 : _b.platform;
397
+ if (platform && Array.isArray(platform) && platform.length) {
398
+ if (!platform.includes('MP') && !platform.includes('小程序')) {
399
+ console.error('Component lib not found in mp platform', `${xComponent.moduleName}:${xComponent.name}`);
400
+ return;
401
+ }
402
+ }
403
+ return compProto;
404
+ }
405
+ exports.findComponentInfo = findComponentInfo;
@@ -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(widgets: {
4
- [key: string]: IWeAppComponentInstance;
5
- }, docTag: string, wxmlDataPrefix: any, ctx: IBuildContext & {
3
+ export declare function generateWxml(ctx: IBuildContext & {
6
4
  isPage: boolean;
7
- }, usingComponents: any, componentGenerics: any, nodeTransform?: (cmp: IWeAppComponentInstance, node: any) => void): string;
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;